You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2017/08/18 08:04:54 UTC
[07/20] lucenenet git commit: LUCENENET-565: Porting of Lucene
Replicator, cleanup stage 1
LUCENENET-565: Porting of Lucene Replicator, cleanup stage 1
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/e3305307
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/e3305307
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/e3305307
Branch: refs/heads/replicator
Commit: e3305307d237e2ffea30f66bb4f83e32830f20e6
Parents: 6da4dd2
Author: jeme <je...@outlook.com>
Authored: Tue Aug 8 00:12:44 2017 +0200
Committer: Jens Melgaard <ad...@it-links.dk>
Committed: Thu Aug 10 12:13:57 2017 +0200
----------------------------------------------------------------------
.../Lucene.Net.Replicator.AspNetCore.csproj | 1 +
.../examples.md | 1 +
.../ComponentWrapperInfoStream.cs | 54 ---
.../Http/Abstractions/IReplicationRequest.cs | 17 +
.../Http/Abstractions/IReplicationResponse.cs | 17 +
.../Http/EnumerableExtensions.cs | 32 --
.../Http/HttpClientBase.cs | 352 ++++---------------
.../Http/HttpReplicator.cs | 105 ++----
.../Http/ReplicationService.cs | 5 +-
.../IReplicationHandler.cs | 2 +-
.../IndexAndTaxonomyReplicationHandler.cs | 97 +----
.../IndexAndTaxonomyRevision.cs | 137 +-------
.../IndexReplicationHandler.cs | 202 +----------
src/Lucene.Net.Replicator/IndexRevision.cs | 63 ----
src/Lucene.Net.Replicator/LocalReplicator.cs | 128 +------
.../Lucene.Net.Replicator.csproj | 2 -
.../PerSessionDirectoryFactory.cs | 38 --
.../Properties/AssemblyInfo.cs | 1 -
src/Lucene.Net.Replicator/ReplicationClient.cs | 199 +----------
src/Lucene.Net.Replicator/Replicator.cs | 10 +-
src/Lucene.Net.Replicator/Revision.cs | 10 +-
src/Lucene.Net.Replicator/RevisionFile.cs | 5 +-
.../SessionExpiredException.cs | 3 -
src/Lucene.Net.Replicator/SessionToken.cs | 6 +-
.../Lucene.Net.TestFramework.csproj | 5 +-
.../Http/HttpReplicatorTest.cs | 2 -
.../IndexAndTaxonomyReplicationClientTest.cs | 56 +--
.../IndexAndTaxonomyRevisionTest.cs | 6 +-
.../IndexReplicationClientTest.cs | 148 +-------
.../IndexRevisionTest.cs | 8 +-
.../LocalReplicatorTest.cs | 6 +-
.../ReplicatorTestCase.cs | 126 -------
src/Lucene.Net/Lucene.Net.csproj | 1 +
src/Lucene.Net/Support/EnumerableExtensions.cs | 63 ++++
34 files changed, 277 insertions(+), 1631 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator.AspNetCore/Lucene.Net.Replicator.AspNetCore.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator.AspNetCore/Lucene.Net.Replicator.AspNetCore.csproj b/src/Lucene.Net.Replicator.AspNetCore/Lucene.Net.Replicator.AspNetCore.csproj
index cdb84b6..e4345b0 100644
--- a/src/Lucene.Net.Replicator.AspNetCore/Lucene.Net.Replicator.AspNetCore.csproj
+++ b/src/Lucene.Net.Replicator.AspNetCore/Lucene.Net.Replicator.AspNetCore.csproj
@@ -63,6 +63,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
+ <None Include="examples.md" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator.AspNetCore/examples.md
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator.AspNetCore/examples.md b/src/Lucene.Net.Replicator.AspNetCore/examples.md
new file mode 100644
index 0000000..5f28270
--- /dev/null
+++ b/src/Lucene.Net.Replicator.AspNetCore/examples.md
@@ -0,0 +1 @@
+
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/ComponentWrapperInfoStream.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/ComponentWrapperInfoStream.cs b/src/Lucene.Net.Replicator/ComponentWrapperInfoStream.cs
deleted file mode 100644
index 20d1e0e..0000000
--- a/src/Lucene.Net.Replicator/ComponentWrapperInfoStream.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-using Lucene.Net.Util;
-
-namespace Lucene.Net.Replicator
-{
- /// <summary>
- /// Wraps a InfoStream for a specific component.
- /// This is intented to make it a little easier to work with the InfoStreams.
- /// </summary>
- /// <remarks>
- /// .NET Specific
- /// </remarks>
- public sealed class ComponentWrapperInfoStream : InfoStream
- {
- private readonly string component;
- private readonly InfoStream innerStream;
-
- public ComponentWrapperInfoStream(string component, InfoStream innerStream)
- {
- this.component = component;
- this.innerStream = innerStream;
- }
-
- public override void Message(string component, string message)
- {
- if (IsEnabled(component))
- innerStream.Message(component, message);
- }
-
- public bool IsEnabled()
- {
- return IsEnabled(component);
- }
-
- public override bool IsEnabled(string component)
- {
- return innerStream.IsEnabled(component);
- }
-
- public override object Clone()
- {
- return new ComponentWrapperInfoStream(component, (InfoStream)innerStream.Clone());
- }
-
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- innerStream.Dispose();
- }
- base.Dispose(disposing);
- }
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/Http/Abstractions/IReplicationRequest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/Http/Abstractions/IReplicationRequest.cs b/src/Lucene.Net.Replicator/Http/Abstractions/IReplicationRequest.cs
index ad869af..e1c3de5 100644
--- a/src/Lucene.Net.Replicator/Http/Abstractions/IReplicationRequest.cs
+++ b/src/Lucene.Net.Replicator/Http/Abstractions/IReplicationRequest.cs
@@ -1,5 +1,22 @@
namespace Lucene.Net.Replicator.Http.Abstractions
{
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
/// <summary>
/// Abstraction for remote replication requests, allows easy integration into any hosting frameworks.
/// </summary>
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/Http/Abstractions/IReplicationResponse.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/Http/Abstractions/IReplicationResponse.cs b/src/Lucene.Net.Replicator/Http/Abstractions/IReplicationResponse.cs
index e46f358..1865dd4 100644
--- a/src/Lucene.Net.Replicator/Http/Abstractions/IReplicationResponse.cs
+++ b/src/Lucene.Net.Replicator/Http/Abstractions/IReplicationResponse.cs
@@ -2,6 +2,23 @@ using System.IO;
namespace Lucene.Net.Replicator.Http.Abstractions
{
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
/// <summary>
/// Abstraction for remote replication response, allows easy integration into any hosting frameworks.
/// </summary>
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/Http/EnumerableExtensions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/Http/EnumerableExtensions.cs b/src/Lucene.Net.Replicator/Http/EnumerableExtensions.cs
deleted file mode 100644
index 5247f40..0000000
--- a/src/Lucene.Net.Replicator/Http/EnumerableExtensions.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Lucene.Net.Replicator.Http
-{
- /// <summary>
- ///
- /// </summary>
- /// <remarks>
- /// .NET Specific Helper Extensions for IEnumerable
- /// </remarks>
- //Note: LUCENENET specific
- public static class EnumerableExtensions
- {
- public static IEnumerable<TOut> InPairs<T, TOut>(this IEnumerable<T> list, Func<T, T, TOut> join)
- {
- using (var enumerator = list.GetEnumerator())
- {
- while (true)
- {
- if (!enumerator.MoveNext())
- yield break;
-
- T x = enumerator.Current;
- if (!enumerator.MoveNext())
- yield return join(x, default(T));
- yield return join(x, enumerator.Current);
- }
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/Http/HttpClientBase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/Http/HttpClientBase.cs b/src/Lucene.Net.Replicator/Http/HttpClientBase.cs
index 17f1c3a..139fffd 100644
--- a/src/Lucene.Net.Replicator/Http/HttpClientBase.cs
+++ b/src/Lucene.Net.Replicator/Http/HttpClientBase.cs
@@ -1,11 +1,10 @@
-//STATUS: DRAFT - 4.8.0
-
-using System;
+using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
+using Lucene.Net.Support;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -42,15 +41,6 @@ namespace Lucene.Net.Replicator.Http
/// </summary>
public const int DEFAULT_CONNECTION_TIMEOUT = 1000;
- /**
- * Default socket timeout for this client, in milliseconds.
- *
- * @see #setSoTimeout(int)
- */
- //TODO: This goes to the Read and Write timeouts in the request (Closest we can get to a socket timeout in .NET?), those should be controlled in the messageHandler
- // if the choosen messagehandler provides such mechanishm (e.g. the WebRequestHandler) so this doesn't seem to make sense in .NET.
- //public const int DEFAULT_SO_TIMEOUT = 60000;
-
// TODO compression?
/// <summary>
@@ -60,15 +50,6 @@ namespace Lucene.Net.Replicator.Http
private readonly HttpClient httpc;
- //JAVA: /**
- //JAVA: * Set the connection timeout for this client, in milliseconds. This setting
- //JAVA: * is used to modify {@link HttpConnectionParams#setConnectionTimeout}.
- //JAVA: *
- //JAVA: * @param timeout timeout to set, in millisecopnds
- //JAVA: */
- //JAVA: public void setConnectionTimeout(int timeout) {
- //JAVA: HttpConnectionParams.setConnectionTimeout(httpc.getParams(), timeout);
- //JAVA: }
/// <summary>
/// Gets or Sets the connection timeout for this client, in milliseconds. This setting
/// is used to modify <see cref="HttpClient.Timeout"/>.
@@ -79,19 +60,6 @@ namespace Lucene.Net.Replicator.Http
set { httpc.Timeout = TimeSpan.FromMilliseconds(value); }
}
- //JAVA: /**
- //JAVA: * Set the socket timeout for this client, in milliseconds. This setting
- //JAVA: * is used to modify {@link HttpConnectionParams#setSoTimeout}.
- //JAVA: *
- //JAVA: * @param timeout timeout to set, in millisecopnds
- //JAVA: */
- //JAVA: public void setSoTimeout(int timeout) {
- //JAVA: HttpConnectionParams.setSoTimeout(httpc.getParams(), timeout);
- //JAVA: }
- //TODO: This goes to the Read and Write timeouts in the request (Closest we can get to a socket timeout in .NET?), those should be controlled in the messageHandler
- // if the choosen messagehandler provides such mechanishm (e.g. the WebRequestHandler) so this doesn't seem to make sense in .NET.
- //public int SoTimeout { get; set; }
-
/// <summary>
/// Returns true if this instance was <see cref="Dispose(bool)"/>ed, otherwise
/// returns false. Note that if you override <see cref="Dispose(bool)"/>, you must call
@@ -99,29 +67,56 @@ namespace Lucene.Net.Replicator.Http
/// </summary>
public bool IsDisposed { get; private set; }
- //TODO: HttpMessageHandler is not really a replacement for the ClientConnectionManager, allowing for custom message handlers will
- // provide flexibility, this is AFAIK also where users would be able to controll the equivalent of the SO timeout.
- protected HttpClientBase(string host, int port, string path, HttpMessageHandler messageHandler)
+ /// <summary>
+ /// Creates a new <see cref="HttpClientBase"/> with the given host, port and path.
+ /// </summary>
+ /// <remarks>
+ /// The host, port and path parameters are normalized to <code>http://{host}:{port}{path}</code>,
+ /// if path is <code>null</code> or <code>empty</code> it defaults to <code>/</code>.
+ /// <p>
+ /// A <see cref="HttpMessageHandler"/> is taken as an optional parameter as well, if this is not provided it defaults to null.
+ /// In this case the internal <see cref="HttpClient"/> will default to use a <see cref="HttpClientHandler"/>.
+ /// </p>
+ /// </remarks>
+ /// <param name="host">The host that the client should retrieve data from.</param>
+ /// <param name="port">The port to be used to connect on.</param>
+ /// <param name="path">The path to the replicator on the host.</param>
+ /// <param name="messageHandler">Optional, The HTTP handler stack to use for sending requests, defaults to null.</param>
+ protected HttpClientBase(string host, int port, string path, HttpMessageHandler messageHandler = null)
+ : this(NormalizedUrl(host, port, path), messageHandler)
{
- IsDisposed = false;
+ }
- #region Java
- //JAVA: /**
- //JAVA: * @param conMgr connection manager to use for this http client.
- //JAVA: * <b>NOTE:</b>The provided {@link ClientConnectionManager} will not be
- //JAVA: * {@link ClientConnectionManager#shutdown()} by this class.
- //JAVA: */
- //JAVA: protected HttpClientBase(String host, int port, String path, ClientConnectionManager conMgr) {
- //JAVA: url = normalizedURL(host, port, path);
- //JAVA: httpc = new DefaultHttpClient(conMgr);
- //JAVA: setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
- //JAVA: setSoTimeout(DEFAULT_SO_TIMEOUT);
- //JAVA: }
- #endregion
+ /// <summary>
+ /// Creates a new <see cref="HttpClientBase"/> with the given url.
+ /// </summary>
+ /// <remarks>
+ /// A <see cref="HttpMessageHandler"/> is taken as an optional parameter as well, if this is not provided it defaults to null.
+ /// In this case the internal <see cref="HttpClient"/> will default to use a <see cref="HttpClientHandler"/>.
+ /// </remarks>
+ /// <param name="url">The full url, including with host, port and path.</param>
+ /// <param name="messageHandler">Optional, The HTTP handler stack to use for sending requests.</param>
+ //Note: LUCENENET Specific
+ protected HttpClientBase(string url, HttpMessageHandler messageHandler = null)
+ : this(url, new HttpClient(messageHandler ?? new HttpClientHandler()) { Timeout = TimeSpan.FromMilliseconds(DEFAULT_CONNECTION_TIMEOUT) })
+ {
+ }
- Url = NormalizedUrl(host, port, path);
- httpc = new HttpClient(messageHandler ?? new HttpClientHandler());
- httpc.Timeout = TimeSpan.FromMilliseconds(DEFAULT_CONNECTION_TIMEOUT);
+ /// <summary>
+ /// Creates a new <see cref="HttpClientBase"/> with the given url and HttpClient.
+ /// </summary>
+ /// <remarks>
+ /// This allows full controll over how the HttpClient is created,
+ /// prefer the <see cref="HttpClientBase(string, HttpMessageHandler)"/> over this unless you know you need the control of the HttpClient.
+ /// </remarks>
+ /// <param name="url"></param>
+ /// <param name="client">The <see cref="HttpClient"/> to use make remote http calls.</param>
+ //Note: LUCENENET Specific
+ protected HttpClientBase(string url, HttpClient client)
+ {
+ Url = url;
+ httpc = client;
+ IsDisposed = false;
}
/// <summary>
@@ -130,14 +125,6 @@ namespace Lucene.Net.Replicator.Http
/// <exception cref="ObjectDisposedException">client is already closed.</exception>
protected void EnsureOpen()
{
- #region Java
- //JAVA: protected final void ensureOpen() throws AlreadyClosedException {
- //JAVA: if (closed) {
- //JAVA: throw new AlreadyClosedException("HttpClient already closed");
- //JAVA: }
- //JAVA: }
- #endregion
-
if (IsDisposed)
{
throw new ObjectDisposedException("HttpClient already closed");
@@ -146,18 +133,6 @@ namespace Lucene.Net.Replicator.Http
private static string NormalizedUrl(string host, int port, string path)
{
- #region Java
- //JAVA: /**
- //JAVA: * Create a URL out of the given parameters, translate an empty/null path to '/'
- //JAVA: */
- //JAVA: private static String normalizedURL(String host, int port, String path) {
- //JAVA: if (path == null || path.length() == 0) {
- //JAVA: path = "/";
- //JAVA: }
- //JAVA: return "http://" + host + ":" + port + path;
- //JAVA: }
- #endregion
-
if (string.IsNullOrEmpty(path))
path = "/";
return string.Format("http://{0}:{1}{2}", host, port, path);
@@ -170,20 +145,6 @@ namespace Lucene.Net.Replicator.Http
/// <exception cref="HttpRequestException">Unknown error received from the server.</exception>
protected void VerifyStatus(HttpResponseMessage response)
{
- #region Java
- //JAVA:
- //JAVA: /**
- //JAVA: * <b>Internal:</b> response status after invocation, and in case or error attempt to read the
- //JAVA: * exception sent by the server.
- //JAVA: */
- //JAVA: protected void verifyStatus(HttpResponse response) throws IOException {
- //JAVA: StatusLine statusLine = response.getStatusLine();
- //JAVA: if (statusLine.getStatusCode() != HttpStatus.SC_OK) {
- //JAVA: throwKnownError(response, statusLine);
- //JAVA: }
- //JAVA: }
- #endregion
-
if (!response.IsSuccessStatusCode)
{
ThrowKnownError(response);
@@ -197,46 +158,16 @@ namespace Lucene.Net.Replicator.Http
/// <exception cref="HttpRequestException">Unknown error received from the server.</exception>
protected void ThrowKnownError(HttpResponseMessage response)
{
- #region Java
- //JAVA: protected void throwKnownError(HttpResponse response, StatusLine statusLine) throws IOException {
- //JAVA: ObjectInputStream in = null;
- //JAVA: try {
- //JAVA: in = new ObjectInputStream(response.getEntity().getContent());
- //JAVA: } catch (Exception e) {
- //JAVA: // the response stream is not an exception - could be an error in servlet.init().
- //JAVA: throw new RuntimeException("Uknown error: " + statusLine);
- //JAVA: }
- //JAVA:
- //JAVA: Throwable t;
- //JAVA: try {
- //JAVA: t = (Throwable) in.readObject();
- //JAVA: } catch (Exception e) {
- //JAVA: //not likely
- //JAVA: throw new RuntimeException("Failed to read exception object: " + statusLine, e);
- //JAVA: } finally {
- //JAVA: in.close();
- //JAVA: }
- //JAVA: if (t instanceof IOException) {
- //JAVA: throw (IOException) t;
- //JAVA: }
- //JAVA: if (t instanceof RuntimeException) {
- //JAVA: throw (RuntimeException) t;
- //JAVA: }
- //JAVA: throw new RuntimeException("unknown exception "+statusLine,t);
- //JAVA: }
- #endregion
-
Stream input;
try
{
//.NET Note: Bridging from Async to Sync, this is not ideal and we could consider changing the interface to be Async or provide Async overloads
- // and have these Sync methods with their caveats.
+ // and have these Sync methods with their caveats.
input = response.Content.ReadAsStreamAsync().ConfigureAwait(false).GetAwaiter().GetResult();
}
catch (Exception)
{
// the response stream is not an exception - could be an error in servlet.init().
- //JAVA: throw new RuntimeException("Uknown error: " + statusLine);
response.EnsureSuccessStatusCode();
//Note: This is unreachable, but the compiler and resharper cant see that EnsureSuccessStatusCode always
// throws an exception in this scenario. So it complains later on in the method.
@@ -270,21 +201,6 @@ namespace Lucene.Net.Replicator.Http
protected HttpResponseMessage ExecutePost(string request, object entity, params string[] parameters)
{
- #region Java
- //JAVA: /**
- //JAVA: * <b>internal:</b> execute a request and return its result
- //JAVA: * The <code>params</code> argument is treated as: name1,value1,name2,value2,...
- //JAVA: */
- //JAVA: protected HttpResponse executePOST(String request, HttpEntity entity, String... params) throws IOException {
- //JAVA: ensureOpen();
- //JAVA: HttpPost m = new HttpPost(queryString(request, params));
- //JAVA: m.setEntity(entity);
- //JAVA: HttpResponse response = httpc.execute(m);
- //JAVA: verifyStatus(response);
- //JAVA: return response;
- //JAVA: }
- #endregion
-
EnsureOpen();
//.NET Note: No headers? No ContentType?... Bad use of Http?
HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Post, QueryString(request, parameters));
@@ -301,20 +217,6 @@ namespace Lucene.Net.Replicator.Http
protected HttpResponseMessage ExecuteGet(string request, params string[] parameters)
{
- #region Java
- //JAVA: /**
- //JAVA: * <b>internal:</b> execute a request and return its result
- //JAVA: * The <code>params</code> argument is treated as: name1,value1,name2,value2,...
- //JAVA: */
- //JAVA: protected HttpResponse executeGET(String request, String... params) throws IOException {
- //JAVA: ensureOpen();
- //JAVA: HttpGet m = new HttpGet(queryString(request, params));
- //JAVA: HttpResponse response = httpc.execute(m);
- //JAVA: verifyStatus(response);
- //JAVA: return response;
- //JAVA: }
- #endregion
-
EnsureOpen();
//Note: No headers? No ContentType?... Bad use of Http?
HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Get, QueryString(request, parameters));
@@ -327,18 +229,6 @@ namespace Lucene.Net.Replicator.Http
private string QueryString(string request, params string[] parameters)
{
- #region Java
- //JAVA: private String queryString(String request, String... params) throws UnsupportedEncodingException {
- //JAVA: StringBuilder query = new StringBuilder(url).append('/').append(request).append('?');
- //JAVA: if (params != null) {
- //JAVA: for (int i = 0; i < params.length; i += 2) {
- //JAVA: query.append(params[i]).append('=').append(URLEncoder.encode(params[i+1], "UTF8")).append('&');
- //JAVA: }
- //JAVA: }
- //JAVA: return query.substring(0, query.length() - 1);
- //JAVA: }
- #endregion
-
return parameters == null
? string.Format("{0}/{1}", Url, request)
: string.Format("{0}/{1}?{2}", Url, request, string
@@ -349,15 +239,8 @@ namespace Lucene.Net.Replicator.Http
/// Internal utility: input stream of the provided response
/// </summary>
/// <exception cref="IOException"></exception>
- public Stream ResponseInputStream(HttpResponseMessage response)// throws IOException
+ public Stream ResponseInputStream(HttpResponseMessage response)
{
- #region Java
- //JAVA: /** Internal utility: input stream of the provided response */
- //JAVA: public InputStream responseInputStream(HttpResponse response) throws IOException {
- //JAVA: return responseInputStream(response, false);
- //JAVA: }
- #endregion
-
return ResponseInputStream(response, false);
}
@@ -365,109 +248,26 @@ namespace Lucene.Net.Replicator.Http
/// Internal utility: input stream of the provided response
/// </summary>
/// <exception cref="IOException"></exception>
- public Stream ResponseInputStream(HttpResponseMessage response, bool consume)// throws IOException
+ public Stream ResponseInputStream(HttpResponseMessage response, bool consume)
{
- #region Java
- //JAVA: TODO: can we simplify this Consuming !?!?!?
- //JAVA: /**
- //JAVA: * Internal utility: input stream of the provided response, which optionally
- //JAVA: * consumes the response's resources when the input stream is exhausted.
- //JAVA: */
- //JAVA: public InputStream responseInputStream(HttpResponse response, boolean consume) throws IOException {
- //JAVA: final HttpEntity entity = response.getEntity();
- //JAVA: final InputStream in = entity.getContent();
- //JAVA: if (!consume) {
- //JAVA: return in;
- //JAVA: }
- //JAVA: return new InputStream() {
- //JAVA: private boolean consumed = false;
- //JAVA: @Override
- //JAVA: public int read() throws IOException {
- //JAVA: final int res = in.read();
- //JAVA: consume(res);
- //JAVA: return res;
- //JAVA: }
- //JAVA: @Override
- //JAVA: public void close() throws IOException {
- //JAVA: super.close();
- //JAVA: consume(-1);
- //JAVA: }
- //JAVA: @Override
- //JAVA: public int read(byte[] b) throws IOException {
- //JAVA: final int res = super.read(b);
- //JAVA: consume(res);
- //JAVA: return res;
- //JAVA: }
- //JAVA: @Override
- //JAVA: public int read(byte[] b, int off, int len) throws IOException {
- //JAVA: final int res = super.read(b, off, len);
- //JAVA: consume(res);
- //JAVA: return res;
- //JAVA: }
- //JAVA: private void consume(int minusOne) {
- //JAVA: if (!consumed && minusOne==-1) {
- //JAVA: try {
- //JAVA: EntityUtils.consume(entity);
- //JAVA: } catch (Exception e) {
- //JAVA: // ignored on purpose
- //JAVA: }
- //JAVA: consumed = true;
- //JAVA: }
- //JAVA: }
- //JAVA: };
- //JAVA: }
- #endregion
-
return response.Content.ReadAsStreamAsync().ConfigureAwait(false).GetAwaiter().GetResult();
}
+ /// <summary>
+ /// Calls the overload <see cref="DoAction{T}(HttpResponseMessage, Boolean, Func{T})"/> passing <code>true</code> to consume.
+ /// </summary>
protected T DoAction<T>(HttpResponseMessage response, Func<T> call)
{
- #region Java
- //JAVA: /**
- //JAVA: * Same as {@link #doAction(HttpResponse, boolean, Callable)} but always do consume at the end.
- //JAVA: */
- //JAVA: protected <T> T doAction(HttpResponse response, Callable<T> call) throws IOException {
- //JAVA: return doAction(response, true, call);
- //JAVA: }
- #endregion
-
return DoAction(response, true, call);
}
+ /// <summary>
+ /// Do a specific action and validate after the action that the status is still OK,
+ /// and if not, attempt to extract the actual server side exception. Optionally
+ /// release the response at exit, depending on <code>consume</code> parameter.
+ /// </summary>
protected T DoAction<T>(HttpResponseMessage response, bool consume, Func<T> call)
{
- #region Java
- //JAVA: /**
- //JAVA: * Do a specific action and validate after the action that the status is still OK,
- //JAVA: * and if not, attempt to extract the actual server side exception. Optionally
- //JAVA: * release the response at exit, depending on <code>consume</code> parameter.
- //JAVA: */
- //JAVA: protected <T> T doAction(HttpResponse response, boolean consume, Callable<T> call) throws IOException {
- //JAVA: IOException error = null;
- //JAVA: try {
- //JAVA: return call.call();
- //JAVA: } catch (IOException e) {
- //JAVA: error = e;
- //JAVA: } catch (Exception e) {
- //JAVA: error = new IOException(e);
- //JAVA: } finally {
- //JAVA: try {
- //JAVA: verifyStatus(response);
- //JAVA: } finally {
- //JAVA: if (consume) {
- //JAVA: try {
- //JAVA: EntityUtils.consume(response.getEntity());
- //JAVA: } catch (Exception e) {
- //JAVA: // ignoring on purpose
- //JAVA: }
- //JAVA: }
- //JAVA: }
- //JAVA: }
- //JAVA: throw error; // should not get here
- //JAVA: }
- #endregion
-
Exception error = new NotImplementedException();
try
{
@@ -483,30 +283,32 @@ namespace Lucene.Net.Replicator.Http
}
finally
{
- try
- {
- VerifyStatus(response);
- }
- finally
- {
- //TODO: Is there any reason for this on .NET?... What are they trying to achieve?
- //JAVA: if (consume) {
- //JAVA: try {
- //JAVA: EntityUtils.consume(response.getEntity());
- //JAVA: } catch (Exception e) {
- //JAVA: // ignoring on purpose
- //JAVA: }
- //JAVA: }
- }
+ //JAVA: Had a TryCatch here and then used a EntityUtils class to consume the response,
+ //JAVA: Unsure of what that was trying to achieve it was left out.
+ //JAVA: This also means that right now this overload does nothing more than support the signature given by the Java ver.
+ //JAVA: Overall from a .NET perspective, this method is overly suspicious.
+ VerifyStatus(response);
}
throw error; // should not get here
}
+ /// <summary>
+ /// Disposes this <see cref="HttpClientBase"/>.
+ /// When called with <code>true</code>, this disposes the underlying <see cref="HttpClient"/>.
+ /// </summary>
protected virtual void Dispose(bool disposing)
{
+ if (disposing)
+ {
+ httpc.Dispose();
+ }
IsDisposed = true;
}
+ /// <summary>
+ /// Disposes this <see cref="HttpClientBase"/>.
+ /// This disposes the underlying <see cref="HttpClient"/>.
+ /// </summary>
public void Dispose()
{
Dispose(true);
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/Http/HttpReplicator.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/Http/HttpReplicator.cs b/src/Lucene.Net.Replicator/Http/HttpReplicator.cs
index 90df85b..ab519c3 100644
--- a/src/Lucene.Net.Replicator/Http/HttpReplicator.cs
+++ b/src/Lucene.Net.Replicator/Http/HttpReplicator.cs
@@ -1,9 +1,6 @@
-//STATUS: DRAFT - 4.8.0
-
-using System;
+using System;
using System.IO;
using System.Net.Http;
-using System.Threading.Tasks;
using Lucene.Net.Support.IO;
namespace Lucene.Net.Replicator.Http
@@ -33,54 +30,49 @@ namespace Lucene.Net.Replicator.Http
/// </remarks>
public class HttpReplicator : HttpClientBase, IReplicator
{
- public HttpReplicator(string host, int port, string path, HttpMessageHandler messageHandler)
+ /// <summary>
+ /// Creates a new <see cref="HttpReplicator"/> with the given host, port and path.
+ /// <see cref="HttpClientBase(string, int, string, HttpMessageHandler)"/> for more details.
+ /// </summary>
+ public HttpReplicator(string host, int port, string path, HttpMessageHandler messageHandler = null)
: base(host, port, path, messageHandler)
{
- #region Java
- //JAVA: /** Construct with specified connection manager. */
- //JAVA: public HttpReplicator(String host, int port, String path, ClientConnectionManager conMgr) {
- //JAVA: super(host, port, path, conMgr);
- //JAVA: }
- #endregion
+ }
+
+ /// <summary>
+ /// Creates a new <see cref="HttpReplicator"/> with the given url.
+ /// <see cref="HttpClientBase(string, HttpMessageHandler)"/> for more details.
+ /// </summary>
+ //Note: LUCENENET Specific
+ public HttpReplicator(string url, HttpMessageHandler messageHandler = null)
+ : this(url, new HttpClient(messageHandler ?? new HttpClientHandler()) { Timeout = TimeSpan.FromMilliseconds(DEFAULT_CONNECTION_TIMEOUT) })
+ {
+ }
+
+ /// <summary>
+ /// Creates a new <see cref="HttpReplicator"/> with the given url and HttpClient.
+ /// <see cref="HttpClientBase(string, HttpClient)"/> for more details.
+ /// </summary>
+ //Note: LUCENENET Specific
+ public HttpReplicator(string url, HttpClient client)
+ : base(url, client)
+ {
}
/// <summary>
- ///
+ /// Not supported.
/// </summary>
- /// <param name="revision"></param>
/// <exception cref="NotSupportedException">this replicator implementation does not support remote publishing of revisions</exception>
public void Publish(IRevision revision)
{
throw new NotSupportedException("this replicator implementation does not support remote publishing of revisions");
}
+ /// <summary>
+ /// Checks for updates at the remote host.
+ /// </summary>
public SessionToken CheckForUpdate(string currentVersion)
{
- #region Java
- //JAVA: public SessionToken checkForUpdate(String currVersion) throws IOException {
- //JAVA: String[] params = null;
- //JAVA: if (currVersion != null) {
- //JAVA: params = new String[] { ReplicationService.REPLICATE_VERSION_PARAM, currVersion };
- //JAVA: }
- //JAVA: final HttpResponse response = executeGET(ReplicationAction.UPDATE.name(), params);
- //JAVA: return doAction(response, new Callable<SessionToken>() {
- //JAVA: @Override
- //JAVA: public SessionToken call() throws Exception {
- //JAVA: final DataInputStream dis = new DataInputStream(responseInputStream(response));
- //JAVA: try {
- //JAVA: if (dis.readByte() == 0) {
- //JAVA: return null;
- //JAVA: } else {
- //JAVA: return new SessionToken(dis);
- //JAVA: }
- //JAVA: } finally {
- //JAVA: dis.close();
- //JAVA: }
- //JAVA: }
- //JAVA: });
- //JAVA: }
- #endregion
-
string[] parameters = null;
if (currentVersion != null)
parameters = new [] { ReplicationService.REPLICATE_VERSION_PARAM, currentVersion };
@@ -95,46 +87,21 @@ namespace Lucene.Net.Replicator.Http
});
}
+ /// <summary>
+ /// Releases a session obtained from the remote host.
+ /// </summary>
public void Release(string sessionId)
{
- #region Java
- //JAVA: public void release(String sessionID) throws IOException {
- //JAVA: String[] params = new String[] {
- //JAVA: ReplicationService.REPLICATE_SESSION_ID_PARAM, sessionID
- //JAVA: };
- //JAVA: final HttpResponse response = executeGET(ReplicationAction.RELEASE.name(), params);
- //JAVA: doAction(response, new Callable<Object>() {
- //JAVA: @Override
- //JAVA: public Object call() throws Exception {
- //JAVA: return null; // do not remove this call: as it is still validating for us!
- //JAVA: }
- //JAVA: });
- //JAVA: }
- #endregion
-
HttpResponseMessage response = ExecuteGet(ReplicationService.ReplicationAction.RELEASE.ToString(), ReplicationService.REPLICATE_SESSION_ID_PARAM, sessionId);
// do not remove this call: as it is still validating for us!
DoAction<object>(response, () => null);
}
+ /// <summary>
+ /// Obtains the given file from it's source at the remote host.
+ /// </summary>
public Stream ObtainFile(string sessionId, string source, string fileName)
{
- #region Java
- //JAVA: public InputStream obtainFile(String sessionID, String source, String fileName) throws IOException {
- //JAVA: String[] params = new String[] {
- //JAVA: ReplicationService.REPLICATE_SESSION_ID_PARAM, sessionID,
- //JAVA: ReplicationService.REPLICATE_SOURCE_PARAM, source,
- //JAVA: ReplicationService.REPLICATE_FILENAME_PARAM, fileName,
- //JAVA: };
- //JAVA: final HttpResponse response = executeGET(ReplicationAction.OBTAIN.name(), params);
- //JAVA: return doAction(response, false, new Callable<InputStream>() {
- //JAVA: @Override
- //JAVA: public InputStream call() throws Exception {
- //JAVA: return responseInputStream(response,true);
- //JAVA: }
- //JAVA: });
- //JAVA: }
- #endregion
HttpResponseMessage response = ExecuteGet(ReplicationService.ReplicationAction.OBTAIN.ToString(),
ReplicationService.REPLICATE_SESSION_ID_PARAM, sessionId,
ReplicationService.REPLICATE_SOURCE_PARAM, source,
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/Http/ReplicationService.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/Http/ReplicationService.cs b/src/Lucene.Net.Replicator/Http/ReplicationService.cs
index d004fc7..090ca4d 100644
--- a/src/Lucene.Net.Replicator/Http/ReplicationService.cs
+++ b/src/Lucene.Net.Replicator/Http/ReplicationService.cs
@@ -1,6 +1,4 @@
-//STATUS: DRAFT - 4.8.0
-
-using System;
+using System;
using System.Collections.Generic;
using System.IO;
using Lucene.Net.Replicator.Http.Abstractions;
@@ -122,7 +120,6 @@ namespace Lucene.Net.Replicator.Http
string param = request.QueryParam(paramName);
if (param == null)
{
- //JAVA: throw new ServletException("Missing mandatory parameter: " + paramName);
throw new InvalidOperationException("Missing mandatory parameter: " + paramName);
}
return param;
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/IReplicationHandler.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/IReplicationHandler.cs b/src/Lucene.Net.Replicator/IReplicationHandler.cs
index 1976435..d3e6504 100644
--- a/src/Lucene.Net.Replicator/IReplicationHandler.cs
+++ b/src/Lucene.Net.Replicator/IReplicationHandler.cs
@@ -1,5 +1,5 @@
//STATUS: DRAFT - 4.8.0
-using System;
+
using System.Collections.Generic;
using System.IO;
using Directory = Lucene.Net.Store.Directory;
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/IndexAndTaxonomyReplicationHandler.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/IndexAndTaxonomyReplicationHandler.cs b/src/Lucene.Net.Replicator/IndexAndTaxonomyReplicationHandler.cs
index a9629b8..36bf271 100644
--- a/src/Lucene.Net.Replicator/IndexAndTaxonomyReplicationHandler.cs
+++ b/src/Lucene.Net.Replicator/IndexAndTaxonomyReplicationHandler.cs
@@ -1,14 +1,9 @@
-//STATUS: DRAFT - 4.8.0
-
-using System;
+using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using Lucene.Net.Index;
using Lucene.Net.Store;
-using Lucene.Net.Support;
using Lucene.Net.Util;
using Directory = Lucene.Net.Store.Directory;
@@ -32,8 +27,8 @@ namespace Lucene.Net.Replicator
*/
/// <summary>
- /// A {@link ReplicationHandler} for replication of an index and taxonomy pair.
- /// See {@link IndexReplicationHandler} for more detail. This handler ensures
+ /// A <see cref="IReplicationHandler"/> for replication of an index and taxonomy pair.
+ /// See <see cref="IReplicationHandler"/> for more detail. This handler ensures
/// that the search and taxonomy indexes are replicated in a consistent way.
///
/// <see cref="IndexReplicationHandler"/>
@@ -51,7 +46,7 @@ namespace Lucene.Net.Replicator
public class IndexAndTaxonomyReplicationHandler : IReplicationHandler
{
/// <summary>
- /// The component used to log messages to the {@link InfoStream#getDefault()default} {@link InfoStream}.
+ /// The component used to log messages to the <see cref="InfoStream"/>.
/// </summary>
public const string INFO_STREAM_COMPONENT = "IndexAndTaxonomyReplicationHandler";
@@ -72,9 +67,6 @@ namespace Lucene.Net.Replicator
/// <summary>
/// Constructor with the given index directory and callback to notify when the indexes were updated.
/// </summary>
- /// <param name="indexDirectory"></param>
- /// <param name="taxonomyDirectory"></param>
- /// <param name="callback"></param>
/// <exception cref="System.IO.IOException"></exception>
public IndexAndTaxonomyReplicationHandler(Directory indexDirectory, Directory taxonomyDirectory, Func<bool?> callback)
{
@@ -88,7 +80,6 @@ namespace Lucene.Net.Replicator
bool indexExists = DirectoryReader.IndexExists(indexDirectory);
bool taxonomyExists = DirectoryReader.IndexExists(taxonomyDirectory);
- //JAVA: IllegalStateException
if (indexExists != taxonomyExists)
throw new InvalidOperationException(string.Format("search and taxonomy indexes must either both exist or not: index={0} taxo={1}", indexExists, taxonomyExists));
@@ -107,92 +98,14 @@ namespace Lucene.Net.Replicator
}
/// <summary>
- ///
+ /// TODO
/// </summary>
- /// <param name="version"></param>
- /// <param name="revisionFiles"></param>
- /// <param name="copiedFiles"></param>
- /// <param name="sourceDirectory"></param>
/// <exception cref=""></exception>
public void RevisionReady(string version,
IDictionary<string, IList<RevisionFile>> revisionFiles,
IDictionary<string, IList<string>> copiedFiles,
IDictionary<string, Directory> sourceDirectory)
{
- #region Java
- //JAVA: Directory taxoClientDir = sourceDirectory.get(IndexAndTaxonomyRevision.TAXONOMY_SOURCE);
- //JAVA: Directory indexClientDir = sourceDirectory.get(IndexAndTaxonomyRevision.INDEX_SOURCE);
- //JAVA: List<String> taxoFiles = copiedFiles.get(IndexAndTaxonomyRevision.TAXONOMY_SOURCE);
- //JAVA: List<String> indexFiles = copiedFiles.get(IndexAndTaxonomyRevision.INDEX_SOURCE);
- //JAVA: String taxoSegmentsFile = IndexReplicationHandler.getSegmentsFile(taxoFiles, true);
- //JAVA: String indexSegmentsFile = IndexReplicationHandler.getSegmentsFile(indexFiles, false);
- //JAVA:
- //JAVA: boolean success = false;
- //JAVA: try {
- //JAVA: // copy taxonomy files before index files
- //JAVA: IndexReplicationHandler.copyFiles(taxoClientDir, taxoDir, taxoFiles);
- //JAVA: IndexReplicationHandler.copyFiles(indexClientDir, indexDir, indexFiles);
- //JAVA:
- //JAVA: // fsync all copied files (except segmentsFile)
- //JAVA: if (!taxoFiles.isEmpty()) {
- //JAVA: taxoDir.sync(taxoFiles);
- //JAVA: }
- //JAVA: indexDir.sync(indexFiles);
- //JAVA:
- //JAVA: // now copy and fsync segmentsFile, taxonomy first because it is ok if a
- //JAVA: // reader sees a more advanced taxonomy than the index.
- //JAVA: if (taxoSegmentsFile != null) {
- //JAVA: taxoClientDir.copy(taxoDir, taxoSegmentsFile, taxoSegmentsFile, IOContext.READONCE);
- //JAVA: }
- //JAVA: indexClientDir.copy(indexDir, indexSegmentsFile, indexSegmentsFile, IOContext.READONCE);
- //JAVA:
- //JAVA: if (taxoSegmentsFile != null) {
- //JAVA: taxoDir.sync(Collections.singletonList(taxoSegmentsFile));
- //JAVA: }
- //JAVA: indexDir.sync(Collections.singletonList(indexSegmentsFile));
- //JAVA:
- //JAVA: success = true;
- //JAVA: } finally {
- //JAVA: if (!success) {
- //JAVA: taxoFiles.add(taxoSegmentsFile); // add it back so it gets deleted too
- //JAVA: IndexReplicationHandler.cleanupFilesOnFailure(taxoDir, taxoFiles);
- //JAVA: indexFiles.add(indexSegmentsFile); // add it back so it gets deleted too
- //JAVA: IndexReplicationHandler.cleanupFilesOnFailure(indexDir, indexFiles);
- //JAVA: }
- //JAVA: }
- //JAVA:
- //JAVA: // all files have been successfully copied + sync'd. update the handler's state
- //JAVA: currentRevisionFiles = revisionFiles;
- //JAVA: currentVersion = version;
- //JAVA:
- //JAVA: if (infoStream.isEnabled(INFO_STREAM_COMPONENT)) {
- //JAVA: infoStream.message(INFO_STREAM_COMPONENT, "revisionReady(): currentVersion=" + currentVersion
- //JAVA: + " currentRevisionFiles=" + currentRevisionFiles);
- //JAVA: }
- //JAVA:
- //JAVA: // update the segments.gen file
- //JAVA: IndexReplicationHandler.writeSegmentsGen(taxoSegmentsFile, taxoDir);
- //JAVA: IndexReplicationHandler.writeSegmentsGen(indexSegmentsFile, indexDir);
- //JAVA:
- //JAVA: // Cleanup the index directory from old and unused index files.
- //JAVA: // NOTE: we don't use IndexWriter.deleteUnusedFiles here since it may have
- //JAVA: // side-effects, e.g. if it hits sudden IO errors while opening the index
- //JAVA: // (and can end up deleting the entire index). It is not our job to protect
- //JAVA: // against those errors, app will probably hit them elsewhere.
- //JAVA: IndexReplicationHandler.cleanupOldIndexFiles(indexDir, indexSegmentsFile);
- //JAVA: IndexReplicationHandler.cleanupOldIndexFiles(taxoDir, taxoSegmentsFile);
- //JAVA:
- //JAVA: // successfully updated the index, notify the callback that the index is
- //JAVA: // ready.
- //JAVA: if (callback != null) {
- //JAVA: try {
- //JAVA: callback.call();
- //JAVA: } catch (Exception e) {
- //JAVA: throw new IOException(e);
- //JAVA: }
- //JAVA: }
- #endregion
-
Directory taxonomyClientDirectory = sourceDirectory[IndexAndTaxonomyRevision.TAXONOMY_SOURCE];
Directory indexClientDirectory = sourceDirectory[IndexAndTaxonomyRevision.INDEX_SOURCE];
IList<string> taxonomyFiles = copiedFiles[IndexAndTaxonomyRevision.TAXONOMY_SOURCE];
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/IndexAndTaxonomyRevision.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/IndexAndTaxonomyRevision.cs b/src/Lucene.Net.Replicator/IndexAndTaxonomyRevision.cs
index 8d32fac..890f995 100644
--- a/src/Lucene.Net.Replicator/IndexAndTaxonomyRevision.cs
+++ b/src/Lucene.Net.Replicator/IndexAndTaxonomyRevision.cs
@@ -2,7 +2,6 @@
using System;
using System.Collections.Generic;
-using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
@@ -43,15 +42,6 @@ namespace Lucene.Net.Replicator
/// </remarks>
public class IndexAndTaxonomyRevision : IRevision
{
- #region Java
- //JAVA: private final IndexWriter indexWriter;
- //JAVA: private final SnapshotDirectoryTaxonomyWriter taxoWriter;
- //JAVA: private final IndexCommit indexCommit, taxoCommit;
- //JAVA: private final SnapshotDeletionPolicy indexSDP, taxoSDP;
- //JAVA: private final String version;
- //JAVA: private final Map<String, List<RevisionFile>> sourceFiles;
- #endregion
-
public const string INDEX_SOURCE = "index";
public const string TAXONOMY_SOURCE = "taxonomy";
@@ -64,36 +54,11 @@ namespace Lucene.Net.Replicator
public IDictionary<string, IList<RevisionFile>> SourceFiles { get; private set; }
/// <summary>
- ///
+ /// TODO
/// </summary>
- /// <param name="indexWriter"></param>
- /// <param name="taxonomyWriter"></param>
/// <exception cref="IOException"></exception>
public IndexAndTaxonomyRevision(IndexWriter indexWriter, SnapshotDirectoryTaxonomyWriter taxonomyWriter)
{
- #region Java
- //JAVA: /**
- //JAVA: * Constructor over the given {@link IndexWriter}. Uses the last
- //JAVA: * {@link IndexCommit} found in the {@link Directory} managed by the given
- //JAVA: * writer.
- //JAVA: */
- //JAVA: public IndexAndTaxonomyRevision(IndexWriter indexWriter, SnapshotDirectoryTaxonomyWriter taxoWriter)
- //JAVA: throws IOException {
- //JAVA: IndexDeletionPolicy delPolicy = indexWriter.getConfig().getIndexDeletionPolicy();
- //JAVA: if (!(delPolicy instanceof SnapshotDeletionPolicy)) {
- //JAVA: throw new IllegalArgumentException("IndexWriter must be created with SnapshotDeletionPolicy");
- //JAVA: }
- //JAVA: this.indexWriter = indexWriter;
- //JAVA: this.taxoWriter = taxoWriter;
- //JAVA: this.indexSDP = (SnapshotDeletionPolicy) delPolicy;
- //JAVA: this.taxoSDP = taxoWriter.getDeletionPolicy();
- //JAVA: this.indexCommit = indexSDP.snapshot();
- //JAVA: this.taxoCommit = taxoSDP.snapshot();
- //JAVA: this.version = revisionVersion(indexCommit, taxoCommit);
- //JAVA: this.sourceFiles = revisionFiles(indexCommit, taxoCommit);
- //JAVA: }
- #endregion
-
this.indexSdp = indexWriter.Config.IndexDeletionPolicy as SnapshotDeletionPolicy;
if (indexSdp == null)
throw new ArgumentException("IndexWriter must be created with SnapshotDeletionPolicy", "indexWriter");
@@ -107,35 +72,17 @@ namespace Lucene.Net.Replicator
this.SourceFiles = RevisionFiles(indexCommit, taxonomyCommit);
}
+ /// <summary>
+ /// Compares this <see cref="IndexAndTaxonomyRevision"/> to the given <see cref="version"/>.
+ /// </summary>
public int CompareTo(string version)
{
- #region Java
- //JAVA: public int compareTo(String version) {
- //JAVA: final String[] parts = version.split(":");
- //JAVA: final long indexGen = Long.parseLong(parts[0], RADIX);
- //JAVA: final long taxoGen = Long.parseLong(parts[1], RADIX);
- //JAVA: final long indexCommitGen = indexCommit.getGeneration();
- //JAVA: final long taxoCommitGen = taxoCommit.getGeneration();
- //JAVA:
- //JAVA: // if the index generation is not the same as this commit's generation,
- //JAVA: // compare by it. Otherwise, compare by the taxonomy generation.
- //JAVA: if (indexCommitGen < indexGen) {
- //JAVA: return -1;
- //JAVA: } else if (indexCommitGen > indexGen) {
- //JAVA: return 1;
- //JAVA: } else {
- //JAVA: return taxoCommitGen < taxoGen ? -1 : (taxoCommitGen > taxoGen ? 1 : 0);
- //JAVA: }
- //JAVA: }
- #endregion
-
string[] parts = version.Split(':');
long indexGen = long.Parse(parts[0], NumberStyles.HexNumber);
long taxonomyGen = long.Parse(parts[1], NumberStyles.HexNumber);
long indexCommitGen = indexCommit.Generation;
long taxonomyCommitGen = taxonomyCommit.Generation;
- //TODO: long.CompareTo(); but which goes where.
if (indexCommitGen < indexGen)
return -1;
@@ -147,68 +94,34 @@ namespace Lucene.Net.Replicator
public int CompareTo(IRevision other)
{
- #region Java
- //JAVA: public int compareTo(Revision o) {
- //JAVA: IndexAndTaxonomyRevision other = (IndexAndTaxonomyRevision) o;
- //JAVA: int cmp = indexCommit.compareTo(other.indexCommit);
- //JAVA: return cmp != 0 ? cmp : taxoCommit.compareTo(other.taxoCommit);
- //JAVA: }
- #endregion
+ if (other == null)
+ throw new ArgumentNullException("other");
+
+ IndexAndTaxonomyRevision itr = other as IndexAndTaxonomyRevision;
+ if(itr == null)
+ throw new ArgumentException(string.Format("Cannot compare IndexAndTaxonomyRevision to a {0}", other.GetType()), "other");
- //TODO: This breaks the contract and will fail if called with a different implementation
- // This is a flaw inherited from the original source...
- // It should at least provide a better description to the InvalidCastException
- IndexAndTaxonomyRevision or = (IndexAndTaxonomyRevision)other;
- int cmp = indexCommit.CompareTo(or.indexCommit);
- return cmp != 0 ? cmp : taxonomyCommit.CompareTo(or.taxonomyCommit);
+ int cmp = indexCommit.CompareTo(itr.indexCommit);
+ return cmp != 0 ? cmp : taxonomyCommit.CompareTo(itr.taxonomyCommit);
}
/// <summary>
- ///
+ /// TODO
/// </summary>
- /// <param name="source"></param>
- /// <param name="fileName"></param>
- /// <returns></returns>
/// <exception cref="IOException"></exception>
public Stream Open(string source, string fileName)
{
- #region Java
- //JAVA: public InputStream open(String source, String fileName) throws IOException {
- //JAVA: assert source.equals(INDEX_SOURCE) || source.equals(TAXONOMY_SOURCE) : "invalid source; expected=(" + INDEX_SOURCE
- //JAVA: + " or " + TAXONOMY_SOURCE + ") got=" + source;
- //JAVA: IndexCommit ic = source.equals(INDEX_SOURCE) ? indexCommit : taxoCommit;
- //JAVA: return new IndexInputStream(ic.getDirectory().openInput(fileName, IOContext.READONCE));
- //JAVA: }
- #endregion
-
- Debug.Assert(source.Equals(INDEX_SOURCE) || source.Equals(TAXONOMY_SOURCE),
- string.Format("invalid source; expected=({0} or {1}) got={2}", INDEX_SOURCE, TAXONOMY_SOURCE, source));
+ Debug.Assert(source.Equals(INDEX_SOURCE) || source.Equals(TAXONOMY_SOURCE), string.Format("invalid source; expected=({0} or {1}) got={2}", INDEX_SOURCE, TAXONOMY_SOURCE, source));
IndexCommit commit = source.Equals(INDEX_SOURCE) ? indexCommit : taxonomyCommit;
return new IndexInputStream(commit.Directory.OpenInput(fileName, IOContext.READ_ONCE));
}
/// <summary>
- ///
+ /// TODO
/// </summary>
/// <exception cref="IOException"></exception>
public void Release()
{
- #region Java
- //JAVA: public void release() throws IOException {
- //JAVA: try {
- //JAVA: indexSDP.release(indexCommit);
- //JAVA: } finally {
- //JAVA: taxoSDP.release(taxoCommit);
- //JAVA: }
- //JAVA:
- //JAVA: try {
- //JAVA: indexWriter.deleteUnusedFiles();
- //JAVA: } finally {
- //JAVA: taxoWriter.getIndexWriter().deleteUnusedFiles();
- //JAVA: }
- //JAVA: }
- #endregion
-
try
{
indexSdp.Release(indexCommit);
@@ -228,7 +141,6 @@ namespace Lucene.Net.Replicator
}
}
- //.NET NOTE: Changed doc comment as the JAVA one seems to be a bit too much copy/paste
/// <summary>
/// Returns a map of the revision files from the given <see cref="IndexCommit"/>s of the search and taxonomy indexes.
/// </summary>
@@ -238,17 +150,6 @@ namespace Lucene.Net.Replicator
/// <exception cref="IOException"></exception>
public static IDictionary<string, IList<RevisionFile>> RevisionFiles(IndexCommit indexCommit, IndexCommit taxonomyCommit)
{
- #region Java
- //JAVA: /** Returns a singleton map of the revision files from the given {@link IndexCommit}. */
- //JAVA: public static Map<String, List<RevisionFile>> revisionFiles(IndexCommit indexCommit, IndexCommit taxoCommit)
- //JAVA: throws IOException {
- //JAVA: HashMap<String,List<RevisionFile>> files = new HashMap<>();
- //JAVA: files.put(INDEX_SOURCE, IndexRevision.revisionFiles(indexCommit).values().iterator().next());
- //JAVA: files.put(TAXONOMY_SOURCE, IndexRevision.revisionFiles(taxoCommit).values().iterator().next());
- //JAVA: return files;
- //JAVA: }
- #endregion
-
return new Dictionary<string, IList<RevisionFile>>{
{ INDEX_SOURCE, IndexRevision.RevisionFiles(indexCommit).Values.First() },
{ TAXONOMY_SOURCE, IndexRevision.RevisionFiles(taxonomyCommit).Values.First() }
@@ -263,12 +164,6 @@ namespace Lucene.Net.Replicator
/// <returns>a String representation of a revision's version from the given <see cref="IndexCommit"/>s of the search and taxonomy indexes.</returns>
public static string RevisionVersion(IndexCommit indexCommit, IndexCommit taxonomyCommit)
{
- #region Java
- //JAVA: public static String revisionVersion(IndexCommit indexCommit, IndexCommit taxoCommit) {
- //JAVA: return Long.toString(indexCommit.getGeneration(), RADIX) + ":" + Long.toString(taxoCommit.getGeneration(), RADIX);
- //JAVA: }
- #endregion
-
return string.Format("{0:X}:{1:X}", indexCommit.Generation, taxonomyCommit.Generation);
}
@@ -319,7 +214,7 @@ namespace Lucene.Net.Replicator
}
/// <summary>
- ///
+ /// TODO
/// </summary>
/// <param name="directory"></param>
/// <param name="config"></param>
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/IndexReplicationHandler.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/IndexReplicationHandler.cs b/src/Lucene.Net.Replicator/IndexReplicationHandler.cs
index 474361a..7edc95c 100644
--- a/src/Lucene.Net.Replicator/IndexReplicationHandler.cs
+++ b/src/Lucene.Net.Replicator/IndexReplicationHandler.cs
@@ -1,5 +1,3 @@
-//STATUS: DRAFT - 4.8.0
-
using System;
using System.Collections.Generic;
using System.IO;
@@ -7,7 +5,6 @@ using System.Linq;
using System.Text.RegularExpressions;
using Lucene.Net.Index;
using Lucene.Net.Store;
-using Lucene.Net.Support;
using Lucene.Net.Util;
using Directory = Lucene.Net.Store.Directory;
@@ -56,8 +53,7 @@ namespace Lucene.Net.Replicator
public class IndexReplicationHandler : IReplicationHandler
{
/// <summary>
- /// The component used to log messages to the {@link InfoStream#getDefault()
- /// default} <seealso cref="InfoStream"/>.
+ /// The component used to log messages to the <see cref="InfoStream"/>.
/// </summary>
public const string INFO_STREAM_COMPONENT = "IndexReplicationHandler";
@@ -78,32 +74,8 @@ namespace Lucene.Net.Replicator
/// Constructor with the given index directory and callback to notify when the
/// indexes were updated.
/// </summary>
- /// <param name="indexDirectory"></param>
- /// <param name="callback"></param>
- // .NET NOTE: Java uses a Callable<Boolean>, however it is never uses the returned value?
public IndexReplicationHandler(Directory indexDirectory, Func<bool?> callback)
{
- #region JAVA
- //JAVA: this.callback = callback;
- //JAVA: this.indexDir = indexDir;
- //JAVA: currentRevisionFiles = null;
- //JAVA: currentVersion = null;
- //JAVA: if (DirectoryReader.indexExists(indexDir))
- //JAVA: {
- //JAVA: final List<IndexCommit> commits = DirectoryReader.listCommits(indexDir);
- //JAVA: final IndexCommit commit = commits.get(commits.size() - 1);
- //JAVA: currentRevisionFiles = IndexRevision.revisionFiles(commit);
- //JAVA: currentVersion = IndexRevision.revisionVersion(commit);
- //JAVA: final InfoStream infoStream = InfoStream.getDefault();
- //JAVA: if (infoStream.isEnabled(INFO_STREAM_COMPONENT))
- //JAVA: {
- //JAVA: infoStream.message(INFO_STREAM_COMPONENT, "constructor(): currentVersion=" + currentVersion
- //JAVA: + " currentRevisionFiles=" + currentRevisionFiles);
- //JAVA: infoStream.message(INFO_STREAM_COMPONENT, "constructor(): commit=" + commit);
- //JAVA: }
- //JAVA: }
- #endregion
-
this.InfoStream = InfoStream.Default;
this.callback = callback;
this.indexDirectory = indexDirectory;
@@ -130,65 +102,6 @@ namespace Lucene.Net.Replicator
IDictionary<string, IList<string>> copiedFiles,
IDictionary<string, Directory> sourceDirectory)
{
- #region Java
- //JAVA: if (revisionFiles.size() > 1) {
- //JAVA: throw new IllegalArgumentException("this handler handles only a single source; got " + revisionFiles.keySet());
- //JAVA: }
- //JAVA:
- //JAVA: Directory clientDir = sourceDirectory.values().iterator().next();
- //JAVA: List<String> files = copiedFiles.values().iterator().next();
- //JAVA: String segmentsFile = getSegmentsFile(files, false);
- //JAVA:
- //JAVA: boolean success = false;
- //JAVA: try {
- //JAVA: // copy files from the client to index directory
- //JAVA: copyFiles(clientDir, indexDir, files);
- //JAVA:
- //JAVA: // fsync all copied files (except segmentsFile)
- //JAVA: indexDir.sync(files);
- //JAVA:
- //JAVA: // now copy and fsync segmentsFile
- //JAVA: clientDir.copy(indexDir, segmentsFile, segmentsFile, IOContext.READONCE);
- //JAVA: indexDir.sync(Collections.singletonList(segmentsFile));
- //JAVA:
- //JAVA: success = true;
- //JAVA: } finally {
- //JAVA: if (!success) {
- //JAVA: files.add(segmentsFile); // add it back so it gets deleted too
- //JAVA: cleanupFilesOnFailure(indexDir, files);
- //JAVA: }
- //JAVA: }
- //JAVA:
- //JAVA: // all files have been successfully copied + sync'd. update the handler's state
- //JAVA: currentRevisionFiles = revisionFiles;
- //JAVA: currentVersion = version;
- //JAVA:
- //JAVA: if (infoStream.isEnabled(INFO_STREAM_COMPONENT)) {
- //JAVA: infoStream.message(INFO_STREAM_COMPONENT, "revisionReady(): currentVersion=" + currentVersion
- //JAVA: + " currentRevisionFiles=" + currentRevisionFiles);
- //JAVA: }
- //JAVA:
- //JAVA: // update the segments.gen file
- //JAVA: writeSegmentsGen(segmentsFile, indexDir);
- //JAVA:
- //JAVA: // Cleanup the index directory from old and unused index files.
- //JAVA: // NOTE: we don't use IndexWriter.deleteUnusedFiles here since it may have
- //JAVA: // side-effects, e.g. if it hits sudden IO errors while opening the index
- //JAVA: // (and can end up deleting the entire index). It is not our job to protect
- //JAVA: // against those errors, app will probably hit them elsewhere.
- //JAVA: cleanupOldIndexFiles(indexDir, segmentsFile);
- //JAVA:
- //JAVA: // successfully updated the index, notify the callback that the index is
- //JAVA: // ready.
- //JAVA: if (callback != null) {
- //JAVA: try {
- //JAVA: callback.call();
- //JAVA: } catch (Exception e) {
- //JAVA: throw new IOException(e);
- //JAVA: }
- //JAVA: }
- #endregion
- //TODO: ArgumentOutOfRangeException more suited?
if (revisionFiles.Count > 1) throw new ArgumentException(string.Format("this handler handles only a single source; got {0}", revisionFiles.Keys));
Directory clientDirectory = sourceDirectory.Values.First();
@@ -246,7 +159,7 @@ namespace Lucene.Net.Replicator
}
}
- // .NET NOTE: Utility Method
+ //Note: LUCENENET Specific Utility Method
private void WriteToInfoStream(params string[] messages)
{
if (!InfoStream.IsEnabled(INFO_STREAM_COMPONENT))
@@ -260,25 +173,9 @@ namespace Lucene.Net.Replicator
/// Returns the last <see cref="IndexCommit"/> found in the <see cref="Directory"/>, or
/// <code>null</code> if there are no commits.
/// </summary>
- /// <param name="directory"></param>
- /// <returns></returns>
- /// <exception cref="System.IO.IOException"></exception>
+ /// <exception cref="IOException"></exception>
public static IndexCommit GetLastCommit(Directory directory)
{
- #region Java
- //JAVA: try {
- //JAVA: if (DirectoryReader.indexExists(dir)) {
- //JAVA: List<IndexCommit> commits = DirectoryReader.listCommits(dir);
- //JAVA: // listCommits guarantees that we get at least one commit back, or
- //JAVA: // IndexNotFoundException which we handle below
- //JAVA: return commits.get(commits.size() - 1);
- //JAVA: }
- //JAVA: } catch (IndexNotFoundException e) {
- //JAVA: // ignore the exception and return null
- //JAVA: }
- //JAVA: return null;
- #endregion
-
try
{
// IndexNotFoundException which we handle below
@@ -304,28 +201,8 @@ namespace Lucene.Net.Replicator
/// that this indicates an error in the Revision implementation.
/// </para>
/// </summary>
- /// <param name="files"></param>
- /// <param name="allowEmpty"></param>
- /// <returns></returns>
public static string GetSegmentsFile(IList<string> files, bool allowEmpty)
{
- #region Java
- //JAVA: if (files.isEmpty()) {
- //JAVA: if (allowEmpty) {
- //JAVA: return null;
- //JAVA: } else {
- //JAVA: throw new IllegalStateException("empty list of files not allowed");
- //JAVA: }
- //JAVA: }
- //JAVA:
- //JAVA: String segmentsFile = files.remove(files.size() - 1);
- //JAVA: if (!segmentsFile.startsWith(IndexFileNames.SEGMENTS) || segmentsFile.equals(IndexFileNames.SEGMENTS_GEN)) {
- //JAVA: throw new IllegalStateException("last file to copy+sync must be segments_N but got " + segmentsFile
- //JAVA: + "; check your Revision implementation!");
- //JAVA: }
- //JAVA: return segmentsFile;
- #endregion
-
if (!files.Any())
{
if (allowEmpty)
@@ -348,21 +225,8 @@ namespace Lucene.Net.Replicator
/// Cleanup the index directory by deleting all given files. Called when file
/// copy or sync failed.
/// </summary>
- /// <param name="directory"></param>
- /// <param name="files"></param>
public static void CleanupFilesOnFailure(Directory directory, IList<string> files)
{
- #region Java
- //JAVA: for (String file : files) {
- //JAVA: try {
- //JAVA: dir.deleteFile(file);
- //JAVA: } catch (Throwable t) {
- //JAVA: // suppress any exception because if we're here, it means copy
- //JAVA: // failed, and we must cleanup after ourselves.
- //JAVA: }
- //JAVA: }
- #endregion
-
foreach (string file in files)
{
try
@@ -379,35 +243,6 @@ namespace Lucene.Net.Replicator
public static void CleanupOldIndexFiles(Directory directory, string segmentsFile)
{
- #region Java
- //JAVA: try {
- //JAVA: IndexCommit commit = getLastCommit(dir);
- //JAVA: // commit == null means weird IO errors occurred, ignore them
- //JAVA: // if there were any IO errors reading the expected commit point (i.e.
- //JAVA: // segments files mismatch), then ignore that commit either.
- //JAVA: if (commit != null && commit.getSegmentsFileName().equals(segmentsFile)) {
- //JAVA: Set<String> commitFiles = new HashSet<>();
- //JAVA: commitFiles.addAll(commit.getFileNames());
- //JAVA: commitFiles.add(IndexFileNames.SEGMENTS_GEN);
- //JAVA: Matcher matcher = IndexFileNames.CODEC_FILE_PATTERN.matcher("");
- //JAVA: for (String file : dir.listAll()) {
- //JAVA: if (!commitFiles.contains(file)
- //JAVA: && (matcher.reset(file).matches() || file.startsWith(IndexFileNames.SEGMENTS))) {
- //JAVA: try {
- //JAVA: dir.deleteFile(file);
- //JAVA: } catch (Throwable t) {
- //JAVA: // suppress, it's just a best effort
- //JAVA: }
- //JAVA: }
- //JAVA: }
- //JAVA: }
- //JAVA: } catch (Throwable t) {
- //JAVA: // ignore any errors that happens during this state and only log it. this
- //JAVA: // cleanup will have a chance to succeed the next time we get a new
- //JAVA: // revision.
- //JAVA: }
- #endregion
-
try
{
IndexCommit commit = GetLastCommit(directory);
@@ -445,22 +280,11 @@ namespace Lucene.Net.Replicator
}
/// <summary>
- ///
+ /// Copies the provided list of files from the <see cref="source"/> <see cref="Directory"/> to the <see cref="target"/> <see cref="Directory"/>.
/// </summary>
- /// <param name="source"></param>
- /// <param name="target"></param>
- /// <param name="files"></param>
- /// <exception cref="System.IO.IOException"></exception>
+ /// <exception cref="IOException"></exception>
public static void CopyFiles(Directory source, Directory target, IList<string> files)
{
- #region Java
- //JAVA: if (!source.equals(target)) {
- //JAVA: for (String file : files) {
- //JAVA: source.copy(target, file, file, IOContext.READONCE);
- //JAVA: }
- //JAVA: }
- #endregion
-
if (source.Equals(target))
return;
@@ -473,24 +297,8 @@ namespace Lucene.Net.Replicator
/// the generation from the given <code>segmentsFile</code>. If it is <code>null</code>,
/// this method deletes segments.gen from the directory.
/// </summary>
- /// <param name="segmentsFile"></param>
- /// <param name="directory"></param>
public static void WriteSegmentsGen(string segmentsFile, Directory directory)
{
- #region Java
- //JAVA: public static void writeSegmentsGen(String segmentsFile, Directory dir) {
- //JAVA: if (segmentsFile != null) {
- //JAVA: SegmentInfos.writeSegmentsGen(dir, SegmentInfos.generationFromSegmentsFileName(segmentsFile));
- //JAVA: } else {
- //JAVA: try {
- //JAVA: dir.deleteFile(IndexFileNames.SEGMENTS_GEN);
- //JAVA: } catch (Throwable t) {
- //JAVA: // suppress any errors while deleting this file.
- //JAVA: }
- //JAVA: }
- //JAVA: }
- #endregion
-
if (segmentsFile != null)
{
SegmentInfos.WriteSegmentsGen(directory, SegmentInfos.GenerationFromSegmentsFileName(segmentsFile));
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/IndexRevision.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/IndexRevision.cs b/src/Lucene.Net.Replicator/IndexRevision.cs
index 930b120..5708bf1 100644
--- a/src/Lucene.Net.Replicator/IndexRevision.cs
+++ b/src/Lucene.Net.Replicator/IndexRevision.cs
@@ -3,7 +3,6 @@
using System;
using System.IO;
using System.Collections.Generic;
-using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
@@ -49,16 +48,6 @@ namespace Lucene.Net.Replicator
/// </remarks>
public class IndexRevision : IRevision
{
- #region Java
- //JAVA: private static final int RADIX = 16;
- //JAVA: private static final String SOURCE = "index";
- //JAVA: private final IndexWriter writer;
- //JAVA: private final IndexCommit commit;
- //JAVA: private final SnapshotDeletionPolicy sdp;
- //JAVA: private final String version;
- //JAVA: private final Map<String, List<RevisionFile>> sourceFiles;
- #endregion
-
private const string SOURCE = "index";
private readonly IndexWriter writer;
@@ -70,20 +59,6 @@ namespace Lucene.Net.Replicator
public IndexRevision(IndexWriter writer)
{
- #region Java
- //JAVA: public IndexRevision(IndexWriter writer) throws IOException {
- //JAVA: IndexDeletionPolicy delPolicy = writer.getConfig().getIndexDeletionPolicy();
- //JAVA: if (!(delPolicy instanceof SnapshotDeletionPolicy)) {
- //JAVA: throw new IllegalArgumentException("IndexWriter must be created with SnapshotDeletionPolicy");
- //JAVA: }
- //JAVA: this.writer = writer;
- //JAVA: this.sdp = (SnapshotDeletionPolicy) delPolicy;
- //JAVA: this.commit = sdp.snapshot();
- //JAVA: this.version = revisionVersion(commit);
- //JAVA: this.sourceFiles = revisionFiles(commit);
- //JAVA: }
- #endregion
-
sdp = writer.Config.IndexDeletionPolicy as SnapshotDeletionPolicy;
if (sdp == null)
throw new ArgumentException("IndexWriter must be created with SnapshotDeletionPolicy", "writer");
@@ -96,11 +71,6 @@ namespace Lucene.Net.Replicator
public int CompareTo(string version)
{
- #region Java
- //JAVA: long gen = Long.parseLong(version, RADIX);
- //JAVA: long commitGen = commit.getGeneration();
- //JAVA: return commitGen < gen ? -1 : (commitGen > gen ? 1 : 0);
- #endregion
long gen = long.Parse(version, NumberStyles.HexNumber);
long commitGen = commit.Generation;
//TODO: long.CompareTo(); but which goes where.
@@ -109,10 +79,6 @@ namespace Lucene.Net.Replicator
public int CompareTo(IRevision other)
{
- #region Java
- //JAVA: IndexRevision other = (IndexRevision)o;
- //JAVA: return commit.compareTo(other.commit);
- #endregion
//TODO: This breaks the contract and will fail if called with a different implementation
// This is a flaw inherited from the original source...
// It should at least provide a better description to the InvalidCastException
@@ -140,36 +106,12 @@ namespace Lucene.Net.Replicator
// returns a RevisionFile with some metadata
private static RevisionFile CreateRevisionFile(string fileName, Directory directory)
{
- #region Java
- //JAVA: private static RevisionFile newRevisionFile(String file, Directory dir) throws IOException {
- //JAVA: RevisionFile revFile = new RevisionFile(file);
- //JAVA: revFile.size = dir.fileLength(file);
- //JAVA: return revFile;
- //JAVA: }
- #endregion
return new RevisionFile(fileName, directory.FileLength(fileName));
}
/** Returns a singleton map of the revision files from the given {@link IndexCommit}. */
public static IDictionary<string, IList<RevisionFile>> RevisionFiles(IndexCommit commit)
{
- #region Java
- //JAVA: public static Map<String,List<RevisionFile>> revisionFiles(IndexCommit commit) throws IOException {
- //JAVA: Collection<String> commitFiles = commit.getFileNames();
- //JAVA: List<RevisionFile> revisionFiles = new ArrayList<>(commitFiles.size());
- //JAVA: String segmentsFile = commit.getSegmentsFileName();
- //JAVA: Directory dir = commit.getDirectory();
- //JAVA:
- //JAVA: for (String file : commitFiles) {
- //JAVA: if (!file.equals(segmentsFile)) {
- //JAVA: revisionFiles.add(newRevisionFile(file, dir));
- //JAVA: }
- //JAVA: }
- //JAVA: revisionFiles.add(newRevisionFile(segmentsFile, dir)); // segments_N must be last
- //JAVA: return Collections.singletonMap(SOURCE, revisionFiles);
- //JAVA: }
- #endregion
-
List<RevisionFile> revisionFiles = commit.FileNames
.Where(file => !string.Equals(file, commit.SegmentsFileName))
.Select(file => CreateRevisionFile(file, commit.Directory))
@@ -189,11 +131,6 @@ namespace Lucene.Net.Replicator
/// <returns></returns>
public static string RevisionVersion(IndexCommit commit)
{
- #region Java
- //JAVA: public static String revisionVersion(IndexCommit commit) {
- //JAVA: return Long.toString(commit.getGeneration(), RADIX);
- //JAVA: }
- #endregion
return commit.Generation.ToString("X");
}
}