Example #1
0
        public RoutedActorCell(ActorSystem system, InternalActorRef supervisor, Props routerProps, Props routeeProps, ActorPath path,
            Mailbox mailbox)
            : base(system, supervisor, routerProps, path, mailbox)
        {
            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 = this.ActorOf(RouteeProps);
                        routees.Add(new ActorRefRoutee(routee));
                    }
                    AddRoutees(routees.ToArray());
                })
                .With<Group>(r =>
                {
                    var routees = routerConfig.GetRoutees(this).ToArray();
                    AddRoutees(routees);
                });



            Self = new RoutedActorRef(path, this);
        }
Example #2
0
        private RouterConfig OverrideUnsetConfig(RouterConfig other)
        {
            if (other is Pool pool)
            {
                RandomPool wssConf;

                if (SupervisorStrategy != null &&
                    SupervisorStrategy.Equals(DefaultSupervisorStrategy) &&
                    !pool.SupervisorStrategy.Equals(DefaultSupervisorStrategy))
                {
                    wssConf = WithSupervisorStrategy(pool.SupervisorStrategy);
                }
                else
                {
                    wssConf = this;
                }

                if (wssConf.Resizer == null && pool.Resizer != null)
                {
                    return(wssConf.WithResizer(pool.Resizer));
                }

                return(wssConf);
            }

            return(this);
        }
Example #3
0
        protected RouterConfig OverrideUnsetConfig(RouterConfig other)
        {
            if (other is NoRouter)
            {
                return(this);                   // NoRouter is the default, hence "neutral"
            }
            if (other is Pool)
            {
                Pool wssConf;
                var  p = other as Pool;
                if (SupervisorStrategy == null || (SupervisorStrategy.Equals(Pool.DefaultStrategy) &&
                                                   !p.SupervisorStrategy.Equals(Pool.DefaultStrategy)))
                {
                    wssConf = this.WithSupervisorStrategy(p.SupervisorStrategy);
                }
                else
                {
                    wssConf = this;
                }

                if (wssConf.Resizer == null && p.Resizer != null)
                {
                    return(wssConf.WithResizer(p.Resizer));
                }
                return(wssConf);
            }
            return(this);
        }
Example #4
0
        public RoutedActorCell(ActorSystem system, InternalActorRef supervisor, Props routerProps, Props routeeProps, ActorPath path,
                               Mailbox mailbox)
            : base(system, supervisor, routerProps, path, mailbox)
        {
            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 = this.ActorOf(RouteeProps);
                    routees.Add(new ActorRefRoutee(routee));
                }
                AddRoutees(routees.ToArray());
            })
            .With <Group>(r =>
            {
                var routees = routerConfig.GetRoutees(this).ToArray();
                AddRoutees(routees);
            });



            Self = new RoutedActorRef(path, this);
        }
Example #5
0
 public Deploy(string path, Config config, RouterConfig routerConfig, Scope scope, string dispatcher)
 {
     Path = path;
     Config = config;
     RouterConfig = routerConfig;
     Scope = scope;
     Dispatcher = dispatcher;
 }
Example #6
0
 internal override void Post(ActorRef sender, object message)
 {
     if (!(RouterConfig.IsManagementMessage(message)) &&
         resizer.IsTimeForResize(Interlocked.Increment(ref _resizeCounter) - 1) &&
         Interlocked.Exchange(ref _resizeInProgress, ResizeInProgressState.True) == ResizeInProgressState.False)
     {
         base.Post(Self, new Resize());
     }
     base.Post(sender, message);
 }
Example #7
0
        public override void SendMessage(IActorRef sender, object message)
        {
            if (!(RouterConfig.IsManagementMessage(message)) &&
                resizer.IsTimeForResize(_resizeCounter.GetAndIncrement()) &&
                _resizeInProgress.CompareAndSet(false, true))
            {
                base.SendMessage(Self, new Resize());
            }

            base.SendMessage(sender, message);
        }
