public async Task LoggingBus_should_stop_all_loggers_on_termination() { var system = ActorSystem.Create("TestSystem", ConfigurationFactory.Default()); system.EventStream.Subscribe(TestActor, typeof(Debug)); await system.Terminate(); var shutdownInitiated = ExpectMsg <Debug>(TestKitSettings.DefaultTimeout); shutdownInitiated.Message.ShouldBe("System shutdown initiated"); var loggerStarted = ExpectMsg <Debug>(TestKitSettings.DefaultTimeout); loggerStarted.Message.ShouldBe("Shutting down: StandardOutLogger started"); loggerStarted.LogClass.ShouldBe(typeof(EventStream)); loggerStarted.LogSource.ShouldBe(typeof(EventStream).Name); var loggerStopped = ExpectMsg <Debug>(TestKitSettings.DefaultTimeout); loggerStopped.Message.ShouldBe("All default loggers stopped"); loggerStopped.LogClass.ShouldBe(typeof(EventStream)); loggerStopped.LogSource.ShouldBe(typeof(EventStream).Name); ExpectNoMsg(TimeSpan.FromSeconds(1)); }
/// <summary> /// Shortcut for creating a new actor system with the specified name and settings. /// </summary> /// <param name="name">The name of the actor system to create. The name must be uri friendly. /// <remarks>Must contain only word characters (i.e. [a-zA-Z0-9] plus non-leading '-'</remarks> /// </param> /// <param name="setup">The bootstrap setup used to help programmatically initialize the <see cref="ActorSystem"/>.</param> /// <returns>A newly created actor system with the given name and configuration.</returns> public static ActorSystem Create(string name, ActorSystemSetup setup) { var bootstrapSetup = setup.Get <BootstrapSetup>(); var appConfig = bootstrapSetup.FlatSelect(_ => _.Config).GetOrElse(ConfigurationFactory.Load()); return(CreateAndStartSystem(name, appConfig, setup)); }
public StatsSampleSpecConfig() { First = Role("first"); Second = Role("second"); Third = Role("third"); // this configuration will be used for all nodes // note that no fixed host names and ports are used CommonConfig = ConfigurationFactory.ParseString(@" # Enable metrics extension in akka-cluster-metrics. akka.extensions=[""Akka.Cluster.Metrics.ClusterMetricsExtensionProvider, Akka.Cluster.Metrics""] akka.actor.provider = cluster akka.remote.classic.log-remote-lifecycle-events = off akka.cluster.roles = [compute] #//#router-lookup-config akka.actor.deployment { /statsService/workerRouter { router = consistent-hashing-group routees.paths = [""/user/statsWorker""] cluster { enabled = on allow-local-routees = on use-roles = [""compute""] } } } #//#router-lookup-config "); }
static ReplicatorSpecs() { SpecConfig = ConfigurationFactory.ParseString(@" akka.loglevel = DEBUG akka.actor.provider = cluster akka.remote.dot-netty.tcp.port = 0") .WithFallback(DistributedData.DefaultConfig()); }
/// <summary> /// Initializes a new instance of the <see cref="ActorSystemImpl"/> class. /// </summary> /// <param name="name">The name given to the actor system.</param> public ActorSystemImpl(string name) : this( name, ConfigurationFactory.Default(), ActorSystemSetup.Empty, Option <Props> .None) { }
private Config Config(string id, Config appConfig) { var simpleName = id.Substring(id.LastIndexOf('.') + 1); return(IdConfig(id) .WithFallback(appConfig) .WithFallback(ConfigurationFactory.ParseString(string.Format("name: {0}", simpleName))) .WithFallback(DefaultDispatcherConfig)); }
public WeightedRouteesSpec() : base(ConfigurationFactory.ParseString(@" akka.actor.provider = ""cluster"" akka.remote.classic.netty.tcp.port = 0 akka.remote.artery.canonical.port = 0 ")) { _routeeA = new ActorSelectionRoutee(Sys.ActorSelection(new RootActorPath(_a1) / "user" / "a")); _routeeB = new ActorSelectionRoutee(Sys.ActorSelection(new RootActorPath(_b1) / "user" / "b")); _routeeC = new ActorSelectionRoutee(Sys.ActorSelection(new RootActorPath(_c1) / "user" / "c")); _routees = ImmutableArray.Create <Routee>(_routeeA, _routeeB, _routeeC); _testActorRoutee = new ActorRefRoutee(TestActor); }
[Fact] public void EventAdapters_should_fail_with_useful_message_when_binding_to_not_defined_adapter() { var badConfig = ConfigurationFactory.ParseString(@" akka.persistence.journal.inmem { event-adapter-bindings { ""System.Integer"" = undefined-adapter } }"); var combinedConfig = badConfig.GetConfig("akka.persistence.journal.inmem"); var ex = Assert.Throws <ArgumentException>(() => EventAdapters.Create(_extendedActorSystem, combinedConfig)); ex.Message.Contains("System.Integer was bound to undefined event-adapter: undefined-adapter").Should().BeTrue(); }
public static Config Config() { var address = TestUtils.TemporaryServerAddress(); return(ConfigurationFactory.ParseString($@" akka {{ loglevel = INFO actor {{ provider = remote serialize-messages = off }} remote.dot-netty.tcp {{ port = {address.Port} hostname = ""{address.Address}"" }} }}") .WithFallback(ConfigurationFactory.Default())); }
public AdaptiveLoadBalancingRouterConfig() { Node1 = Role("node-1"); Node2 = Role("node-2"); Node3 = Role("node-3"); CommonConfig = DebugConfig(on: false) .WithFallback(ConfigurationFactory.ParseString(@" # Enable metrics extension in akka-cluster-metrics. akka.extensions=[""Akka.Cluster.Metrics.ClusterMetricsExtensionProvider, Akka.Cluster.Metrics""] akka.cluster.failure-detector.acceptable-heartbeat-pause = 10s # Use rapid metrics collection. akka.cluster.metrics { collector { sample-interval = 1s gossip-interval = 1s moving-average-half-life = 2s } } # Use metrics extension routing. akka.actor.deployment { /router3 = { router = cluster-metrics-adaptive-pool metrics-selector = cpu nr-of-instances = 9 } /router4 = { router = cluster-metrics-adaptive-pool metrics-selector = ""Akka.Cluster.Metrics.Tests.MultiNode.TestCustomMetricsSelector, Akka.Cluster.Metrics.Tests.MultiNode"" nr-of-instances = 10 cluster { enabled = on max-nr-of-instances-per-node = 2 } } } ")) .WithFallback(ClusterMetrics.DefaultConfig()) .WithFallback(MultiNodeClusterSpec.ClusterConfig()); }
public static ActorSystem CreateActorSystem() { var address = TestUtils.TemporaryServerAddress(); var config = ConfigurationFactory.ParseString($@" akka {{ loglevel = INFO actor {{ provider = remote serialize-messages = off }} remote.dot-netty.tcp {{ port = {address.Port} hostname = ""{address.Address}"" }} }}") .WithFallback(ConfigurationFactory.Default()); var system = ActorSystem.Create("remote-system-2", config); return(system); }
public void Should_be_able_to_parse_settings() { var config = Sys.Settings.Config.WithFallback( ConfigurationFactory.FromResource <ClusterMetricsSettings>("Akka.Cluster.Metrics.reference.conf")); var settings = new ClusterMetricsSettings(config); // Extension. settings.MetricsDispatcher.ShouldBe(Dispatchers.DefaultDispatcherId); settings.PeriodicTasksInitialDelay.Should().Be(1.Seconds()); // Supervisor. settings.SupervisorName.Should().Be("cluster-metrics"); settings.SupervisorStrategyProvider.Should().BeEquivalentTo(typeof(ClusterMetricsStrategy).TypeQualifiedName()); settings.SupervisorStrategyConfiguration.ToString().ShouldBeEquivalentTo( ConfigurationFactory.ParseString("loggingEnabled=true,withinTimeRange=3s,maxNrOfRetries=3").ToString()); // Collector. settings.CollectorEnabled.Should().BeTrue(); settings.CollectorProvider.Should().BeEmpty(); settings.CollectorSampleInterval.Should().Be(3.Seconds()); settings.CollectorGossipInterval.Should().Be(3.Seconds()); settings.CollectorMovingAverageHalfLife.Should().Be(12.Seconds()); }
public MemoryEventAdaptersSpec() { var config = ConfigurationFactory.ParseString(@" akka.persistence.journal { plugin = ""akka.persistence.journal.inmem"" # adapters defined for all plugins common-event-adapter-bindings { } inmem { # showcases re-using and concating configuration of adapters event-adapters { example = """ + typeof(ExampleEventAdapter).FullName + @", Akka.Persistence.Tests"" marker = """ + typeof(MarkerInterfaceAdapter).FullName + @", Akka.Persistence.Tests"" precise = """ + typeof(PreciseAdapter).FullName + @", Akka.Persistence.Tests"" reader = """ + typeof(ReaderAdapter).FullName + @", Akka.Persistence.Tests"" writer = """ + typeof(WriterAdapter).FullName + @", Akka.Persistence.Tests"" another-reader = """ + typeof(AnotherReaderAdapter).FullName + @", Akka.Persistence.Tests"" } event-adapter-bindings = { """ + typeof(IEventMarkerInterface).FullName + @", Akka.Persistence.Tests"" = marker ""System.String"" = example """ + typeof(PreciseAdapterEvent).FullName + @", Akka.Persistence.Tests"" = precise """ + typeof(ReadMeEvent).FullName + @", Akka.Persistence.Tests"" = reader """ + typeof(WriteMeEvent).FullName + @", Akka.Persistence.Tests"" = writer """ + typeof(ReadMeTwiceEvent).FullName + @", Akka.Persistence.Tests"" = [reader, another-reader] """ + typeof(ReadWriteEvent).FullName + @", Akka.Persistence.Tests"" = [reader, another-reader, writer] } } }").WithFallback(ConfigurationFactory.Default()); _extendedActorSystem = (ExtendedActorSystem)Sys; _memoryConfig = config.GetConfig("akka.persistence.journal.inmem"); }
/// <summary> /// Initializes a new instance of the <see cref="ActorSystemImpl"/> class. /// </summary> /// <param name="name">The name given to the actor system.</param> public ActorSystemImpl(string name) : this(name, ConfigurationFactory.Default()) { }
public ConfigurationSpec(ITestOutputHelper output) : base(ConfigurationFactory.Default(), output) { }
/// <summary> /// Initializes a new instance of the <see cref="Settings" /> class. /// </summary> /// <param name="system">The system.</param> /// <param name="config">The configuration.</param> /// <exception cref="ConfigurationException"> /// This exception is thrown if the 'akka.actor.provider' configuration item is not a valid type name or a valid actor ref provider. /// </exception> public Settings(ActorSystem system, Config config) { _userConfig = config; _fallbackConfig = ConfigurationFactory.Default(); RebuildConfig(); System = system; ConfigVersion = Config.GetString("akka.version", null); ProviderClass = GetProviderClass(Config.GetString("akka.actor.provider", null)); var providerType = Type.GetType(ProviderClass); if (providerType == null) { throw new ConfigurationException($"'akka.actor.provider' is not a valid type name : '{ProviderClass}'"); } if (!typeof(IActorRefProvider).IsAssignableFrom(providerType)) { throw new ConfigurationException($"'akka.actor.provider' is not a valid actor ref provider: '{ProviderClass}'"); } SupervisorStrategyClass = Config.GetString("akka.actor.guardian-supervisor-strategy", null); AskTimeout = Config.GetTimeSpan("akka.actor.ask-timeout", null, allowInfinite: true); CreationTimeout = Config.GetTimeSpan("akka.actor.creation-timeout", null); UnstartedPushTimeout = Config.GetTimeSpan("akka.actor.unstarted-push-timeout", null); SerializeAllMessages = Config.GetBoolean("akka.actor.serialize-messages", false); SerializeAllCreators = Config.GetBoolean("akka.actor.serialize-creators", false); LogLevel = Config.GetString("akka.loglevel", null); StdoutLogLevel = Config.GetString("akka.stdout-loglevel", null); Loggers = Config.GetStringList("akka.loggers", new string[] { }); LoggersDispatcher = Config.GetString("akka.loggers-dispatcher", null); LoggerStartTimeout = Config.GetTimeSpan("akka.logger-startup-timeout", null); //handled LogConfigOnStart = Config.GetBoolean("akka.log-config-on-start", false); LogDeadLetters = 0; switch (Config.GetString("akka.log-dead-letters", null)) { case "on": case "true": case "yes": LogDeadLetters = int.MaxValue; break; case "off": case "false": case "no": LogDeadLetters = 0; break; default: LogDeadLetters = Config.GetInt("akka.log-dead-letters", 0); break; } LogDeadLettersDuringShutdown = Config.GetBoolean("akka.log-dead-letters-during-shutdown", false); AddLoggingReceive = Config.GetBoolean("akka.actor.debug.receive", false); DebugAutoReceive = Config.GetBoolean("akka.actor.debug.autoreceive", false); DebugLifecycle = Config.GetBoolean("akka.actor.debug.lifecycle", false); FsmDebugEvent = Config.GetBoolean("akka.actor.debug.fsm", false); DebugEventStream = Config.GetBoolean("akka.actor.debug.event-stream", false); DebugUnhandledMessage = Config.GetBoolean("akka.actor.debug.unhandled", false); DebugRouterMisconfiguration = Config.GetBoolean("akka.actor.debug.router-misconfiguration", false); Home = Config.GetString("akka.home", ""); DefaultVirtualNodesFactor = Config.GetInt("akka.actor.deployment.default.virtual-nodes-factor", 0); SchedulerClass = Config.GetString("akka.scheduler.implementation", null); SchedulerShutdownTimeout = Config.GetTimeSpan("akka.scheduler.shutdown-timeout", null); CoordinatedShutdownTerminateActorSystem = Config.GetBoolean("akka.coordinated-shutdown.terminate-actor-system"); CoordinatedShutdownRunByActorSystemTerminate = Config.GetBoolean("akka.coordinated-shutdown.run-by-actor-system-terminate"); if (CoordinatedShutdownRunByActorSystemTerminate && !CoordinatedShutdownTerminateActorSystem) { throw new ConfigurationException( "akka.coordinated-shutdown.run-by-actor-system-terminate=on and " + "akka.coordinated-shutdown.terminate-actor-system=off is not a supported configuration combination."); } //TODO: dunno.. we don't have FiniteStateMachines, don't know what the rest is /* * final val SchedulerClass: String = getString("akka.scheduler.implementation") * final val Daemonicity: Boolean = getBoolean("akka.daemonic") * final val DefaultVirtualNodesFactor: Int = getInt("akka.actor.deployment.default.virtual-nodes-factor") */ }
/// <summary> /// Adds the supplied configuration as a fallback to the supplied configuration string. /// </summary> /// <param name="configHocon">The configuration string used as the source.</param> /// <param name="fallbackConfig">The configuration used as the fallback.</param> /// <returns>A configuration configured with the supplied fallback.</returns> public static Config operator +(string configHocon, Config fallbackConfig) { Config config = ConfigurationFactory.ParseString(configHocon); return(config.WithFallback(fallbackConfig)); }
/// <summary> /// Initializes a new instance of the <see cref="ActorSystemImpl"/> class. /// </summary> /// <param name="name">The name given to the actor system.</param> public ActorSystemImpl(string name) : this(name, ConfigurationFactory.Default(), ActorSystemSetup.Empty) { }
static void Main(string[] args) { using (var system = ActorSystem.Create("persistent-benchmark", config.WithFallback(ConfigurationFactory.Default()))) { Console.WriteLine("Performance benchmark starting..."); var actors = new IActorRef[ActorCount]; for (int i = 0; i < ActorCount; i++) { var pid = "a-" + i; actors[i] = system.ActorOf(Props.Create(() => new PerformanceTestActor(pid))); } Task.WaitAll(actors.Select(a => a.Ask <Done>(Init.Instance)).Cast <Task>().ToArray()); Console.WriteLine("All actors have been initialized..."); var stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < MessagesPerActor; i++) { for (int j = 0; j < ActorCount; j++) { actors[j].Tell(new Store(1)); } } var finished = new Task[ActorCount]; for (int i = 0; i < ActorCount; i++) { finished[i] = actors[i].Ask <Finished>(Finish.Instance); } Task.WaitAll(finished); var elapsed = stopwatch.ElapsedMilliseconds; Console.WriteLine($"{ActorCount} actors stored {MessagesPerActor} events each in {elapsed/1000.0} sec. Average: {ActorCount*MessagesPerActor*1000.0/elapsed} events/sec"); foreach (Task <Finished> task in finished) { if (!task.IsCompleted || task.Result.State != MessagesPerActor) { throw new IllegalStateException("Actor's state was invalid"); } } } Console.ReadLine(); }
/// <summary> /// Creates a new <see cref="ActorSystem"/> with the specified name. /// </summary> /// <param name="name">The name of the actor system to create. The name must be uri friendly. /// <remarks>Must contain only word characters (i.e. [a-zA-Z0-9] plus non-leading '-'</remarks> /// </param> /// <returns>A newly created actor system with the given name.</returns> public static ActorSystem Create(string name) { return(CreateAndStartSystem(name, ConfigurationFactory.Load())); }
/// <summary> /// Adds the supplied configuration string as a fallback to the supplied configuration. /// </summary> /// <param name="config">The configuration used as the source.</param> /// <param name="fallback">The string used as the fallback configuration.</param> /// <returns>The supplied configuration configured with the supplied fallback.</returns> public static Config operator +(Config config, string fallback) { Config fallbackConfig = ConfigurationFactory.ParseString(fallback); return(config.WithFallback(fallbackConfig)); }
/// <summary> /// Initializes a new instance of the <see cref="Settings" /> class. /// </summary> /// <param name="system">The system.</param> /// <param name="config">The configuration.</param> /// <param name="setup">The setup class used to help bootstrap the <see cref="ActorSystem"/></param> /// <exception cref="ConfigurationException"> /// This exception is thrown if the 'akka.actor.provider' configuration item is not a valid type name or a valid actor ref provider. /// </exception> public Settings(ActorSystem system, Config config, ActorSystemSetup setup) { Setup = setup; _userConfig = config; _fallbackConfig = ConfigurationFactory.Default(); RebuildConfig(); System = system; var providerSelectionSetup = Setup.Get <BootstrapSetup>() .FlatSelect(_ => _.ActorRefProvider) .Select(_ => _.Fqn) .GetOrElse(Config.GetString("akka.actor.provider", null)); ProviderSelectionType = ProviderSelection.GetProvider(providerSelectionSetup); ConfigVersion = Config.GetString("akka.version", null); ProviderClass = ProviderSelectionType.Fqn; HasCluster = ProviderSelectionType.HasCluster; var providerType = Type.GetType(ProviderClass); if (providerType == null) { throw new ConfigurationException($"'akka.actor.provider' is not a valid type name : '{ProviderClass}'"); } if (!typeof(IActorRefProvider).IsAssignableFrom(providerType)) { throw new ConfigurationException($"'akka.actor.provider' is not a valid actor ref provider: '{ProviderClass}'"); } SupervisorStrategyClass = Config.GetString("akka.actor.guardian-supervisor-strategy", null); AskTimeout = Config.GetTimeSpan("akka.actor.ask-timeout", null, allowInfinite: true); CreationTimeout = Config.GetTimeSpan("akka.actor.creation-timeout", null); UnstartedPushTimeout = Config.GetTimeSpan("akka.actor.unstarted-push-timeout", null); SerializeAllMessages = Config.GetBoolean("akka.actor.serialize-messages", false); SerializeAllCreators = Config.GetBoolean("akka.actor.serialize-creators", false); LogLevel = Config.GetString("akka.loglevel", null); StdoutLogLevel = Config.GetString("akka.stdout-loglevel", null); Loggers = Config.GetStringList("akka.loggers", new string[] { }); LoggersDispatcher = Config.GetString("akka.loggers-dispatcher", null); LoggerStartTimeout = Config.GetTimeSpan("akka.logger-startup-timeout", null); LoggerAsyncStart = Config.GetBoolean("akka.logger-async-start", false); //handled LogConfigOnStart = Config.GetBoolean("akka.log-config-on-start", false); LogDeadLetters = 0; switch (Config.GetString("akka.log-dead-letters", null)) { case "on": case "true": case "yes": LogDeadLetters = int.MaxValue; break; case "off": case "false": case "no": LogDeadLetters = 0; break; default: LogDeadLetters = Config.GetInt("akka.log-dead-letters", 0); break; } LogDeadLettersDuringShutdown = Config.GetBoolean("akka.log-dead-letters-during-shutdown", false); const string key = "akka.log-dead-letters-suspend-duration"; LogDeadLettersSuspendDuration = Config.GetString(key, null) == "infinite" ? Timeout.InfiniteTimeSpan : Config.GetTimeSpan(key); AddLoggingReceive = Config.GetBoolean("akka.actor.debug.receive", false); DebugAutoReceive = Config.GetBoolean("akka.actor.debug.autoreceive", false); DebugLifecycle = Config.GetBoolean("akka.actor.debug.lifecycle", false); FsmDebugEvent = Config.GetBoolean("akka.actor.debug.fsm", false); DebugEventStream = Config.GetBoolean("akka.actor.debug.event-stream", false); DebugUnhandledMessage = Config.GetBoolean("akka.actor.debug.unhandled", false); DebugRouterMisconfiguration = Config.GetBoolean("akka.actor.debug.router-misconfiguration", false); Home = Config.GetString("akka.home", ""); DefaultVirtualNodesFactor = Config.GetInt("akka.actor.deployment.default.virtual-nodes-factor", 0); SchedulerClass = Config.GetString("akka.scheduler.implementation", null); SchedulerShutdownTimeout = Config.GetTimeSpan("akka.scheduler.shutdown-timeout", null); CoordinatedShutdownTerminateActorSystem = Config.GetBoolean("akka.coordinated-shutdown.terminate-actor-system"); CoordinatedShutdownRunByActorSystemTerminate = Config.GetBoolean("akka.coordinated-shutdown.run-by-actor-system-terminate"); if (CoordinatedShutdownRunByActorSystemTerminate && !CoordinatedShutdownTerminateActorSystem) { throw new ConfigurationException( "akka.coordinated-shutdown.run-by-actor-system-terminate=on and " + "akka.coordinated-shutdown.terminate-actor-system=off is not a supported configuration combination."); } }
/// <summary> /// Default HOCON settings for cluster metrics. /// </summary> /// <returns>TBD</returns> public static Config DefaultConfig() { return(ConfigurationFactory.FromResource <ClusterMetrics>("Akka.Cluster.Metrics.reference.conf")); }
private Config IdConfig(string id) { return(ConfigurationFactory.ParseString(string.Format("id: {0}", id))); }
private static Config IdConfig(string id) { return(ConfigurationFactory.ParseString($"id: {id}")); }