protected PluginSpec(ActorSystemSetup setup, string actorSystemName = null, ITestOutputHelper output = null) : base(setup, actorSystemName, output) { Extension = Persistence.Instance.Apply(Sys as ExtendedActorSystem); Pid = "p-" + Counter.IncrementAndGet(); WriterGuid = Guid.NewGuid().ToString(); }
public void InstantiateAndStart(ActorSystemSetup actorSystemSetup, IExposedPropertyTable resolver = null, UnityProject unityProject = null, UnityUser unityUser = null) { Hook.InstantiateAndStart(actorSystemSetup, resolver, unityProject, unityUser); }
public void SerializationSettingsShouldOverrideHoconSettings() { var serializationSettings = new SerializationSetup(_ => ImmutableHashSet <SerializerDetails> .Empty .Add(SerializerDetails.Create( "test", new TestSerializer(_), ImmutableHashSet <Type> .Empty.Add(typeof(ProgammaticDummy))))); var bootstrap = BootstrapSetup.Create().WithConfig(ConfigurationFactory.ParseString(@" akka{ actor{ serialize-messages = on serializers { test = ""Akka.Tests.Serialization.OverridenSerializer, Akka.Test"" } serialization-bindings { ""Akka.Tests.Serialization.ProgammaticDummy, Akka.Tests"" = test } } }").WithFallback(TestConfigs.DefaultConfig)); var actorSystemSettings = ActorSystemSetup.Create(serializationSettings, bootstrap); var sys2 = ActorSystem.Create("override-test", actorSystemSettings); var serializer = sys2.Serialization.FindSerializerFor(new ProgammaticDummy()); serializer.Should().BeOfType <TestSerializer>(); sys2.Terminate().Wait(); }
private MultiNodeSpec( RoleName myself, ActorSystem system, ActorSystemSetup setup, ImmutableList <RoleName> roles, Func <RoleName, ImmutableList <string> > deployments) : base(new XunitAssertions(), system, setup, null, null) { _myself = myself; _log = Logging.GetLogger(Sys, this); _roles = roles; _deployments = deployments; var node = new IPEndPoint(Dns.GetHostAddresses(ServerName)[0], ServerPort); _controllerAddr = node; AttachConductor(new TestConductor(Sys)); _replacements = _roles.ToImmutableDictionary(r => r, r => new Replacement("@" + r.Name + "@", r, this)); InjectDeployments(Sys, myself); _myAddress = Sys.AsInstanceOf <ExtendedActorSystem>().Provider.DefaultAddress; Log.Info("Role [{0}] started with address [{1}]", myself.Name, _myAddress); MultiNodeSpecBeforeAll(); }
/// <summary> /// Initializes a new instance of the <see cref="ActorSystemImpl"/> class. /// </summary> /// <param name="name">The name given to the actor system.</param> /// <param name="config">The configuration used to configure the actor system.</param> /// <param name="setup">The <see cref="ActorSystemSetup"/> used to help programmatically bootstrap the actor system.</param> /// <exception cref="ArgumentException"> /// This exception is thrown if the given <paramref name="name"/> is an invalid name for an actor system. /// Note that the name must contain only word characters (i.e. [a-zA-Z0-9] plus non-leading '-'). /// </exception> /// <exception cref="ArgumentNullException">This exception is thrown if the given <paramref name="config"/> is undefined.</exception> public ActorSystemImpl( string name, Config config, ActorSystemSetup setup, Option <Props>?guardianProps = null) { if (!Regex.Match(name, "^[a-zA-Z0-9][a-zA-Z0-9-]*$").Success) { throw new ArgumentException( $"Invalid ActorSystem name [{name}], must contain only word characters (i.e. [a-zA-Z0-9] plus non-leading '-')", nameof(name)); } // Not checking for empty Config here, default values will be substituted in Settings class constructor (called in ConfigureSettings) if (config is null) { throw new ArgumentNullException(nameof(config), $"Cannot create {typeof(ActorSystemImpl)}: Configuration must not be null."); } _name = name; GuardianProps = guardianProps ?? Option <Props> .None; ConfigureSettings(config, setup); ConfigureEventStream(); ConfigureLoggers(); ConfigureScheduler(); ConfigureProvider(); ConfigureTerminationCallbacks(); ConfigureSerialization(); ConfigureMailboxes(); ConfigureDispatchers(); ConfigureActorProducerPipeline(); }
public void Custom_programmatic_SerializerWithStringManifest_should_work_with_base_class_binding() { var settings = SerializationSetup.Create(system => ImmutableHashSet <SerializerDetails> .Empty.Add( new SerializerDetails( alias: "custom", serializer: new CustomManifestSerializer(system), useFor: ImmutableHashSet <Type> .Empty.Add(typeof(MessageBase)))) ); var setup = ActorSystemSetup.Create(settings); using (var system = ActorSystem.Create(nameof(CustomSerializerSpec), setup)) { var firstMessage = new FirstMessage("First message"); var serialization = system.Serialization; var serializer = (CustomManifestSerializer)serialization.FindSerializerFor(firstMessage); var serialized = serializer.ToBinary(firstMessage); var manifest = serializer.Manifest(firstMessage); var deserializedFirstMessage = serializer.FromBinary(serialized, manifest); manifest.Should().Be(FirstMessage.Manifest); deserializedFirstMessage.Should().Be(firstMessage); var secondMessage = new SecondMessage("Second message"); serialized = serializer.ToBinary(secondMessage); manifest = serializer.Manifest(secondMessage); var deserializedSecondMessage = serializer.FromBinary(serialized, manifest); manifest.Should().Be(SecondMessage.Manifest); deserializedSecondMessage.Should().Be(secondMessage); } }
/// <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)); }
static ActorGraphViewWindow GetWindow(ActorSystemSetup asset) { var openedWindows = Resources.FindObjectsOfTypeAll <ActorGraphViewWindow>().ToList(); var window = openedWindows.FirstOrDefault(x => x.m_Asset == asset); if (window == null) { window = openedWindows.FirstOrDefault(x => x.m_Asset == null); } if (window == null) { window = CreateWindow <ActorGraphViewWindow>("Actor: empty", typeof(SceneView)); } window.Focus(); window.AssignAsset(asset); if (asset != null) { window.titleContent = new GUIContent($"Actor: {asset.name}"); } return(window); }
protected MultiNodeSpec( RoleName myself, ActorSystemSetup setup, ImmutableList <RoleName> roles, Func <RoleName, ImmutableList <string> > deployments) : this(myself, null, setup, roles, deployments) { }
public void ActorSystemSettingsShouldStoreAndRetrieveSetup() { var setup = new DummySetup("Ardbeg"); var setups = ActorSystemSetup.Create(setup); setups.Get <DummySetup>().Should().Be(new Option <DummySetup>(setup)); setups.Get <DummySetup2>().Should().Be(Option <DummySetup2> .None); }
void AssignAsset(ActorSystemSetup asset) { m_Asset = asset; if (m_GraphView != null) { m_GraphView.Asset = asset; } }
static void Main(string[] args) { // setup declaring our custom serializer to override the default typeof(object) newtonsoft registration var serializationSetup = SerializationSetup.Create(system => ImmutableHashSet <SerializerDetails> .Empty.Add( SerializerDetails.Create("json-custom", new CustomSerializer(system), ImmutableHashSet <Type> .Empty // this should make all my messages use CustomSerializer .Add(typeof(object)) // this is provided to show CustomSerializer gets called, // i.e, everything appears to be configured correctly .Add(typeof(World)) ) ) ); // we just want to force serialization so we don't need to set up remote // the goal of the programmatic setup is so apps don't need to register the serializer var hocon = ConfigurationFactory.ParseString(@" akka { ""loglevel"": ""DEBUG"", ""stdout-loglevel"": ""DEBUG"", actor { ""serialize-messages"": ""on"", ""debug"": { ""receive"": ""on"", ""lifecycle"": ""on"", ""unhandled"": ""on"", ""event-stream"": ""on"" } } } "); // I'm not sure why 'serialize-messages' isn't triggering my serializer, not even for // my 'World' type. Inspecting system.Serialization._serializerMap reveals the following: // [object] = NewtonsoftJsonSerializer // [World] = CustomSerializer // [byte[]] = ByteArraySerializer // * I thought it might have been dependent on the ordering of ActorSystemSetup.Create(params Setup[] setups) // but I observe the same behavior regardless of the setup ordering. var bootstrapSetup = BootstrapSetup.Create().WithConfig(hocon); var systemSetup = ActorSystemSetup.Create(serializationSetup, bootstrapSetup); var system = ActorSystem.Create("system", systemSetup); // uncommenting this line and the custom serializer is invoked // really bizarre since there is a mapping for typeof(World) but w/out this next line it's not invoked on that type either. //system.Serialization.AddSerializationMap(typeof(object), new CustomSerializer(system.Serialization.System)); var actor = system.ActorOf(Props.Create(() => new Actor()), "actor"); var response = actor.Ask <World>(new Hello("world!")).GetAwaiter().GetResult(); system.Log.Info($"Response: {response.Message}"); Thread.Sleep(TimeSpan.FromSeconds(20)); system.Dispose(); }
protected MultiNodeClusterSpec( RoleName myself, ActorSystemSetup setup, ImmutableList <RoleName> roles, Func <RoleName, ImmutableList <string> > deployments) : base(myself, setup, roles, deployments) { _assertions = new XunitAssertions(); _roleNameComparer = new RoleNameComparer(this); }
public void ActorSystemSettingsShouldBeCreatedWithSetOfSetups() { var setup1 = new DummySetup("Ardbeg"); var setup2 = new DummySetup2("Ledaig"); var setups = ActorSystemSetup.Create(setup1, setup2); setups.Get <DummySetup>().HasValue.Should().BeTrue(); setups.Get <DummySetup2>().HasValue.Should().BeTrue(); setups.Get <DummySetup3>().HasValue.Should().BeFalse(); }
public static void InstantiateAndStart(this ReflectBootstrapper reflectBootstrapper, ActorSystemSetup actorSystemSetup, IExposedPropertyTable resolver = null, UnityProject unityProject = null, UnityUser unityUser = null) { var actorRunnerProxy = reflectBootstrapper.systems.ActorRunner; actorRunnerProxy.Instantiate(actorSystemSetup, unityProject, resolver, unityUser); actorRunnerProxy.StartActorSystem(); }
/// <summary> /// Create a new instance of the <see cref="PersistenceTestKit"/> class. /// A new system with the specified configuration will be created. /// </summary> /// <param name="setup">Test ActorSystem configuration</param> /// <param name="actorSystemName">Optional: The name of the actor system</param> /// <param name="output">TBD</param> protected PersistenceTestKit(ActorSystemSetup setup, string actorSystemName = null, ITestOutputHelper output = null) : base(GetConfig(setup), actorSystemName, output) { var persistenceExtension = Persistence.Instance.Apply(Sys); JournalActorRef = persistenceExtension.JournalFor(null); Journal = TestJournal.FromRef(JournalActorRef); SnapshotsActorRef = persistenceExtension.SnapshotStoreFor(null); Snapshots = TestSnapshotStore.FromRef(SnapshotsActorRef); }
protected TestKitBase(ITestKitAssertions assertions, ActorSystem system, ActorSystemSetup config, string actorSystemName, string testActorName) { if (assertions == null) { throw new ArgumentNullException(nameof(assertions), "The supplied assertions must not be null."); } _assertions = assertions; InitializeTest(system, config, actorSystemName, testActorName); }
private static void Main(string[] args) { var Bootstrap = BootstrapSetup.Create().WithConfig(ConfigurationFactory.ParseString(@" akka { actor { serialize-messages = off } }")); var ActorSystemSettings = ActorSystemSetup.Create(SerializationSettings, Bootstrap); }
void Run(ActorSystemSetup asset) { // Create the scene component var reflectBootstrapper = gameObject.AddComponent <RuntimeReflectBootstrapper>(); reflectBootstrapper.EnableExperimentalActorSystem = true; reflectBootstrapper.Asset = asset; // Start the system reflectBootstrapper.InstantiateAndStart(asset); var runtimeBridgeActor = reflectBootstrapper.FindActor <SampleBridgeActor>(); runtimeBridgeActor.SendUpdateManifests(); }
public void ActorSystemSettingsShouldBeAvailableFromExtendedActorSystem() { ActorSystem system = null; try { var setup = new DummySetup("Eagle Rare"); system = ActorSystem.Create("name", ActorSystemSetup.Create(setup)); system.Settings.Setup.Get <DummySetup>().Should().Be(new Option <DummySetup>(setup)); } finally { system?.Terminate().Wait(TimeSpan.FromSeconds(5)); } }
public static ActorSetup CreateActorSetup <T>(this ActorSystemSetup actorSystemSetup) { var actorConfig = actorSystemSetup.GetActorConfig <T>(); var actorSetup = actorConfig.CreateActorSetup(); actorSystemSetup.ActorSetups.Add(actorSetup); foreach (var inputConfig in actorConfig.InputConfigs) { var isValid = MultiplicityValidator.IsValid(actorSystemSetup.ComponentConfigs.First(x => x.Id == inputConfig.ComponentConfigId).InputMultiplicity, 0); actorSetup.Inputs.Add(new ActorPort(Guid.NewGuid().ToString(), inputConfig.Id, new List <ActorLink>(), isValid, false)); } foreach (var outputConfig in actorConfig.OutputConfigs) { var isValid = MultiplicityValidator.IsValid(actorSystemSetup.ComponentConfigs.First(x => x.Id == outputConfig.ComponentConfigId).OutputMultiplicity, 0); actorSetup.Outputs.Add(new ActorPort(Guid.NewGuid().ToString(), outputConfig.Id, new List <ActorLink>(), isValid, false)); } return(actorSetup); }
public ProgrammaticJsonSerializerSetup() { #region CustomJsonSetup var jsonSerializerSetup = NewtonSoftJsonSerializerSetup.Create( settings => { settings.NullValueHandling = NullValueHandling.Include; settings.PreserveReferencesHandling = PreserveReferencesHandling.None; settings.Formatting = Formatting.None; }); var systemSetup = ActorSystemSetup.Create(jsonSerializerSetup); var system = ActorSystem.Create("MySystem", systemSetup); #endregion system.Terminate().Wait(); }
public async Task StartAsync() { var setup = ActorSystemSetup.Create( BootstrapSetup.Create() .WithConfig(Util.Config(_port)) .WithConfigFallback(DistributedPubSub.DefaultConfig()) .WithConfigFallback(ClusterClientReceptionist.DefaultConfig()) .WithActorRefProvider(ProviderSelection.Cluster.Instance)); _actorSystem = ActorSystem.Create(Consts.NodeName, setup); var cluster = Akka.Cluster.Cluster.Get(_actorSystem); await cluster.JoinSeedNodesAsync(Consts.Seeds); _receptionist = ClusterClientReceptionist.Get(_actorSystem); foreach (var id in Enumerable.Range(_nodeId * Consts.ActorCount, Consts.ActorCount)) { var actor = _actorSystem.ActorOf(Props.Create(() => new ServiceActor(id)), Util.ActorName(id)); _receptionist.RegisterService(actor); } }
static void Main(string[] args) { var logger = new LoggerConfiguration() .WriteTo.File("log.txt", buffered: true, flushToDiskInterval: TimeSpan.FromSeconds(2)) .MinimumLevel.Information() .CreateLogger(); //TestDatabase(); Serilog.Log.Logger = logger; var port = args.Length == 1 ? args[0] : "0"; var config = hocon .Replace("{{connection_string}}", Environment.GetEnvironmentVariable("CONNECTION_STRING")) .Replace("{{port}}", port) .Replace("{{hostname}}", "172.20.176.1"); var ConfigBootstrap = BootstrapSetup.Create().WithConfig(config); var ActorSystemSettings = ActorSystemSetup.Create(ConfigBootstrap); LotteryActorSystem = ActorSystem.Create(Constants.ActorSystemName, ActorSystemSettings); LotteryActorSystem.ActorOf(Props.Create(typeof(SimpleClusterListener)), "clusterListener"); Props lotterySupervisorProps = Props.Create <LotterySupervisor>(); IActorRef lotterySupervisor = LotteryActorSystem.ActorOf(lotterySupervisorProps, "LotterySupervisor"); lotterySupervisor.Tell(new BeginPeriodMessage() { MinTickets = 5, MaxTickets = 10, NumberOfUsers = 20, NumberOfVendors = 150 }); Console.WriteLine("Ticket sales have begun, press enter to end period"); Console.ReadLine(); lotterySupervisor.Tell(new SupervisorSalesClosedMessage() { }); Console.ReadLine(); LotteryActorSystem.Terminate(); ////Akka.Logger.Serilog.SerilogLogger }
public static void Connect <TComponent, TMessage>(this ActorSystemSetup actorSystemSetup, ActorSetup outputActorSetup, ActorSetup inputActorSetup) { var componentConfig = actorSystemSetup.GetComponentConfig <TComponent>(); var messageTypeName = typeof(TMessage).ToString(); var outputActorConfig = actorSystemSetup.GetActorConfig(outputActorSetup); var inputActorConfig = actorSystemSetup.GetActorConfig(inputActorSetup); var outputPortConfig = outputActorConfig.OutputConfigs.First(x => x.ComponentConfigId == componentConfig.Id && x.MessageTypeNormalizedFullName == messageTypeName); var inputPortConfig = inputActorConfig.InputConfigs.First(x => x.ComponentConfigId == componentConfig.Id && x.MessageTypeNormalizedFullName == messageTypeName); var outputPort = outputActorSetup.Outputs.First(x => x.ConfigId == outputPortConfig.Id); var inputPort = inputActorSetup.Inputs.First(x => x.ConfigId == inputPortConfig.Id); var link = new ActorLink(outputPort.Id, inputPort.Id, false); outputPort.Links.Add(link); inputPort.Links.Add(link); }
/// <summary> /// Loads from embedded resources actor system persistence configuration with <see cref="TestJournal"/> and /// <see cref="TestSnapshotStore"/> configured as default persistence plugins. /// </summary> /// <param name="customConfig">Custom configuration that was passed in the constructor.</param> /// <returns>Actor system configuration object.</returns> /// <seealso cref="Config"/> private static ActorSystemSetup GetConfig(ActorSystemSetup customConfig) { var bootstrapSetup = customConfig.Get <BootstrapSetup>(); var config = bootstrapSetup.FlatSelect(x => x.Config); var actorProvider = bootstrapSetup.FlatSelect(x => x.ActorRefProvider); var newSetup = BootstrapSetup.Create(); if (config.HasValue) { newSetup = newSetup.WithConfig(GetConfig(config.Value)); } else { newSetup = newSetup.WithConfig(GetConfig(Config.Empty)); } if (actorProvider.HasValue) { newSetup = newSetup.WithActorRefProvider(actorProvider.Value); } return(customConfig.WithSetup(newSetup)); }
static async Task Main(string[] args) { var cts = new CancellationTokenSource(); #region Console shutdown setup Console.CancelKeyPress += (sender, eventArgs) => { eventArgs.Cancel = true; cts.Cancel(); }; AppDomain.CurrentDomain.ProcessExit += (sender, eventArgs) => { cts.Cancel(); }; #endregion var setup = ActorSystemSetup.Create( BootstrapSetup.Create() .WithConfig(Util.Config(Consts.PortStart - 1)) .WithActorRefProvider(ProviderSelection.Remote.Instance)); var system = ActorSystem.Create("ClusterClientSystem", setup); var clientActor = system.ActorOf(Props.Create(() => new ClientActor())); try { await Task.Delay(Timeout.Infinite, cts.Token); } catch (TaskCanceledException _) { // expected } await system.Terminate(); }
private static ActorSystem CreateAndStartSystem(string name, Config withFallback, ActorSystemSetup setup) { var system = new ActorSystemImpl(name, withFallback, setup, Option <Props> .None); system.Start(); return(system); }
static void OpenWindow(ActorSystemSetup asset) { var window = GetWindow(asset); window.Reload(); }
/// <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, BootstrapSetup setup) { return(Create(name, ActorSystemSetup.Create(setup))); }