Example #8
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="envelope">TBD</param>
        public override void SendMessage(Envelope envelope)
        {
            if (!(RouterConfig.IsManagementMessage(envelope.Message)) &&
                resizer.IsTimeForResize(_resizeCounter.GetAndIncrement()) &&
                _resizeInProgress.CompareAndSet(false, true))
            {
                base.SendMessage(new Envelope(new Resize(), Self, System));
            }

            base.SendMessage(envelope);
        }
Example #9
0
        public override bool Equals(RouterConfig other)
        {
            if (!base.Equals(other))
            {
                return(false);
            }
            var otherGroup = other as Group;

            if (otherGroup == null)
            {
                return(false);                    //should never be true due to the previous check
            }
            return(Paths.Intersect(otherGroup.Paths).Count() == Paths.Length);
        }
 /// <summary>
 /// Configure the current router with an auxiliary router for routes that it does not know how to handle.
 /// </summary>
 /// <param name="routerConfig">The router to use as an auxiliary source.</param>
 /// <exception cref="ArgumentException">
 /// This exception is thrown if the given <paramref name="routerConfig"/> is not a <see cref="ConsistentHashingGroup"/>.
 /// </exception>
 /// <returns>The router configured with the auxiliary information.</returns>
 public override RouterConfig WithFallback(RouterConfig routerConfig)
 {
     if (routerConfig is FromConfig || routerConfig is NoRouter)
     {
         return(base.WithFallback(routerConfig));
     }
     else if (routerConfig is ConsistentHashingGroup other)
     {
         return(WithHashMapping(other._hashMapping));
     }
     else
     {
         throw new ArgumentException($"Expected ConsistentHashingGroup, got {routerConfig}", nameof(routerConfig));
     }
 }
Example #11
0
 /// <summary>
 /// Configure the current router with an auxiliary router for routes that it does not know how to handle.
 /// </summary>
 /// <param name="routerConfig">The router to use as an auxiliary source.</param>
 /// <exception cref="ArgumentException">
 /// This exception is thrown if the given <paramref name="routerConfig"/> is not a <see cref="ConsistentHashingPool"/>.
 /// </exception>
 /// <returns>The router configured with the auxiliary information.</returns>
 public override RouterConfig WithFallback(RouterConfig routerConfig)
 {
     if (routerConfig is FromConfig || routerConfig is NoRouter)
     {
         return(OverrideUnsetConfig(routerConfig));
     }
     else if (routerConfig is ConsistentHashingPool)
     {
         var other = routerConfig as ConsistentHashingPool;
         return(WithHashMapping(other._hashMapping).OverrideUnsetConfig(other));
     }
     else
     {
         throw new ArgumentException($"Expected ConsistentHashingPool, got {routerConfig}", nameof(routerConfig));
     }
 }
Example #12
0
 public override RouterConfig WithFallback(RouterConfig routerConfig)
 {
     if (routerConfig is FromConfig || routerConfig is NoRouter)
     {
         return(base.WithFallback(routerConfig));
     }
     else if (routerConfig is ConsistentHashingGroup)
     {
         var other = routerConfig as ConsistentHashingGroup;
         return(WithHashMapping(other.HashMapping));
     }
     else
     {
         throw new ArgumentException(string.Format("Expected ConsistentHashingGroup, got {0}", routerConfig),
                                     "routerConfig");
     }
 }
Example #13
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 #14
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 #15
0
        private RouterConfig OverrideUnsetConfig(RouterConfig other)
        {
            if (other is NoRouter)
            {
                return(this);
            }
            else
            {
                var pool = other as Pool;
                if (pool != null)
                {
                    RoundRobinPool wssConf;

                    if (SupervisorStrategy != null &&
                        SupervisorStrategy.Equals(Pool.DefaultSupervisorStrategy) &&
                        !(pool.SupervisorStrategy.Equals(Pool.DefaultSupervisorStrategy)))
                    {
                        wssConf = this.WithSupervisorStrategy(pool.SupervisorStrategy);
                    }
                    else
                    {
                        wssConf = this;
                    }

                    if (wssConf.Resizer == null && pool.Resizer != null)
                    {
                        return(wssConf.WithResizer(pool.Resizer));
                    }

                    return(wssConf);
                }
                else
                {
                    return(this);
                }
            }
        }
