Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new <see cref="Akka.Actor.Props" /> with a given router.
        ///
        /// <note>
        /// This method is immutable and returns a new instance of <see cref="Akka.Actor.Props" />.
        /// </note>
        /// </summary>
        /// <param name="routerConfig">The router used when deploying the actor.</param>
        /// <returns>A new <see cref="Akka.Actor.Props" /> with the provided <paramref name="routerConfig" />.</returns>
        public Props WithRouter(RouterConfig routerConfig)
        {
            Props copy = Copy();

            copy.Deploy = Deploy.WithRouterConfig(routerConfig);
            return(copy);
        }
Ejemplo n.º 2
0
 /// <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;
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        ///     Returns a new Props with the specified deployment configuration.
        /// </summary>
        /// <param name="deploy">The deploy.</param>
        /// <returns>Props.</returns>
        public Props WithDeploy(Deploy deploy)
        {
            Props copy     = Copy();
            var   original = copy.Deploy;

            // TODO: this is a hack designed to preserve explicit router deployments https://github.com/akkadotnet/akka.net/issues/546
            // in reality, we should be able to do copy.Deploy = deploy.WithFallback(copy.Deploy); but that blows up at the moment
            // - Aaron Stannard
            if (!(original.RouterConfig is NoRouter || original.RouterConfig is FromConfig) && deploy.RouterConfig is NoRouter)
            {
                copy.Deploy = deploy.WithRouterConfig(original.RouterConfig);
            }
            else
            {
                copy.Deploy = deploy;
            }

            return(copy);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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;
            }
        }
Ejemplo n.º 6
0
        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 != 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);
            }
        }
Ejemplo n.º 7
0
        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;
        }