private async Task InjectDependencies() { catalog.SiloStatusOracle = this.siloStatusOracle; this.siloStatusOracle.SubscribeToSiloStatusEvents(localGrainDirectory); // consistentRingProvider is not a system target per say, but it behaves like the localGrainDirectory, so it is here this.siloStatusOracle.SubscribeToSiloStatusEvents((ISiloStatusListener)RingProvider); this.siloStatusOracle.SubscribeToSiloStatusEvents(Services.GetRequiredService <DeploymentLoadPublisher>()); var reminderTable = Services.GetService <IReminderTable>(); if (reminderTable != null) { logger.Info($"Creating reminder grain service for type={reminderTable.GetType()}"); // Start the reminder service system target var timerFactory = this.Services.GetRequiredService <IAsyncTimerFactory>(); reminderService = new LocalReminderService(this, reminderTable, this.initTimeout, this.loggerFactory, timerFactory); this.Services.GetService <SiloLoggingHelper>()?.RegisterGrainService(reminderService); RegisterSystemTarget((SystemTarget)reminderService); } RegisterSystemTarget(catalog); await LocalScheduler.QueueActionAsync(catalog.Start, catalog) .WithTimeout(initTimeout, $"Starting Catalog failed due to timeout {initTimeout}"); // SystemTarget for provider init calls this.fallbackScheduler = Services.GetRequiredService <FallbackSystemTarget>(); RegisterSystemTarget(fallbackScheduler); }
public DockingViewManager(ITransport transport, IAdapter adapter, IScheduler scheduler, LocalScheduler dispatcher) { _transport = transport; _adapter = adapter; _scheduler = scheduler; _dispatcher = dispatcher; }
public DurationTraderViewModelController(ITransport transport, IAdapter adapter, IScheduler scheduler, LocalScheduler dispatcher) { transport.GetTradingObservables() .SubscribeOn(scheduler) .ObserveOn(dispatcher) .Subscribe(fSet => adapter.updater(fSet, ViewModel)); }
protected WorkItem(LocalScheduler scheduler, DateTimeOffset dueTime) { Scheduler = scheduler; DueTime = dueTime; _hasRun = 0; }
private void OpenProject(object sender, RoutedEventArgs e) { var openDialog = new OpenFileDialog { Filter = "GradRooAte Project (*.grdb)|*.grdb", DefaultExt = "grdb", Title = "Open project" }; var ok = openDialog.ShowDialog(); if (!ok.GetValueOrDefault()) { return; } var path = openDialog.FileName; try { client = LocalScheduler.Connect(path); } catch (Exception ex) { // TODO: Use well formatted errors MessageBox.Show($"Could not open database: {ex.Message}"); return; } DialogResult = true; Close(); }
internal static void Register(LocalScheduler scheduler) { // // LocalScheduler maintains per-instance work queues that need revisiting // upon system clock changes. We need to be careful to avoid keeping those // scheduler instances alive by the system clock monitor, so we use weak // references here. In particular, AsyncLockScheduler in ImmediateScheduler // can have a lot of instances, so we need to collect spurious handlers // at regular times. // lock (s_systemClockChanged) { #if NO_WEAKREFOFT s_systemClockChanged.Add(new WeakReference(scheduler, false)); #else s_systemClockChanged.Add(new WeakReference <LocalScheduler>(scheduler)); #endif if (s_systemClockChanged.Count == 1) { s_systemClockChangedHandlerCollector = ConcurrencyAbstractionLayer.Current.StartPeriodicTimer(CollectHandlers, TimeSpan.FromSeconds(30)); } else if (s_systemClockChanged.Count % 64 == 0) { CollectHandlers(); } } }
private async Task OnBecomeActiveStop(CancellationToken ct) { if (this.isFastKilledNeeded) { return; } bool gracefully = !ct.IsCancellationRequested; string operation = gracefully ? "Shutdown()" : "Stop()"; try { if (gracefully) { logger.Info(ErrorCode.SiloShuttingDown, "Silo starting to Shutdown()"); //Stop LocalGrainDirectory await LocalScheduler.QueueTask(() => localGrainDirectory.Stop(true), localGrainDirectory.CacheValidator) .WithCancellation(ct, "localGrainDirectory Stop failed because the task was cancelled"); SafeExecute(() => catalog.DeactivateAllActivations().Wait(ct)); //wait for all queued message sent to OutboundMessageQueue before MessageCenter stop and OutboundMessageQueue stop. await Task.Delay(WaitForMessageToBeQueuedForOutbound); } } catch (Exception exc) { logger.Error(ErrorCode.SiloFailedToStopMembership, $"Failed to {operation}. About to FastKill this silo.", exc); this.isFastKilledNeeded = true; } // Stop the gateway SafeExecute(messageCenter.StopAcceptingClientMessages); SafeExecute(() => catalog?.Stop()); }
private async Task OnBecomeActiveStop(CancellationToken ct) { if (this.isFastKilledNeeded) { return; } bool gracefully = !ct.IsCancellationRequested; try { if (gracefully) { // Stop LocalGrainDirectory await LocalScheduler.QueueTask(() => localGrainDirectory.Stop(true), localGrainDirectory.CacheValidator) .WithCancellation(ct, "Failed to stop local grain directory gracefully before cancellation"); SafeExecute(() => catalog.DeactivateAllActivations().Wait(ct)); // Wait for all queued message sent to OutboundMessageQueue before MessageCenter stop and OutboundMessageQueue stop. await Task.Delay(WaitForMessageToBeQueuedForOutbound); } } catch (Exception exc) { logger.LogError( (int)ErrorCode.SiloFailedToStopMembership, exc, "Failed to shutdown gracefully. About to terminate ungracefully"); this.isFastKilledNeeded = true; } // Stop the gateway SafeExecute(messageCenter.StopAcceptingClientMessages); SafeExecute(() => catalog?.Stop()); }
/// <summary> Return dump of diagnostic data from this silo. </summary> /// <param name="all"></param> /// <returns>Debug data for this silo.</returns> public string GetDebugDump(bool all = true) { var sb = new StringBuilder(); foreach (var systemTarget in activationDirectory.AllSystemTargets()) { sb.AppendFormat("System target {0}:", ((ISystemTargetBase)systemTarget).GrainId.ToString()).AppendLine(); } var enumerator = activationDirectory.GetEnumerator(); while (enumerator.MoveNext()) { Utils.SafeExecute(() => { var activationData = enumerator.Current.Value; var workItemGroup = LocalScheduler.GetWorkItemGroup(activationData); if (workItemGroup == null) { sb.AppendFormat("Activation with no work item group!! Grain {0}, activation {1}.", activationData.GrainId, activationData.ActivationId); sb.AppendLine(); return; } if (all || activationData.State.Equals(ActivationState.Valid)) { sb.AppendLine(workItemGroup.DumpStatus()); sb.AppendLine(activationData.DumpStatus()); } }); } logger.Info(ErrorCode.SiloDebugDump, sb.ToString()); return(sb.ToString()); }