예제 #1
0
        public static void Shutdown(ActorSystem sys)
        {
            CoordinatedShutdown.Get(sys).Run().Wait(TimeSpan.FromSeconds(10));

            Console.WriteLine("Bye");
        }
예제 #2
0
 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);
 }
예제 #3
0
 public Task Stop()
 {
     return(CoordinatedShutdown.Get(System).Run(CoordinatedShutdown.ClusterDowningReason.Instance));
 }
예제 #4
0
 public async Task StopAsync()
 {
     await CoordinatedShutdown.Get(_lighthouseSystem).Run(CoordinatedShutdown.ClrExitReason.Instance);
 }
 public Task Stop()
 {
     return(CoordinatedShutdown.Get(ClusterSystem).Run());
 }
예제 #6
0
 public void Stop()
 {
     ClusterHttpManagement.Get(actorSystem).Stop();
     CoordinatedShutdown.Get(actorSystem).Run(CoordinatedShutdown.ClrExitReason.Instance).Wait();
 }
예제 #7
0
        /// <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 });
            });
        }
예제 #8
0
 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();
예제 #10
0
 /// <summary>
 /// Safely shutdown the actor system
 /// </summary>
 /// <returns></returns>
 public Task Stop()
 => CoordinatedShutdown.Get(ActorSystem)
 .Run(CoordinatedShutdown.ClrExitReason.Instance);
예제 #11
0
 public async Task Shutdown()
 => await CoordinatedShutdown
 .Get(ActorSystem)
 .Run(CoordinatedShutdown.ActorSystemTerminateReason.Instance);
예제 #12
0
 public Task Shutdown()
 {
     return(CoordinatedShutdown.Get(_system).Run());
 }
예제 #13
0
 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);
 }
예제 #15
0
 public async void Stop()
 {
     await CoordinatedShutdown.Get(AppAkkaRefs.Cluster).Run();
 }
예제 #16
0
        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();
        }
예제 #17
0
 /// <summary>
 /// Performs a coordinated shutdown of the system asynchronously.
 /// </summary>
 /// <returns>Shutdown task</returns>
 public async Task StopAsync()
 {
     await CoordinatedShutdown.Get(_actorSystem).Run();
 }
예제 #18
0
 public async Task StopAsync()
 {
     await CoordinatedShutdown.Get(_actorSystem).Run(CoordinatedShutdown.ClusterLeavingReason.Instance);
 }
예제 #19
0
        /// <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++;
            });
        }
예제 #20
0
 public async Task StopAsync()
 {
     await CoordinatedShutdown.Get(_lighthouseSystem).Run();
 }
예제 #21
0
 protected void Application_End()
 {
     CoordinatedShutdown.Get(ActorSystemProvider.ActorSystem).Run().Wait(TimeSpan.FromSeconds(5));
 }
예제 #22
0
 public async Task Stop()
 {
     await CoordinatedShutdown.Get(ClusterSystem).Run(CoordinatedShutdown.ClrExitReason.Instance);
 }
예제 #23
0
 public async Task StopAsync()
 {
     await CoordinatedShutdown.Get(SystemActors.ClusterSystem).Run();
 }
예제 #24
0
 public Task StopAsync(CancellationToken cancellationToken)
 {
     return(CoordinatedShutdown.Get(_actors.Sys).Run(CoordinatedShutdown.ClrExitReason.Instance));
 }
예제 #25
0
 private static void LeaveCluster()
 {
     Console.WriteLine("Leaving cluster");
     CoordinatedShutdown.Get(_clusterSystem).Run().Wait(TimeSpan.FromSeconds(60));
 }
예제 #26
0
        /// <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));
 }
예제 #28
0
 private void StopAsync()
 {
     CoordinatedShutdown.Get(_system).Run(CoordinatedShutdown.ClrExitReason.Instance).Wait();
 }
예제 #29
0
        private static void StopActorSystem()
        {
            Task <Done> shutdownTask = CoordinatedShutdown.Get(_actorSystem).Run(CoordinatedShutdown.ClrExitReason.Instance);

            shutdownTask.Wait();
        }
예제 #30
0
        public Task Stop()
        {
            GetActor("messagePool").Tell(new Broadcast(PoisonPill.Instance));

            return(CoordinatedShutdown.Get(System).Run(CoordinatedShutdown.ClusterDowningReason.Instance));
        }