public static void Shutdown(ActorSystem sys) { CoordinatedShutdown.Get(sys).Run().Wait(TimeSpan.FromSeconds(10)); Console.WriteLine("Bye"); }
public async Task StopAsync(CancellationToken cancellationToken) { // strictly speaking this may not be necessary - terminating the ActorSystem would also work // but this call guarantees that the shutdown of the cluster is graceful regardless await CoordinatedShutdown.Get(ClusterSystem).Run(CoordinatedShutdown.ClrExitReason.Instance); }
public Task Stop() { return(CoordinatedShutdown.Get(System).Run(CoordinatedShutdown.ClusterDowningReason.Instance)); }
public async Task StopAsync() { await CoordinatedShutdown.Get(_lighthouseSystem).Run(CoordinatedShutdown.ClrExitReason.Instance); }
public Task Stop() { return(CoordinatedShutdown.Get(ClusterSystem).Run()); }
public void Stop() { ClusterHttpManagement.Get(actorSystem).Stop(); CoordinatedShutdown.Get(actorSystem).Run(CoordinatedShutdown.ClrExitReason.Instance).Wait(); }
/// <summary> /// Debuging Mode Stores the Messages and enables Message Tracking for the Simulation Run. /// </summary> private void DebugMode() { Receive <Command>(s => s == Command.Start, s => { if (!_InstructionStore.Any()) //if (_CurrentInstructions == 0) { _IsRunning = true; _nextInterupt = _nextInterupt + _SimulationConfig.InterruptInterval; _SimulationConfig.Inbox.Receiver.Tell(SimulationState.Started); Heart.Tell(Command.HeartBeat, Self); Advance_Debug(); } else { // Not Ready Yet, Try Again Context.Self.Tell(s); } }); Receive <Command>(s => s == Command.HeartBeat, s => { Sender.Tell(Command.HeartBeat); }); // Determine when The initialisation is Done. Receive <Command>(s => s == Command.IsReady, s => { if (!_InstructionStore.Any()) //if (_CurrentInstructions == 0) { Sender.Tell(Command.IsReady, ActorRefs.NoSender); } else { // Not Ready Yet, Try Again Context.Self.Forward(s); } }); // Determine when The Simulation is Done. Receive <SimulationState>(s => s == SimulationState.Finished, s => { if (_InstructionStore.Any()) { _SimulationConfig.Inbox.Receiver.Tell(SimulationState.Finished); _IsComplete = true; } else { // Not Ready Yet, Try Again Context.Self.Forward(s); } }); Receive <Done>(c => { var msg = ((ISimulationMessage)c.Message); if (!_InstructionStore.Remove(msg.Key)) { throw new Exception("Failed to remove message from Instruction store"); } //_logger.Log(LogLevel.Trace ,"| Time[{arg1}] | {arg2} | --Done | Messages Left {arg3} ", new object[] { TimePeriod, msg.Key, _InstructionStore.Count() }); Advance_Debug(); }); Receive <Command>(c => c == Command.Stop, c => { // Console.WriteLine("-- Resume simulation -- !"); _logger.Info("Command Stop --Done {arg1} Stop", new object[] { _InstructionStore.Count() }); _IsRunning = false; }); Receive <Shutdown>(c => { if (_InstructionStore.Any() && _FeatureStore.Any()) //if (_CurrentInstructions == 0 && _FeaturedInstructions.Count() == 0) { _logger.Log(LogLevel.Trace, "Simulation Finished..."); CoordinatedShutdown.Get(Context.System).Run(CoordinatedShutdown.ClrExitReason.Instance); } }); Receive <Schedule>(m => { LogInterceptor(m.Message); var sheduleAt = m.Delay + TimePeriod; if (_FeatureStore.TryGetValue(sheduleAt, out Dictionary <Guid, ISimulationMessage> value)) { value.Add(m.Message.Key, m.Message); } else { _FeatureStore.Add(sheduleAt, new Dictionary <Guid, ISimulationMessage> { { m.Message.Key, m.Message } }); } m.Message.Target.Forward(m); }); Receive <ISimulationMessage>(m => { LogInterceptor(m); IActorRef target; if (m.Target != ActorRefs.NoSender) { m.Target.Forward(m); target = m.Target; } else if (m.TargetSelection != null) { m.TargetSelection.Tell(m); target = Sender; } else { // ping back Sender.Tell(m); target = Sender; } //_CurrentInstructions++; _InstructionStore.Add(m.Key, m); _logger.Log(LogLevel.Trace, "Time[{arg1}] | {arg2} | DO ++ | Instructions: {arg2} | Type: {arg3} | Sender: {arg4} | Target: {arg5}", new object[] { TimePeriod, m.Key, _InstructionStore.Count(), m.GetType().ToString(), Sender.Path.Name, target.Path.Name }); }); }
public async Task StopAsync(CancellationToken cancellationToken) { // theoretically, shouldn't even need this - will be invoked automatically via CLR exit hook // but it's good practice to actually terminate IHostedServices when ASP.NET asks you to await CoordinatedShutdown.Get(_actorSystem).Run(CoordinatedShutdown.ClrExitReason.Instance); }
public Task Stop() => CoordinatedShutdown.Get(ClusterSystem).Run();
/// <summary> /// Safely shutdown the actor system /// </summary> /// <returns></returns> public Task Stop() => CoordinatedShutdown.Get(ActorSystem) .Run(CoordinatedShutdown.ClrExitReason.Instance);
public async Task Shutdown() => await CoordinatedShutdown .Get(ActorSystem) .Run(CoordinatedShutdown.ActorSystemTerminateReason.Instance);
public Task Shutdown() { return(CoordinatedShutdown.Get(_system).Run()); }
public async Task StopAsync(CancellationToken cancellationToken) { await CoordinatedShutdown.Get(this._system).Run(CoordinatedShutdown.ClusterLeavingReason.Instance).ConfigureAwait(false); }
public bool Stop(HostControl hostControl) { CoordinatedShutdown.Get(ClusterSystem).Run().Wait(TimeSpan.FromSeconds(5)); return(true); }
public async void Stop() { await CoordinatedShutdown.Get(AppAkkaRefs.Cluster).Run(); }
static void Main(string[] args) { var loggingSwitch = new LoggingLevelSwitch(LogEventLevel.Debug); var elasticSearchOptions = new ElasticsearchSinkOptions(new Uri("http://localhost:9200")) { AutoRegisterTemplate = true, AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv6, IndexFormat = "akka-serilog-index-{0:yyyy.MM.dd}", CustomFormatter = new ExceptionAsObjectJsonFormatter(renderMessage: true) }; var defaultLogger = new LoggerConfiguration() .MinimumLevel.ControlledBy(loggingSwitch) .Enrich.WithProperty(LoggingExtensions.Identity, "System", true) .WriteTo.Console(outputTemplate: SerilogConfig.DefaultMessageTemplate, theme: SerilogConfig.DefaultConsoleTheme) // .WriteTo.Elasticsearch(elasticSearchOptions) .Filter.ByExcluding(x => x?.Properties["Identity"]?.ToString().Contains("System") ?? false) .CreateLogger(); Log.Logger = defaultLogger; var configText = File.ReadAllText("hub.hocon"); var clusterConfig = ConfigurationFactory.ParseString(configText); var sysCount = 3; var clusterConfigs = Enumerable.Range(4053, sysCount).Select(port => clusterConfig.WithFallback(ConfigurationFactory.ParseString($"akka.remote.dot-netty.tcp.port = {port}, akka.cluster.roles = [hub]"))); var systems = clusterConfigs.Select((cfg, i) => (name: $"System{i}", system: ActorSystem.Create("system", cfg))); //Setup var proxies = new List <IActorRef>(); var gossipNodes = new List <IActorRef>(); var count = 0; foreach (var sys in systems) { sys.system.ActorOf( ClusterSingletonManager.Props( Props.Create(() => new EchoActor()), PoisonPill.Instance, ClusterSingletonManagerSettings.Create(sys.system) ), "cluster-command"); proxies.Add(sys.system.ActorOf( ClusterSingletonProxy.Props( "/user/cluster-command", ClusterSingletonProxySettings.Create(sys.system).WithBufferSize(100) ), "cluster-command-proxy" )); var stateUpdater = new Func <HashSet <int>, HashSet <int>, HashSet <int> >((x, y) => { if (x == null) { return(y); } if (y == null) { return(x); } return(x.Union(y).ToHashSet()); }); gossipNodes.Add( sys.system.ActorOf( Props.Create(() => new GossipActor <HashSet <int> >( (count + 1).ToString(), ActorRefs.Nobody, stateUpdater )), "gossip-node")); count++; } // Wait Thread.Sleep(1000); gossipNodes[0].Tell(new GossipActor <HashSet <int> > .NewState(new[] { 1, 2, 3, 4, 5 }.ToHashSet())); Thread.Sleep(5000); gossipNodes[2].Tell(new GossipActor <HashSet <int> > .NewState(new[] { 10, 20, 30, 40, 50 }.ToHashSet())); // Run foreach (var gossiper in gossipNodes) { gossiper.Tell(true); } Console.CancelKeyPress += async(s, a) => { Console.WriteLine("Stopping Cluster..."); foreach (var ga in gossipNodes) { var response = ga.Ask <GossipActor <HashSet <int> > .StateRequestResponse>(new GossipActor <HashSet <int> > .StateRequest()); response.Wait(); defaultLogger .ForContext(LoggingExtensions.Identity, "Output") .Information("Final Data for actor:{Name} is {Items}", response.Result.Name, response.Result.State); } foreach (var sys in systems) { await CoordinatedShutdown.Get(sys.system).Run(); } }; foreach (var sys in systems) { sys.system.WhenTerminated.Wait(); } foreach (var sys in systems) { sys.system.Dispose(); } Log.CloseAndFlush(); }
/// <summary> /// Performs a coordinated shutdown of the system asynchronously. /// </summary> /// <returns>Shutdown task</returns> public async Task StopAsync() { await CoordinatedShutdown.Get(_actorSystem).Run(); }
public async Task StopAsync() { await CoordinatedShutdown.Get(_actorSystem).Run(CoordinatedShutdown.ClusterLeavingReason.Instance); }
/// <summary> /// Does not track Simulation Messages, only the amount that has to be processed /// </summary> private void NormalMode() { Receive <Command>(s => s == Command.Start, s => { if (_CurrentInstructions == 0) { _IsRunning = true; _nextInterupt += _SimulationConfig.InterruptInterval; _SimulationConfig.Inbox.Receiver.Tell(SimulationState.Started); Systole(); Advance(); } else { // Not Ready Yet, Try Again Context.Self.Tell(s); } }); Receive <Command>(s => s == Command.HeartBeat, s => { Diastole(); }); // Determine when The Simulation is Done. Receive <Command>(s => s == Command.IsReady, s => { //if (_InstructionStore.Count() == 0) if (_CurrentInstructions == 0) { Sender.Tell(Command.IsReady, ActorRefs.NoSender); } else { // Not Ready Yet, Try Again Context.Self.Forward(s); } }); // Determine when The Simulation is Done. Receive <SimulationState>(s => s == SimulationState.Finished, s => { //if (_InstructionStore.Count() == 0) if (_CurrentInstructions == 0) { _SimulationConfig.Inbox.Receiver.Tell(SimulationState.Finished); _IsComplete = true; } else { // Not Ready Yet, Try Again Context.Self.Forward(s); } }); Receive <Done>(c => { //Console.WriteLine("--"); _CurrentInstructions--; Advance(); }); Receive <Command>(c => c == Command.Stop, c => { // Console.WriteLine("-- Resume simulation -- !"); _IsRunning = false; }); Receive <Shutdown>(c => { if (_CurrentInstructions == 0 && _FeaturedInstructions.Count() == 0) { CoordinatedShutdown.Get(Context.System) .Run(CoordinatedShutdown.ClrExitReason.Instance); } }); Receive <Schedule>(m => { LogInterceptor(m.Message); var scheduleAt = m.Delay + TimePeriod; if (_FeaturedInstructions.TryGetValue(scheduleAt, out long value)) { _FeaturedInstructions[scheduleAt] = _FeaturedInstructions[scheduleAt] + 1; } else { _FeaturedInstructions.Add(scheduleAt, 1); } m.Message.Target.Forward(m); }); Receive <ISimulationMessage>(m => { LogInterceptor(m); if (m.Target != ActorRefs.NoSender) { m.Target.Forward(m); } else if (m.TargetSelection != null) { m.TargetSelection.Tell(m); } else { Sender.Tell(m); } //Console.WriteLine("++"); _CurrentInstructions++; }); }
public async Task StopAsync() { await CoordinatedShutdown.Get(_lighthouseSystem).Run(); }
protected void Application_End() { CoordinatedShutdown.Get(ActorSystemProvider.ActorSystem).Run().Wait(TimeSpan.FromSeconds(5)); }
public async Task Stop() { await CoordinatedShutdown.Get(ClusterSystem).Run(CoordinatedShutdown.ClrExitReason.Instance); }
public async Task StopAsync() { await CoordinatedShutdown.Get(SystemActors.ClusterSystem).Run(); }
public Task StopAsync(CancellationToken cancellationToken) { return(CoordinatedShutdown.Get(_actors.Sys).Run(CoordinatedShutdown.ClrExitReason.Instance)); }
private static void LeaveCluster() { Console.WriteLine("Leaving cluster"); CoordinatedShutdown.Get(_clusterSystem).Run().Wait(TimeSpan.FromSeconds(60)); }
/// <summary> /// Debuging Mode Stores the Messages and enables Message Tracking for the Simulation Run. /// </summary> private void DebugMode() { Receive <Command>(s => s == Command.Start, s => { if (!_InstructionStore.Any()) //if (_CurrentInstructions == 0) { _IsRunning = true; _nextInterupt = _nextInterupt + _SimulationConfig.InteruptInterval; _SimulationConfig.Inbox.Receiver.Tell(SimulationState.Started); Advance_Debug(); } else { // Not Ready Yet, Try Again Context.Self.Tell(s); } }); // Determine when The initialisation is Done. Receive <Command>(s => s == Command.IsReady, s => { if (_InstructionStore.Any()) //if (_CurrentInstructions == 0) { Sender.Tell(Command.IsReady, ActorRefs.NoSender); } else { // Not Ready Yet, Try Again Context.Self.Forward(s); } }); // Determine when The Simulation is Done. Receive <SimulationState>(s => s == SimulationState.Finished, s => { if (_InstructionStore.Any()) { _SimulationConfig.Inbox.Receiver.Tell(SimulationState.Finished); _IsComplete = true; } else { // Not Ready Yet, Try Again Context.Self.Forward(s); } }); Receive <Done>(c => { if (!_InstructionStore.Remove(((ISimulationMessage)c.Message).Key)) { throw new Exception("Failed to remove message from Instruction store"); } System.Diagnostics.Debug.WriteLine("-- Done(" + _InstructionStore.Count() + ") ", "AKKA"); Advance_Debug(); }); Receive <Command>(c => c == Command.Stop, c => { // Console.WriteLine("-- Resume simulation -- !"); System.Diagnostics.Debug.WriteLine("STOP", "AKKA"); _IsRunning = false; }); Receive <Shutdown>(c => { if (_InstructionStore.Any() && _FeatureStore.Any()) //if (_CurrentInstructions == 0 && _FeaturedInstructions.Count() == 0) { System.Diagnostics.Debug.WriteLine("Simulation Finished...", "AKKA"); CoordinatedShutdown.Get(Context.System).Run(CoordinatedShutdown.ClrExitReason.Instance); } }); Receive <Schedule>(m => { LogInterceptor(m.Message); var sheduleAt = m.Delay + TimePeriod; if (_FeatureStore.TryGetValue(sheduleAt, out Dictionary <Guid, ISimulationMessage> value)) { value.Add(m.Message.Key, m.Message); } else { _FeatureStore.Add(sheduleAt, new Dictionary <Guid, ISimulationMessage> { { m.Message.Key, m.Message } }); } m.Message.Target.Forward(m); }); Receive <ISimulationMessage>(m => { LogInterceptor(m); if (m.Target != ActorRefs.NoSender) { m.Target.Forward(m); } else if (m.TargetSelection != null) { m.TargetSelection.Tell(m); } else { // ping back Sender.Tell(m); } //_CurrentInstructions++; _InstructionStore.Add(m.Key, m); System.Diagnostics.Debug.WriteLine(" DO ++ (" + _InstructionStore.Count() + ")" + m.GetType().ToString(), "AKKA"); }); }
public Task Stop() { return(CoordinatedShutdown.Get(ClusterSystem).Run(CoordinatedShutdown.ClrExitReason.Instance)); }
private void StopAsync() { CoordinatedShutdown.Get(_system).Run(CoordinatedShutdown.ClrExitReason.Instance).Wait(); }
private static void StopActorSystem() { Task <Done> shutdownTask = CoordinatedShutdown.Get(_actorSystem).Run(CoordinatedShutdown.ClrExitReason.Instance); shutdownTask.Wait(); }
public Task Stop() { GetActor("messagePool").Tell(new Broadcast(PoisonPill.Instance)); return(CoordinatedShutdown.Get(System).Run(CoordinatedShutdown.ClusterDowningReason.Instance)); }