示例#1
0
        public static Spawner Spawner(IRouterConfig config)
        {
            PID spawnRouterProcess(string name, Props props, PID parent)
            {
                var routeeProps = props.WithSpawner(null);
                var routerState = config.CreateRouterState();
                var wg          = new AutoResetEvent(false);
                var routerProps = Actor.FromProducer(() => new RouterActor(routeeProps, config, routerState, wg))
                                  .WithMailbox(props.MailboxProducer);

                var ctx        = new LocalContext(routerProps.Producer, props.SupervisorStrategy, props.ReceiveMiddlewareChain, props.SenderMiddlewareChain, parent);
                var mailbox    = routerProps.MailboxProducer();
                var dispatcher = routerProps.Dispatcher;
                var reff       = new RouterProcess(routerState, mailbox);

                var(pid, absent) = ProcessRegistry.Instance.TryAdd(name, reff);
                if (!absent)
                {
                    throw new ProcessNameExistException(name);
                }
                ctx.Self = pid;
                mailbox.RegisterHandlers(ctx, dispatcher);
                mailbox.PostSystemMessage(Started.Instance);
                mailbox.Start();
                wg.WaitOne();
                return(pid);
            }

            return(spawnRouterProcess);
        }
示例#2
0
        public static Spawner Spawner(IRouterConfig config)
        {
            return((id, props, parent) =>
            {
                var routeeProps = props.WithSpawner(null);
                var routerState = config.CreateRouterState();
                var wg = new AutoResetEvent(false);
                var routerProps = Actor.FromProducer(() => new RouterActor(routeeProps, config, routerState, wg));
                var routerId = ProcessRegistry.Instance.NextId();
                var router = Props.DefaultSpawner(routerId + "/router", routerProps, parent);
                wg.WaitOne(); //wait for the router to start

                var reff = new RouterProcess(router, routerState);
                var(pid, ok) = ProcessRegistry.Instance.TryAdd(routerId, reff);
                return pid;
            });
        }