lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <>
Subject [jira] [Commented] (LUCENENET-565) Port Lucene.Net.Replicator
Date Tue, 08 Aug 2017 09:16:00 GMT


ASF GitHub Bot commented on LUCENENET-565:

Github user AndyPook commented on the issue:
    Making ```Perform``` async could be done like... 
            public async Task PerformAsync(IReplicationRequest request, IReplicationResponse
                    switch (action)
                        case ReplicationAction.OBTAIN:
                            string sessionId = ExtractRequestParam(request, REPLICATE_SESSION_ID_PARAM);
                            string fileName = ExtractRequestParam(request, REPLICATE_FILENAME_PARAM);
                            string source = ExtractRequestParam(request, REPLICATE_SOURCE_PARAM);
                            using (Stream stream = replicator.ObtainFile(sessionId, source,
                                await stream.CopyToAsync(response.Body);
                        case ReplicationAction.RELEASE:
                            replicator.Release(ExtractRequestParam(request, REPLICATE_SESSION_ID_PARAM));
                        case ReplicationAction.UPDATE:
                            string currentVersion = request.QueryParam(REPLICATE_VERSION_PARAM);
                            SessionToken token = replicator.CheckForUpdate(currentVersion);
                            if (token == null)
                                await response.Body.WriteAsync(new byte[] { 0 }, 0, 1); //
marker for null token
                                await response.Body.WriteAsync(new byte[] { 1 }, 0, 1);
                                token.Serialize(new DataOutputStream(response.Body));
                            throw new ArgumentOutOfRangeException();
    Note ```CopyToAsync``` and ```WriteAsync```. It's a shame that DataOutputStream isn't
async. A little out of scope for this though :)
    On the trivia front. The ReplicatorBuilder fluent methods can just ```return this``` rather
than newing up another builder each time.
    Shouldn't the template building part be
    string template = (string.IsNullOrWhiteSpace(urlPrefix) ? "" : urlPrefix) +
    Otherwise the template would not start with "/" if urlPrefix was missing and it would
    Though I would suggest that urlPrefix should be mandatory. Otherwise it will steal all
the requests from whatever comes next in the middleware pipeline.
    Q: Why do you say it's "horrible to block the default route"?
    This seems entirely natural to me :) Even back in asp you could add handlers that would
intercept certain paths/extensions. It doesn't seem any different to Swagger intercepting
"/swagger". Or OAuth intercepting it's control flow.
    Lastly, an observation... My intent with using the template was that the Perform method
would be refactored to accept the parts from the route. If you want to leave the Perform method
as is (closer to java implementation I'm guessing) which parses the path and qs then the ```MapWhen```
approach might be better/simpler...
    		public static void UseLuceneReplicator3(this IApplicationBuilder app, string urlPrefix,
object indexService)
    			if (string.IsNullOrEmpty(urlPrefix) || !urlPrefix.StartsWith("/"))
    				throw new ArgumentException("urlPrefix MUST be provided");
    			var replicatorAccessor = app.ApplicationServices.GetService<IReplicatorAccessor>();
    			var replicationService = new ReplicationService(replicatorAccessor.Replicators);
    			app.MapWhen(context => context.Request.Path.StartsWithSegments(urlPrefix), appBuilder
    				appBuilder.Run(async context =>
    					await replicationService.PerformAsync(
    						new AspNetCoreReplicationRequest(context.Request), 
    						new AspNetCoreReplicationResponse(context.Response));
    As the accessor and service are singletons, they only need resolving once rather than
every request.
    Lastly, the template we've been looking at has a {context] segement, however the Perform
method only parses 'shard' and 'action'. Is that significant?
    Just stream of thought and observations :)

> Port Lucene.Net.Replicator
> --------------------------
>                 Key: LUCENENET-565
>                 URL:
>             Project: Lucene.Net
>          Issue Type: Task
>          Components: Lucene.Net.Replicator
>    Affects Versions: Lucene.Net 4.8.0
>            Reporter: Shad Storhaug
>            Priority: Minor
>              Labels: features

This message was sent by Atlassian JIRA

View raw message