public Task StartParseWikiJob(GrainCancellationToken cancellationToken) { var saveDir = GetCloneDirectory(); //TODO Parseflow return(Task.CompletedTask); }
public Task CancellationTokenCallbackThrow(GrainCancellationToken tc) { tc.CancellationToken.Register(() => { throw new InvalidOperationException("From cancellation token callback"); }); return(Task.CompletedTask); }
public Task <string> SayHello(string name, GrainCancellationToken grainCancellationToken) { if (!grainCancellationToken.CancellationToken.IsCancellationRequested) { return(Task.FromResult(Say.hello(name))); } return(null); }
public Task AcceptMessageAsync(AnonymousMessage message, GrainCancellationToken cancellationToken) { return(Task.WhenAll( State.ConnectionIds .Where(connId => !message.Excluding.Contains(connId)) .Select(connId => GrainFactory.GetGrain <IClientGrain>(connId)) .Select(client => client.AcceptMessageAsync(message.Payload, cancellationToken)) ).WithCancellation(cancellationToken.CancellationToken)); }
public Task StartExecutingAsync(GrainCancellationToken cancellation) { var waitHandle = new ManualResetEventSlim(false); RunPollLoopOnThreadpool(cancellation.CancellationToken, waitHandle); RunMessageProcessingLoop(cancellation.CancellationToken, waitHandle); return(Task.CompletedTask); }
public Task CancelRemoteToken(GrainCancellationToken token) { GrainCancellationToken gct; if (!_cancellationTokens.TryFind(token.Id, out gct)) { _logger.Value.Error(ErrorCode.CancellationTokenCancelFailed, $"Remote token cancellation failed: token with id {token.Id} was not found"); return TaskDone.Done; } return gct.Cancel(); }
public async Task <string> SayHello(string name, GrainCancellationToken grainCancellationToken) { string result = null; if (!grainCancellationToken.CancellationToken.IsCancellationRequested && await _featureManagerSnapshot.IsEnabledAsync("FeatureA")) { result = Say.hello(name) + $" Grain reference - {IdentityString}"; } return(result); }
public Task CancelRemoteToken(GrainCancellationToken token) { GrainCancellationToken gct; if (!_cancellationTokens.TryFind(token.Id, out gct)) { _logger.Value.Error(ErrorCode.CancellationTokenCancelFailed, $"Remote token cancellation failed: token with id {token.Id} was not found"); return(Task.CompletedTask); } return(gct.Cancel()); }
public async Task <DotNetRuProfiles.Models.Profile.Profile> GetProfile(GrainCancellationToken grainCancellationToken) { var path = Path.Combine( Directory.GetCurrentDirectory(), "AnatolyKulakov\\SpbDotNet.wiki.git\\", $"{this.GetPrimaryKeyString()}.md" ); var file = await File.ReadAllTextAsync(path); return(await _markdownParser.Extract <DotNetRuProfiles.Models.Profile.Profile>(file)); }
public async Task <string> GetAllSerialized(GrainCancellationToken cancellationToken = null) { _logger.Info($"{GetType().Name}.{nameof(GetAllSerialized)}() started..."); var collection = await _tarantoolUtils.GetIndex <T>(); if (cancellationToken == null) { return(JsonConvert.SerializeObject(collection)); } var serialized = JsonConvert.SerializeObject(collection); return(serialized); }
public async Task <string> GetAllSerialized(GrainCancellationToken cancellationToken = null) { _logger.Info($"{GetType().Name}.{nameof(GetAllSerialized)}() started..."); var collection = await _mongoUtils.GetCollection <T>(); if (cancellationToken == null) { return(JsonConvert.SerializeObject(await collection.AsQueryable().ToListAsync())); } var serialized = JsonConvert.SerializeObject(await collection.AsQueryable().ToListAsync(cancellationToken.CancellationToken)); return(serialized); }
public Task StartFetchWikiJob(GrainCancellationToken cancellationToken) { var repolink = this.GetPrimaryKeyString(); var saveDir = GetCloneDirectory(); if (Directory.Exists(saveDir)) { FetchRepo(repolink); } else { CloneRepo(repolink, saveDir); } return(Task.CompletedTask); }
public async Task LongIoWork(GrainCancellationToken tc, TimeSpan delay) { logger.LogInformation("LongIoWork"); var timesamp = DateTimeOffset.UtcNow; while (!tc.CancellationToken.IsCancellationRequested && (DateTimeOffset.UtcNow - timesamp) < delay) { await IoOperation(tc.CancellationToken); } if (tc.CancellationToken.IsCancellationRequested) { logger.LogInformation("Cancel"); } else { logger.LogInformation("timeout"); } }
public Task <bool> CancellationTokenCallbackResolve(GrainCancellationToken tc) { var tcs = new TaskCompletionSource <bool>(); var orleansTs = TaskScheduler.Current; tc.CancellationToken.Register(() => { if (TaskScheduler.Current != orleansTs) { tcs.SetException(new Exception("Callback executed on wrong thread")); } else { tcs.SetResult(true); } }); return(tcs.Task); }
public async Task LongWait(GrainCancellationToken tc, TimeSpan delay) { await Task.Delay(delay, tc.CancellationToken); }
public async Task <Immutable <Map2D <TExport>[]> > Render(RenderingOptions options, Complex center, double scale, double scaleMultiplier, int frames, GrainCancellationToken cancellationToken = null) { var rendererTasks = new Task <Immutable <Map2D <TExport> > > [frames]; var currentScale = scale; // Render all frames for (int i = 0; i < frames; i++) { var renderer = GrainFactory.GetGrain <IFrameRenderer <TExport> >(Guid.NewGuid()); rendererTasks[i] = renderer.RenderFrame(options, center, currentScale, cancellationToken); currentScale *= scaleMultiplier; } // Wait for the rendering to finish var combinedTask = Task.WhenAll(rendererTasks); await combinedTask; // TODO: exception handling cancellationToken?.CancellationToken.ThrowIfCancellationRequested(); var readyFrames = new Map2D <TExport> [frames]; for (int i = 0; i < frames; i++) { readyFrames[i] = rendererTasks[i].Result.Value; } return(new Immutable <Map2D <TExport>[]>(readyFrames)); }
public async Task AcceptMessageAsync(HubInvocationMessage message, GrainCancellationToken cancellationToken) { var handle = await rewoundMessagesGrain.PushMessageAsync(message); observers.Notify(x => x.ReceiveMessage(message, handle)); }
public async Task <string> GetAllSerialized(GrainCancellationToken cancellationToken = null) => await(await GetGrain()).GetAllSerialized();
public Entry(GrainCancellationToken token) { Token = token; _createdTime = Stopwatch.GetTimestamp(); }
private async Task DispatchRenderMovie(Guid requestIdentifier, Complex center, double scale, double scaleMultiplier, int frames, GrainCancellationToken cancellationToken = null) { var movieRenderer = GrainFactory.GetGrain <IMovieRenderer <TExport> >(Guid.NewGuid()); var rendered = await movieRenderer.Render(State, center, scale, scaleMultiplier, frames, cancellationToken); _observerManager.Notify(o => o.ReceiveRenderedMovie(requestIdentifier, rendered)); }
public Task <bool> BeginRenderMovie(Guid requestIdentifier, Complex center, double scale, double scaleMultiplier, int frames, GrainCancellationToken cancellationToken = null) { DispatchRenderMovie(requestIdentifier, center, scale, scaleMultiplier, frames, cancellationToken); return(Task.FromResult(true)); }
public async Task <ICollection <T> > GetAllCollection(GrainCancellationToken cancellationToken = null) => JsonConvert.DeserializeObject <ICollection <T> >(await GetAllSerialized(cancellationToken));
public async Task DoAsyncWork(TimeSpan waitTime, GrainCancellationToken gct) { await Task.Delay(waitTime, gct.CancellationToken); }
public async Task <Immutable <Map2D <TExport> > > RenderFrame(RenderingOptions options, Complex center, double scale, GrainCancellationToken cancellationToken = null) { // Prepare a frame to return var frame = new Map2D <TExport>(options.FrameWidth, options.FrameHeight); // Load initial values var initialSet = PrepareInitialValues(options.FrameWidth, options.FrameHeight, center, scale); // Compute in batches var batchCount = (int)Math.Ceiling(frame.Raw.Length / (double)options.BatchSize); var batchTasks = new Task <Immutable <TExport[]> > [batchCount]; for (int i = 0; i < batchCount; i++) { var newBatch = GrainFactory.GetGrain <IRenderBatch <TExport> >(Guid.NewGuid()); var startPoint = i * options.BatchSize; var count = Math.Min(options.BatchSize, frame.Raw.Length - startPoint); var buffer = new Span <Complex>(initialSet, startPoint, count).ToArray(); batchTasks[i] = newBatch.Compute(options, buffer, cancellationToken); } // Wait for the workers to finish var combinedTask = Task.WhenAll(batchTasks); // TODO: exception handling await combinedTask; cancellationToken?.CancellationToken.ThrowIfCancellationRequested(); // Import the results... for (int i = 0; i < batchCount; i++) { var startPoint = i * options.BatchSize; batchTasks[i].Result.Value.CopyTo(frame.Raw, startPoint); } // ... and send them back to the requestor. return(new Immutable <Map2D <TExport> >(frame)); }
public Task RemoveFromGroupAsync(string connectionId, GrainCancellationToken cancellationToken) { dirty = State.ConnectionIds.Remove(connectionId) || dirty; return(Task.CompletedTask); }
public Task <bool> StartAsync(TRequest request, GrainCancellationToken cancellationToken) { return(StartAsync(request, cancellationToken.CancellationToken)); }
public async Task CallOtherLongRunningTask(ILongRunningTaskGrain <T> target, GrainCancellationToken tc, TimeSpan delay) { await target.LongWait(tc, delay); }
public Task <Immutable <TExport[]> > Compute(RenderingOptions options, Complex[] coordinates, GrainCancellationToken cancellationToken = null) { var bailout = options.BailoutValue * options.BailoutValue; var maxIteration = options.MaxIteration; var values = new TExport[coordinates.Length]; for (int n = 0; n < coordinates.Length; n++) { // Kill on request cancellationToken?.CancellationToken.ThrowIfCancellationRequested(); var i = 0; var newVal = Complex.Zero; while (newVal.Real * newVal.Real + newVal.Imaginary * newVal.Imaginary <= bailout && i < maxIteration) { var tempVal = newVal * newVal + coordinates[n]; // Local periodicity checking if (tempVal == newVal) { i = maxIteration - 1; } newVal = tempVal; ++i; } values[n] = (TExport)Convert.ChangeType(i, typeof(TExport)); } return(Task.FromResult(new Immutable <TExport[]>(values))); }
public Task SendAsync(T t, GrainCancellationToken gct) { throw new NotImplementedException(); }
public Task AddToUserAsync(string connectionId, GrainCancellationToken cancellationToken) { dirty = State.ConnectionIds.Add(connectionId) || dirty; return(Task.CompletedTask); }