Exemple #1
0
 public abstract ActorRef ActorOf(Props props, string name = null);
Exemple #2
0
 public virtual InternalActorRef ActorOf <TActor>(string name = null) where TActor : ActorBase
 {
     return(ActorOf(Props.Create <TActor>(), name));
 }
Exemple #3
0
 public virtual InternalActorRef ActorOf(Props props, string name = null)
 {
     return(MakeChild(props, name));
 }
Exemple #4
0
 private DynamicProps(Props copy, Func <TActor> invoker)
     : base(copy)
 {
     this.invoker = invoker;
 }
Exemple #5
0
 /// <summary>
 /// TBD
 /// </summary>
 protected void ClearActorCell()
 {
     UnstashAll();
     _props = TerminatedProps;
 }
        /// <summary>
        /// Actor factory with create-only semantics: will create an actor as
        /// described by <paramref name="props" /> with the given <paramref name="supervisor" /> and <paramref name="path" /> (may be different
        /// in case of remote supervision). If <paramref name="systemService" /> is true, deployment is
        /// bypassed (local-only). If a value for<paramref name="deploy" /> is passed in, it should be
        /// regarded as taking precedence over the nominally applicable settings,
        /// but it should be overridable from external configuration; the lookup of
        /// the latter can be suppressed by setting "lookupDeploy" to "false".
        /// </summary>
        /// <param name="system">TBD</param>
        /// <param name="props">TBD</param>
        /// <param name="supervisor">TBD</param>
        /// <param name="path">TBD</param>
        /// <param name="systemService">TBD</param>
        /// <param name="deploy">TBD</param>
        /// <param name="lookupDeploy">TBD</param>
        /// <param name="async">TBD</param>
        /// <exception cref="ConfigurationException">
        /// This exception can be thrown for a number of reasons. The following are some examples:
        /// <dl>
        /// <dt><b>non-routers</b></dt>
        /// <dd>The dispatcher in the given <paramref name="props"/> is not configured for the given <paramref name="path"/>.</dd>
        /// <dd>or</dd>
        /// <dd>There was a configuration problem while creating the given <paramref name="path"/> with the dispatcher and mailbox from the given <paramref name="props"/></dd>
        /// <dt><b>routers</b></dt>
        /// <dd>The dispatcher in the given <paramref name="props"/> is not configured for routees of the given <paramref name="path"/></dd>
        /// <dd>or</dd>
        /// <dd>The dispatcher in the given <paramref name="props"/> is not configured for router of the given <paramref name="path"/></dd>
        /// <dd>or</dd>
        /// <dd>$There was a configuration problem while creating the given <paramref name="path"/> with router dispatcher and mailbox and routee dispatcher and mailbox.</dd>
        /// </dl>
        /// </exception>
        /// <returns>TBD</returns>
        public IInternalActorRef ActorOf(ActorSystemImpl system, Props props, IInternalActorRef supervisor, ActorPath path, bool systemService, Deploy deploy, bool lookupDeploy, bool async)
        {
            if (props.Deploy.RouterConfig is NoRouter)
            {
                if (Settings.DebugRouterMisconfiguration)
                {
                    var d = Deployer.Lookup(path);
                    if (d != null && !(d.RouterConfig is 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($"Dispatcher [{props2.Dispatcher}] not configured for path {path}");
                }

                try
                {
                    // for consistency we check configuration of dispatcher and mailbox locally
                    var dispatcher  = _system.Dispatchers.Lookup(props2.Dispatcher);
                    var mailboxType = _system.Mailboxes.GetMailboxType(props2, dispatcher.Configurator.Config);

                    if (async)
                    {
                        return
                            (new RepointableActorRef(system, props2, dispatcher,
                                                     mailboxType, supervisor,
                                                     path).Initialize(async));
                    }
                    return(new LocalActorRef(system, props2, dispatcher,
                                             mailboxType, supervisor, path));
                }
                catch (Exception ex)
                {
                    throw new ConfigurationException(
                              $"Configuration problem while creating [{path}] with dispatcher [{props.Dispatcher}] and mailbox [{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($"Dispatcher [{p.Dispatcher}] not configured for routees of path [{path}]");
                }
                if (!system.Dispatchers.HasDispatcher(d.RouterConfig.RouterDispatcher))
                {
                    throw new ConfigurationException($"Dispatcher [{p.RouterConfig.RouterDispatcher}] not configured for router of path [{path}]");
                }

                var routerProps = Props.Empty.WithRouter(p.Deploy.RouterConfig).WithDispatcher(p.RouterConfig.RouterDispatcher);
                var routeeProps = props.WithRouter(NoRouter.Instance);

                try
                {
                    var routerDispatcher = system.Dispatchers.Lookup(p.RouterConfig.RouterDispatcher);
                    var 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 routeeDispatcher = system.Dispatchers.Lookup(p.Dispatcher);

                    var routedActorRef = new RoutedActorRef(system, routerProps, routerDispatcher, routerMailbox, routeeProps,
                                                            supervisor, path);
                    routedActorRef.Initialize(async);
                    return(routedActorRef);
                }
                catch (Exception ex)
                {
                    throw new ConfigurationException(
                              $"Configuration problem while creating [{path}] with router dispatcher [{routerProps.Dispatcher}] and mailbox [{routerProps.Mailbox}] and routee dispatcher [{routeeProps.Dispatcher}] and mailbox [{routeeProps.Mailbox}].", ex);
                }
            }
        }
        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);
            }
        }