Example #16
0
 public static bool NoRouter(this RouterConfig config)
 {
     return(config == null || config is NoRouter);
 }
Example #17
0
 public virtual RouterConfig WithFallback(RouterConfig routerConfig)
 {
     return this;
 }
 public override RouterConfig WithFallback(RouterConfig routerConfig)
 {
     var localFallback = (ClusterRouterGroup) routerConfig;
     if (localFallback != null && (localFallback.Local is ClusterRouterGroup)) throw new ConfigurationException("ClusterRouterGroup is not allowed to wrap a ClusterRouterGroup");
     if (localFallback != null) return Copy(Local.WithFallback(localFallback.Local).AsInstanceOf<Group>());
     return Copy(Local.WithFallback(routerConfig).AsInstanceOf<Group>());
 }
 public override RouterConfig WithFallback(RouterConfig routerConfig)
 {
     if (routerConfig is FromConfig || routerConfig is NoRouter)
     {
         return base.WithFallback(routerConfig);
     }
     else if (routerConfig is ConsistentHashingGroup)
     {
         var other = routerConfig as ConsistentHashingGroup;
         return WithHashMapping(other.HashMapping);
     }
     else
     {
         throw new ArgumentException(string.Format("Expected ConsistentHashingGroup, got {0}", routerConfig),
             "routerConfig");
     }
 }
 /// <summary>
 /// Configure the current router with an auxiliary router for routes that it does not know how to handle.
 /// </summary>
 /// <param name="routerConfig">The router to use as an auxiliary source.</param>
 /// <exception cref="ArgumentException">
 /// This exception is thrown if the given <paramref name="routerConfig"/> is not a <see cref="ConsistentHashingGroup"/>.
 /// </exception>
 /// <returns>The router configured with the auxiliary information.</returns>
 public override RouterConfig WithFallback(RouterConfig routerConfig)
 {
     if (routerConfig is FromConfig || routerConfig is NoRouter)
     {
         return base.WithFallback(routerConfig);
     }
     else if (routerConfig is ConsistentHashingGroup)
     {
         var other = routerConfig as ConsistentHashingGroup;
         return WithHashMapping(other._hashMapping);
     }
     else
     {
         throw new ArgumentException($"Expected ConsistentHashingGroup, got {routerConfig}", nameof(routerConfig));
     }
 }
Example #21
0
 public virtual RouterConfig WithFallback(RouterConfig routerConfig)
 {
     return(this);
 }
Example #22
0
 public RoutedActorCell(ActorSystemImpl system, IInternalActorRef self, Props routerProps, MessageDispatcher dispatcher, Props routeeProps, IInternalActorRef supervisor)
     : base(system, self, routerProps, dispatcher, supervisor)
 {
     _routeeProps = routeeProps;
     _routerConfig = routerProps.RouterConfig;
 }
Example #23
0
 public override RouterConfig WithFallback(RouterConfig routerConfig)
 {
     var other = routerConfig as RemoteRouterConfig;
     if(other != null && other.Local is RemoteRouterConfig)
         throw new ArgumentException("RemoteRouterConfig is not allowed to wrap a RemoteRouterConfig", "routerConfig");
     if (other != null && other.Local != null)
         return Copy(Local.WithFallback(other.Local).AsInstanceOf<Pool>());
     return Copy(Local.WithFallback(routerConfig).AsInstanceOf<Pool>());
 }
Example #24
0
 public override bool Equals(RouterConfig other)
 {
     if (!base.Equals(other)) return false;
     var otherRemote = other as RemoteRouterConfig;
     if (otherRemote == null) return false; //should never be true due to the previous check
     return Local.Equals(otherRemote.Local) &&
            Nodes.Intersect(otherRemote.Nodes).Count() == Nodes.Count;
 }
 public override RouterConfig WithFallback(RouterConfig routerConfig)
 {
     if (routerConfig is FromConfig || routerConfig is NoRouter)
     {
         return OverrideUnsetConfig(routerConfig);
     }
     else if (routerConfig is ConsistentHashingPool)
     {
         var other = routerConfig as ConsistentHashingPool;
         return WithHashMapping(other._hashMapping).OverrideUnsetConfig(other);
     }
     else
     {
         throw new ArgumentException(string.Format("Expected ConsistentHashingPool, got {0}", routerConfig),
             "routerConfig");
     }
 }
