Example #1
0
 internal void AddRoutees(IList<Routee> routees)
 {
     foreach (var routee in routees)
     {
         Watch(routee);
     }
     _router = _router.WithRoutees(_router.Routees.Concat(routees).ToArray());
 }
Example #2
0
 protected void AddRoutees(Routee[] routees)
 {
     foreach(var routee in routees)
     {
         if(routee is ActorRefRoutee)
         {
             var @ref = ((ActorRefRoutee)routee).Actor;
             Watch(@ref);
         }
     }
     _router = _router.WithRoutees(_router.Routees.Concat(routees).ToArray());
 }
Example #3
0
        /// <summary>
        /// Remove routees from <see cref="Router"/>. Messages in flight may still
        /// be routed to the old <see cref="Router"/> instance containing the old routees.
        /// </summary>
        /// <param name="affectedRoutees"></param>
        /// <param name="stopChild"></param>
        internal void RemoveRoutees(IList<Routee> affectedRoutees, bool stopChild)
        {
            var routees = _router.Routees
                .Where(routee => !affectedRoutees.Contains(routee))
                .ToArray();

            _router = _router.WithRoutees(routees);

            foreach (var affectedRoutee in affectedRoutees)
            {
                Unwatch(affectedRoutee);
                if(stopChild)
                    StopIfChild(affectedRoutee);
            }

        }
Example #4
0
        internal void RemoveRoutee(ActorRef actorRef, bool stopChild)
        {
            var routees = _router.Routees.ToList();
            routees.RemoveAll(r =>
            {
                var routee = r as ActorRefRoutee;
                if(routee != null)
                {
                    return routee.Actor == actorRef;
                }
                return false;
            });
            _router = _router.WithRoutees(routees.ToArray());
            if(stopChild)
            {

            }
        }
Example #5
0
 public RoutedActorCell(ActorSystemImpl system, InternalActorRef self, Props routerProps, MessageDispatcher dispatcher, Props routeeProps, InternalActorRef supervisor)
     : base(system, self, routerProps, dispatcher, supervisor)
 {
     _routeeProps = routeeProps;
     _routerConfig = routerProps.RouterConfig;
     _router = _routerConfig.CreateRouter(system);
     _routerConfig.Match()
         .With<Pool>(r =>
         {
             var routees = new List<Routee>();
             for(int i = 0; i < r.NrOfInstances; i++)
             {
                 var routee = ActorOf(_routeeProps);
                 routees.Add(new ActorRefRoutee(routee));
             }
             AddRoutees(routees.ToArray());
         })
         .With<Group>(r =>
         {
             var routees = _routerConfig.GetRoutees(this).ToArray();
             AddRoutees(routees);
         });
 }
Example #6
0
        public void Router_RemoveRoute_should_remove_existing_routee_and_leave_the_rest()
        {
            var blackHole1 = ActorOf<BlackHoleActor>();
            var blackHole2 = ActorOf<BlackHoleActor>();
            var router = new Router(new RoundRobinRoutingLogic(), TestActor, blackHole1, blackHole2);

            var updatedRouter = router.RemoveRoutee(TestActor);
            updatedRouter.Routees.Count().ShouldBe(2);
            updatedRouter.Routees.Cast<ActorRefRoutee>().Any(r => ReferenceEquals(r.Actor, blackHole1)).ShouldBe(true);
            updatedRouter.Routees.Cast<ActorRefRoutee>().Any(r => ReferenceEquals(r.Actor, blackHole2)).ShouldBe(true);
        }
Example #7
0
 public void Router_AddRoute_should_add_new_routee()
 {
     var router = new Router(new RoundRobinRoutingLogic(), TestActor);
     var blackHole = ActorOf<BlackHoleActor>();
     var updatedRouter = router.AddRoutee(blackHole);
     updatedRouter.Routees.Count().ShouldBe(2);
     updatedRouter.Routees.Cast<ActorRefRoutee>().Any(r => ReferenceEquals(r.Actor, TestActor)).ShouldBe(true);
     updatedRouter.Routees.Cast<ActorRefRoutee>().Any(r => ReferenceEquals(r.Actor, blackHole)).ShouldBe(true);
 }
Example #8
0
        public void Router_AddRoute_should_not_add_same_routee()
        {
            var router = new Router(new RoundRobinRoutingLogic(), TestActor);

            var updatedRouter = router.AddRoutee(TestActor);
            updatedRouter.Routees.Count().ShouldBe(1);
            updatedRouter.Routees.First().AsInstanceOf<ActorRefRoutee>().Actor.ShouldBe(TestActor);
        }
        public Streamer()
        {
            RequestStrategy = new InFlightStrategy(this);

            var routees = new[]
            {
                Routee.FromActorRef(Context.ActorOf(Props.Create<Worker>().WithDispatcher(Context.Props.Dispatcher))),
                Routee.FromActorRef(Context.ActorOf(Props.Create<Worker>().WithDispatcher(Context.Props.Dispatcher))),
                Routee.FromActorRef(Context.ActorOf(Props.Create<Worker>().WithDispatcher(Context.Props.Dispatcher)))
            };
            _router = new Router(new RoundRobinRoutingLogic(), routees);
        }
Example #10
0
 public override void Start()
 {
     // create the initial routees before scheduling the Router actor
     _router = _routerConfig.CreateRouter(System);
     _routerConfig.Match()
         .With<Pool>(pool =>
         {
             var nrOfRoutees = pool.GetNrOfInstances(System);
             if (nrOfRoutees > 0)
                 AddRoutees(Vector.Fill<Routee>(nrOfRoutees)(() => pool.NewRoutee(_routeeProps, this)));
         })
         .With<Group>(group =>
         {
             var paths = group.Paths;
             if (paths.NonEmpty())
                 AddRoutees(paths.Select(p => group.RouteeFor(p, this)).ToList());
         });
     PreSuperStart();
     base.Start();
 }
Example #11
0
 internal void RemoveRoutees(IEnumerable<Routee> affectedRoutees, bool stopChild)
 {
     var routees = _router.Routees.ToList();
     routees.RemoveAll(r =>
     {
         var routee = r as ActorRefRoutee;
         if (routee != null)
         {
             return affectedRoutees.Contains(routee);
         }
         return false;
     });
     _router = _router.WithRoutees(routees.ToArray());
     if (stopChild)
     {
         foreach (var affectedRoutee in affectedRoutees)
         {
             StopIfChild(affectedRoutee);
         }
     }
 }
Example #12
0
            public RoundRobinLogicActor()
            {
                var n = 0;
                var router = new Router(new RoundRobinRoutingLogic());

                Receive<Props>(p =>
                {
                    n++;
                    var c = Context.ActorOf(p, "child-" + n);
                    Context.Watch(c);
                    router = router.AddRoutee(c);
                });

                Receive<Terminated>(terminated =>
                {
                    router = router.RemoveRoutee(terminated.ActorRef);
                    if (!router.Routees.Any())
                    {
                        Context.Stop(Self);
                    }
                });

                ReceiveAny(other =>
                {
                    router.Route(other, Sender);
                });
            }