Exemple #8
0
 protected void ClearActorCell()
 {
     //TODO_ UnstashAll stashed system messages (this is not the same stash that might exist on the actor)
     _props = terminatedProps;
 }
Exemple #9
0
 /// <summary></summary>
 /// <exception cref="InvalidActorNameException">
 /// This exception is thrown if the given <paramref name="name"/> is an invalid actor name.
 /// </exception>
 /// <exception cref="ArgumentException">
 /// This exception is thrown if a pre-creation serialization occurred.
 /// </exception>
 /// <exception cref="InvalidOperationException">
 /// This exception is thrown if the actor tries to create a child while it is terminating or is terminated.
 /// </exception>
 public virtual IActorRef ActorOf(Props props, string name = null)
 {
     return(ActorOf(props, name, false, false));
 }
Exemple #10
0
 /// <summary></summary>
 /// <exception cref="InvalidActorNameException">
 /// This exception is thrown if the given <paramref name="name"/> is an invalid actor name.
 /// </exception>
 /// <exception cref="ArgumentException">
 /// This exception is thrown if a pre-creation serialization occurred.
 /// </exception>
 /// <exception cref="InvalidOperationException">
 /// This exception is thrown if the actor tries to create a child while it is terminating or is terminated.
 /// </exception>
 public virtual IActorRef AttachChild(Props props, bool isSystemService, string name = null)
 {
     return(MakeChild(props, name == null ? GetRandomActorName() : CheckName(name), true, isSystemService));
 }
Exemple #11
0
        private IInternalActorRef MakeChild(Props props, string name, bool async, bool systemService)
        {
            if (_systemImpl.Settings.SerializeAllCreators && !systemService && props.Deploy != Deploy.Local)
            {
                var ser = _systemImpl.Serialization;
                if (props.Arguments != null)
                {
                    foreach (var argument in props.Arguments)
                    {
                        if (argument != null && !(argument is INoSerializationVerificationNeeded))
                        {
                            var objectType         = argument.GetType();
                            var serializer         = ser.FindSerializerFor(objectType);
                            var bytes              = serializer.ToBinary(objectType);
                            var manifestSerializer = serializer as SerializerWithStringManifest;
                            if (manifestSerializer != null)
                            {
                                var manifest = manifestSerializer.Manifest(objectType);
                                if (ser.Deserialize(bytes, manifestSerializer.Identifier, manifest) == null)
                                {
                                    throw new ArgumentException($"Pre-creation serialization check failed at [${_self.Path}/{name}]", nameof(name));
                                }
                            }
                            else
                            {
                                if (ser.Deserialize(bytes, serializer.Identifier, argument.GetType().AssemblyQualifiedName) == null)
                                {
                                    throw new ArgumentException($"Pre-creation serialization check failed at [${_self.Path}/{name}]", nameof(name));
                                }
                            }
                        }
                    }
                }
            }

            // In case we are currently terminating, fail external attachChild requests
            // (internal calls cannot happen anyway because we are suspended)
            if (ChildrenContainer.IsTerminating)
            {
                throw new InvalidOperationException("Cannot create child while terminating or terminated");
            }
            else
            {
                // this name will either be unreserved or overwritten with a real child below
                ReserveChild(name);
                IInternalActorRef actor;
                try
                {
                    var childPath = new ChildActorPath(Self.Path, name, NewUid());
                    actor = _systemImpl.Provider.ActorOf(_systemImpl, props, _self, childPath,
                                                         systemService: systemService, deploy: null, lookupDeploy: true, async: async);
                }
                catch
                {
                    //if actor creation failed, unreserve the name
                    UnreserveChild(name);
                    throw;
                }

                if (Mailbox != null && IsFailed)
                {
                    for (var i = 1; i <= Mailbox.SuspendCount(); i++)
                    {
                        actor.Suspend();
                    }
                }

                //replace the reservation with the real actor
                InitChild(actor);
                actor.Start();
                return(actor);
            }
        }
Exemple #12
0
 /// <summary>
 /// Creates a new system actor in the "/system" namespace. This actor
 /// will be shut down during system shutdown only after all user actors have
 /// terminated.
 /// </summary>
 /// <param name="props">The <see cref="Props"/> used to create the actor</param>
 /// <param name="name">The name of the actor to create. The default value is <see langword="null"/>.</param>
 /// <returns>A reference to the newly created actor</returns>
 public abstract IActorRef SystemActorOf(Props props, string name = null);