Example #26
0
 /// <summary>
 /// Configure the current router with an auxiliary router for routes that it does not know how to handle.
 /// </summary>
 /// <param name="routerConfig">The router to use as an auxiliary source.</param>
 /// <returns>The router configured with the auxiliary information.</returns>
 public override RouterConfig WithFallback(RouterConfig routerConfig)
 {
     return OverrideUnsetConfig(routerConfig);
 }
Example #27
0
 public Deploy WithRouterConfig(RouterConfig routerConfig)
 {
     var copy = Copy();
     copy.RouterConfig = routerConfig;
     return copy;
 }
        public override RouterConfig WithFallback(RouterConfig other)
        {
            var localFallback = other as ClusterRouterGroup;
            if (localFallback != null && (localFallback.Local is ClusterRouterGroup))
            {
                throw new ConfigurationException("ClusterRouterGroup is not allowed to wrap a ClusterRouterGroup");
            }

            if (localFallback != null)
            {
                return Copy(Local.WithFallback(localFallback.Local).AsInstanceOf<Group>());
            }

            return Copy(Local.WithFallback(other).AsInstanceOf<Group>());
        }
Example #29
0
 public Deploy(RouterConfig routerConfig, Scope scope)
     : this()
 {
     RouterConfig = routerConfig;
     Scope = scope;
 }
Example #30
0
 /// <summary>
 /// Configure the current router with an auxiliary router for routes that it does not know how to handle.
 /// </summary>
 /// <param name="routerConfig">The router to use as an auxiliary source.</param>
 /// <returns>The router configured with the auxiliary information.</returns>
 public override RouterConfig WithFallback(RouterConfig routerConfig)
 {
     return(OverrideUnsetConfig(routerConfig));
 }
Example #31
0
 public Deploy(RouterConfig routerConfig)
 {
     RouterConfig = routerConfig;
 }
        private RouterConfig OverrideUnsetConfig(RouterConfig other)
        {
            if (other is NoRouter)
            {
                return this;
            }
            else
            {
                var pool = other as Pool;
                if (pool != null)
                {
                    ConsistentHashingPool wssConf;

                    if (SupervisorStrategy != null
                        && SupervisorStrategy.Equals(Pool.DefaultSupervisorStrategy)
                        && !(pool.SupervisorStrategy.Equals(Pool.DefaultSupervisorStrategy)))
                    {
                        wssConf = this.WithSupervisorStrategy(pool.SupervisorStrategy);
                    }
                    else
                    {
                        wssConf = this;
                    }

                    if (wssConf.Resizer == null && pool.Resizer != null)
                        return wssConf.WithResizer(pool.Resizer);

                    return wssConf;
                }
                else
                {
                    return this;
                }
            }
        }
 public override RouterConfig WithFallback(RouterConfig routerConfig)
 {
     var otherClusterRouterPool = (ClusterRouterPool) routerConfig;
     if(otherClusterRouterPool != null && otherClusterRouterPool.Local is ClusterRouterPool) throw new ConfigurationException("ClusterRouterPool is not allowed to wrap a ClusterRouterPool");
     if (otherClusterRouterPool != null)
         return Copy(Local.WithFallback(otherClusterRouterPool.Local).AsInstanceOf<Pool>());
     return Copy(Local.WithFallback(routerConfig).AsInstanceOf<Pool>());
 }
Example #34
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="routerConfig">TBD</param>
 /// <returns>TBD</returns>
 public override RouterConfig WithFallback(RouterConfig routerConfig)
 {
     return(routerConfig);
 }
Example #35
0
 public RoutedActorCell(ActorSystemImpl system, IInternalActorRef self, Props routerProps, MessageDispatcher dispatcher, Props routeeProps, IInternalActorRef supervisor)
     : base(system, self, routerProps, dispatcher, supervisor)
 {
     _routeeProps  = routeeProps;
     _routerConfig = routerProps.RouterConfig;
 }