public void SetDeploy(Deploy deploy) { Action<IList<string>, Deploy> add = (path, d) => { bool set; do { var w = _deployments.Value; foreach (var t in path) { var curPath = t; if (string.IsNullOrEmpty(curPath)) throw new IllegalActorNameException(string.Format("Actor name in deployment [{0}] must not be empty", d.Path)); if (!ActorPath.IsValidPathElement(t)) { throw new IllegalActorNameException( string.Format("Illegal actor name [{0}] in deployment [${1}]. Actor paths MUST: not start with `$`, include only ASCII letters and can only contain these special characters: ${2}.", t, d.Path, new String(ActorPath.ValidSymbols))); } } set = _deployments.CompareAndSet(w, w.Insert(path.GetEnumerator(), d)); } while(!set); }; var elements = deploy.Path.Split('/').Drop(1).ToList(); add(elements, deploy); }
/// <summary> /// Initializes a new instance of the <see cref="DaemonMsgCreate" /> class. /// </summary> /// <param name="props">The props.</param> /// <param name="deploy">The deploy.</param> /// <param name="path">The path.</param> /// <param name="supervisor">The supervisor.</param> public DaemonMsgCreate(Props props, Deploy deploy, string path, IActorRef supervisor) { Props = props; Deploy = deploy; Path = path; Supervisor = supervisor; }
/// <summary> /// Initializes a new instance of the <see cref="RemoteActorRef"/> class. /// </summary> /// <param name="remote">The remote.</param> /// <param name="localAddressToUse">The local address to use.</param> /// <param name="path">The path.</param> /// <param name="parent">The parent.</param> /// <param name="props">The props.</param> /// <param name="deploy">The deploy.</param> internal RemoteActorRef(RemoteTransport remote, Address localAddressToUse, ActorPath path, InternalActorRef parent, Props props, Deploy deploy) { Remote = remote; LocalAddressToUse = localAddressToUse; Path = path; _parent = parent; _props = props; _deploy = deploy; }
public virtual Deploy ParseConfig(string key, Config config) { var deployment = config.WithFallback(_default); var routerType = deployment.GetString("router"); var router = CreateRouterConfig(routerType, deployment); var dispatcher = deployment.GetString("dispatcher"); var mailbox = deployment.GetString("mailbox"); var deploy = new Deploy(key, deployment, router, Deploy.NoScopeGiven, dispatcher, mailbox); return deploy; }
public Deploy WithFallback(Deploy other) { return new Deploy { Path = Path, Config = Config.WithFallback(other.Config), RouterConfig = RouterConfig.WithFallback(other.RouterConfig), Scope = Scope.WithFallback(other.Scope), Dispatcher = Dispatcher == NoDispatcherGiven ? other.Dispatcher : Dispatcher, Mailbox = Mailbox == NoMailboxGiven ? other.Mailbox : Mailbox, }; }
public void Serialization_must_serialize_and_deserialize_DaemonMsgCreate_with_Deploy_and_RouterConfig() { var supervisorStrategy = new OneForOneStrategy(3, TimeSpan.FromSeconds(10), exception => Directive.Escalate); var deploy1 = new Deploy("path1", ConfigurationFactory.ParseString("a=1"), new RoundRobinPool(5, null, supervisorStrategy, null), new RemoteScope(new Address("akka", "Test", "host1", 1921)), "mydispatcher"); var deploy2 = new Deploy("path2", ConfigurationFactory.ParseString("a=2"), FromConfig.Instance, new RemoteScope(new Address("akka", "Test", "host2", 1922)), Deploy.NoDispatcherGiven); VerifySerialization(new DaemonMsgCreate(Props.Create<MyActor>().WithDispatcher("my-disp").WithDeploy(deploy1), deploy2, "foo", _supervisor)); }
/// <summary> /// Used to determine if a given <see cref="deploy"/> is an instance of <see cref="RemoteRouterConfig"/>. /// </summary> private static Deploy CheckRemoteRouterConfig(Deploy deploy) { var nodes = deploy.Config.GetStringList("target.nodes").Select(Address.Parse).ToList(); if (nodes.Any() && deploy.RouterConfig != RouterConfig.NoRouter) { if (deploy.RouterConfig is Pool) return deploy.WithRouterConfig(new RemoteRouterConfig(deploy.RouterConfig.AsInstanceOf<Pool>(), nodes)); return deploy.WithScope(scope: Deploy.NoScopeGiven); } else { //TODO: return deploy; return deploy; } }
public void SetDeploy(Deploy deploy) { Action<IList<string>, Deploy> add = (path, d) => { bool set; do { var w = _deployments.Value; foreach (var t in path) { var curPath = t; if (string.IsNullOrEmpty(curPath)) throw new IllegalActorNameException(string.Format("Actor name in deployment [{0}] must not be empty", d.Path)); if (!ActorPath.ElementRegex.IsMatch(t)) { throw new IllegalActorNameException(string.Format("Actor name in deployment [{0}] must conform to {1}", d.Path, ActorPath.ElementRegex)); } } set = _deployments.CompareAndSet(w, w.Insert(path.GetEnumerator(), d)); } while(!set); }; var elements = deploy.Path.Split('/').Drop(1).ToList(); add(elements, deploy); }
public override void AddRoutees() { var deploymentTarget = SelectDeploymentTarget(); while (deploymentTarget != null) { var routeeProps = Cell.RouteeProps; var deploy = new Deploy( path: string.Empty, config: ConfigurationFactory.Empty, routerConfig: routeeProps.RouterConfig, scope: new RemoteScope(deploymentTarget), dispatcher: Deploy.NoDispatcherGiven); var routee = Pool.NewRoutee(routeeProps.WithDeploy(deploy), Context); //must register each one, since registered routees are used in SelectDeploymentTarget Cell.AddRoutee(routee); deploymentTarget = SelectDeploymentTarget(); } }
private void Deploy(ActorSystem system, Deploy d) { system.Provider.AsInstanceOf<RemoteActorRefProvider>().Deployer.SetDeploy(d); }
public override Routee NewRoutee(Props routeeProps, IActorContext context) { _nodeAddrEnumerator.MoveNext(); var name = "c" + _childNameCounter.GetAndIncrement(); var deploy = new Deploy(routeeProps.RouterConfig, new RemoteScope(_nodeAddrEnumerator.Current)); var actorRef = context.AsInstanceOf<ActorCell>() .AttachChild(Local.EnrichWithPoolDispatcher(routeeProps, context).WithDeploy(deploy), false, name); return new ActorRefRoutee(actorRef); }
public InternalActorRef ActorOf(ActorSystemImpl system, Props props, InternalActorRef supervisor, ActorPath path, bool systemService, Deploy deploy, bool lookupDeploy, bool async) { //TODO: This does not match Akka's ActorOf at all Deploy configDeploy = _system.Provider.Deployer.Lookup(path); deploy = configDeploy ?? props.Deploy ?? Deploy.None; if(deploy.Mailbox != Deploy.NoMailboxGiven) props = props.WithMailbox(deploy.Mailbox); if(deploy.Dispatcher != Deploy.NoDispatcherGiven) props = props.WithDispatcher(deploy.Dispatcher); //TODO: how should this be dealt with? //akka simply passes the "deploy" var from remote daemon to ActorOf //so it atleast seems like they ignore if remote scope is provided here. //leaving this for now since it does work if(props.RouterConfig.NoRouter()) { return CreateNoRouter(system, props, supervisor, path, deploy, async); } return CreateWithRouter(system, props, supervisor, path, deploy, async); }
private InternalActorRef CreateWithRouter(ActorSystemImpl system, Props props, InternalActorRef supervisor, ActorPath path, Deploy deploy, bool async) { //if no Router config value was specified, override with procedural input if (deploy.RouterConfig.NoRouter()) { deploy = deploy.WithRouterConfig(props.RouterConfig); } var routerDispatcher = system.Dispatchers.FromConfig(props.RouterConfig.RouterDispatcher); var routerMailbox = _system.Mailboxes.CreateMailbox(props, null); //TODO: Should be val routerMailbox = system.mailboxes.getMailboxType(routerProps, routerDispatcher.configurator.config) // routers use context.actorOf() to create the routees, which does not allow us to pass // these through, but obtain them here for early verification var routerProps = Props.Empty.WithDeploy(deploy); var routeeProps = props.WithRouter(RouterConfig.NoRouter); var routedActorRef = new RoutedActorRef(system, routerProps, routerDispatcher, () => routerMailbox, routeeProps, supervisor, path); routedActorRef.Initialize(async); return routedActorRef; }
public void UseActorOnNode(RemoteActorRef actor, Props props, Deploy deploy, InternalActorRef supervisor) { Akka.Serialization.Serialization.CurrentTransportInformation = new Information { System = System, Address = actor.LocalAddressToUse, }; log.Debug("[{0}] Instantiating Remote Actor [{1}]", RootPath, actor.Path); ActorRef remoteNode = ResolveActorRef(new RootActorPath(actor.Path.Address)/"remote"); remoteNode.Tell(new DaemonMsgCreate(props, deploy, actor.Path.ToSerializationFormat(), supervisor)); }
private InternalActorRef CreateNoRouter(ActorSystemImpl system, Props props, InternalActorRef supervisor, ActorPath path, Deploy deploy, bool async) { if(props.Deploy != deploy) props = props.WithDeploy(deploy); var dispatcher = system.Dispatchers.FromConfig(props.Dispatcher); var mailbox = _system.Mailboxes.CreateMailbox(props, null /*dispatcher.Configurator.Config*/); //TODO: Should be: system.mailboxes.getMailboxType(props2, dispatcher.configurator.config) if (async) { var reActorRef = new RepointableActorRef(system, props, dispatcher, () => mailbox, supervisor, path); reActorRef.Initialize(async: true); return reActorRef; } return new LocalActorRef(system, props, dispatcher, () => mailbox, supervisor, path); }
public IInternalActorRef ActorOf(ActorSystemImpl system, Props props, IInternalActorRef supervisor, ActorPath path, bool systemService, Deploy deploy, bool lookupDeploy, bool async) { if (props.Deploy.RouterConfig.NoRouter()) { if (Settings.DebugRouterMisconfiguration) { var d = Deployer.Lookup(path); if (d != null && d.RouterConfig != RouterConfig.NoRouter) Log.Warning("Configuration says that [{0}] should be a router, but code disagrees. Remove the config or add a RouterConfig to its Props.", path); } var props2 = props; // mailbox and dispatcher defined in deploy should override props var propsDeploy = lookupDeploy ? Deployer.Lookup(path) : deploy; if (propsDeploy != null) { if (propsDeploy.Mailbox != Deploy.NoMailboxGiven) props2 = props2.WithMailbox(propsDeploy.Mailbox); if (propsDeploy.Dispatcher != Deploy.NoDispatcherGiven) props2 = props2.WithDispatcher(propsDeploy.Dispatcher); } if (!system.Dispatchers.HasDispatcher(props2.Dispatcher)) { throw new ConfigurationException(string.Format("Dispatcher [{0}] not configured for path {1}", props2.Dispatcher, path)); } try { // for consistency we check configuration of dispatcher and mailbox locally var dispatcher = _system.Dispatchers.Lookup(props2.Dispatcher); if (async) return new RepointableActorRef(system, props2, dispatcher, () => _system.Mailboxes.CreateMailbox(props2, dispatcher.Configurator.Config), supervisor, path).Initialize(async); return new LocalActorRef(system, props2, dispatcher, () => _system.Mailboxes.CreateMailbox(props2, dispatcher.Configurator.Config), supervisor, path); } catch (Exception ex) { throw new ConfigurationException( string.Format( "Configuration problem while creating {0} with dispatcher [{1}] and mailbox [{2}]", path, props.Dispatcher, props.Mailbox), ex); } } else //routers!!! { var lookup = (lookupDeploy ? Deployer.Lookup(path) : null) ?? Deploy.None; var fromProps = new List<Deploy>() { props.Deploy, deploy, lookup }; var d = fromProps.Where(x => x != null).Aggregate((deploy1, deploy2) => deploy2.WithFallback(deploy1)); var p = props.WithRouter(d.RouterConfig); if (!system.Dispatchers.HasDispatcher(p.Dispatcher)) throw new ConfigurationException(string.Format("Dispatcher [{0}] not configured for routees of path {1}", p.Dispatcher, path)); if (!system.Dispatchers.HasDispatcher(d.RouterConfig.RouterDispatcher)) throw new ConfigurationException(string.Format("Dispatcher [{0}] not configured for router of path {1}", p.RouterConfig.RouterDispatcher, path)); var routerProps = Props.Empty.WithRouter(p.Deploy.RouterConfig).WithDispatcher(p.RouterConfig.RouterDispatcher); var routeeProps = props.WithRouter(RouterConfig.NoRouter); try { var routerDispatcher = system.Dispatchers.Lookup(p.RouterConfig.RouterDispatcher); var routerMailbox = system.Mailboxes.CreateMailbox(routerProps, routerDispatcher.Configurator.Config); // routers use context.actorOf() to create the routees, which does not allow us to pass // these through, but obtain them here for early verification var routeeDispatcher = system.Dispatchers.Lookup(p.Dispatcher); var routedActorRef = new RoutedActorRef(system, routerProps, routerDispatcher, () => routerMailbox, routeeProps, supervisor, path); routedActorRef.Initialize(async); return routedActorRef; } catch (Exception) { throw new ConfigurationException(string.Format("Configuration problem while creating [{0}] with router dispatcher [{1}] and mailbox {2}" + " and routee dispatcher [{3}] and mailbox [{4}].", path, routerProps.Dispatcher, routerProps.Mailbox, routeeProps.Dispatcher, routeeProps.Mailbox)); } } }
protected virtual Deploy ParseConfig(string key) { Config config = deployment.GetConfig(key).WithFallback(@default); var routerType = config.GetString("router"); var router = CreateRouterConfig(routerType, key, config, deployment); var dispatcher = config.GetString("dispatcher"); var mailbox = config.GetString("mailbox"); var scope = ParseScope(config); var deploy = new Deploy(key, deployment, router, scope ,dispatcher,mailbox); return deploy; }
private DeployData GetDeployData(Deploy deploy) { var res = DeployData.CreateBuilder() .SetPath(deploy.Path); if (deploy.Config != ConfigurationFactory.Empty) res.SetConfig(Serialize(deploy.Config)); if (deploy.RouterConfig != RouterConfig.NoRouter) res.SetRouterConfig(Serialize(deploy.RouterConfig)); if (deploy.Scope != Deploy.NoScopeGiven) res.SetScope(Serialize(deploy.Scope)); if (deploy.Dispatcher != Deploy.NoDispatcherGiven) res.SetDispatcher(deploy.Dispatcher); return res.Build(); }
public override void AddRoutees() { var deploymentTarget = SelectDeploymentTarget(); while (deploymentTarget != null) { var routeeProps = Cell.RouteeProps; var deploy = new Deploy(routeeProps.RouterConfig, new RemoteScope(deploymentTarget)); var routee = _pool.NewRoutee(routeeProps.WithDeploy(deploy), Context); //must register each one, since registered routees are used in SelectDeploymentTarget Cell.AddRoutee(routee); deploymentTarget = SelectDeploymentTarget(); } }
public InternalActorRef ActorOf(ActorSystem system, Props props, InternalActorRef supervisor, ActorPath path, bool systemService, Deploy deploy, bool lookupDeploy, bool async) { //TODO: This does not match Akka's ActorOf at all Deploy configDeploy = _system.Provider.Deployer.Lookup(path); deploy = configDeploy ?? props.Deploy ?? Deploy.None; if(deploy.Mailbox != null) props = props.WithMailbox(deploy.Mailbox); if(deploy.Dispatcher != null) props = props.WithDispatcher(deploy.Dispatcher); if(deploy.Scope is RemoteScope) { } if(string.IsNullOrEmpty(props.Mailbox)) { // throw new NotSupportedException("Mailbox can not be configured as null or empty"); } if(string.IsNullOrEmpty(props.Dispatcher)) { //TODO: fix this.. // throw new NotSupportedException("Dispatcher can not be configured as null or empty"); } //TODO: how should this be dealt with? //akka simply passes the "deploy" var from remote daemon to ActorOf //so it atleast seems like they ignore if remote scope is provided here. //leaving this for now since it does work //if (props.Deploy != null && props.Deploy.Scope is RemoteScope) //{ // throw new NotSupportedException("LocalActorRefProvider can not deploy remote"); //} if(props.RouterConfig is NoRouter || props.RouterConfig == null) { props = props.WithDeploy(deploy); var dispatcher = system.Dispatchers.FromConfig(props.Dispatcher); var mailbox = _system.Mailboxes.FromConfig(props.Mailbox); //TODO: Should be: system.mailboxes.getMailboxType(props2, dispatcher.configurator.config) if (async) { var reActorRef=new RepointableActorRef(system, props, dispatcher, () => mailbox, supervisor, path); reActorRef.Initialize(async:true); return reActorRef; } return new LocalActorRef(system, props, dispatcher, () => mailbox, supervisor, path); } else { //if no Router config value was specified, override with procedural input if(deploy.RouterConfig is NoRouter) { deploy = deploy.WithRouterConfig(props.RouterConfig); } var routerDispatcher = system.Dispatchers.FromConfig(props.RouterConfig.RouterDispatcher); var routerMailbox = _system.Mailboxes.FromConfig(props.Mailbox); //TODO: Should be val routerMailbox = system.mailboxes.getMailboxType(routerProps, routerDispatcher.configurator.config) // routers use context.actorOf() to create the routees, which does not allow us to pass // these through, but obtain them here for early verification var routerProps = Props.Empty.WithDeploy(deploy); var routeeProps = props.WithRouter(RouterConfig.NoRouter); var routedActorRef = new RoutedActorRef(system, routerProps, routerDispatcher, () => routerMailbox, routeeProps,supervisor, path); routedActorRef.Initialize(async); return routedActorRef; } }
//TODO: real akka does this in the RoutedActorRef //Keep this here for now? public static ActorCell NewRouterCell(ActorSystem system, InternalActorRef supervisor, ActorPath path, Props props, Mailbox mailbox,Deploy deploy) { var routerProps = Props.Empty.WithDeploy(deploy); var routeeProps = props.WithRouter(RouterConfig.NoRouter); if (routerProps.RouterConfig is Pool) { var p = routerProps.RouterConfig.AsInstanceOf<Pool>(); if (p.Resizer != null) { //if there is a resizer, use ResizablePoolCell return new ResizablePoolCell(system, supervisor, routerProps, routeeProps, path, mailbox, p); } } //Use RoutedActorCell for all other routers return new RoutedActorCell(system, supervisor, routerProps, routeeProps, path, mailbox); }