Ejemplo n.º 1
0
        internal void Resize(bool initial)
        {
            if (_resizeInProgress.Value || initial)
            {
                try
                {
                    var requestedCapacity = resizer.Resize(Router.Routees);
                    if (requestedCapacity > 0)
                    {
                        var newRoutees = new List <Routee>();
                        for (var i = 0; i < requestedCapacity; i++)
                        {
                            newRoutees.Add(_pool.NewRoutee(RouteeProps, this));
                        }
                        AddRoutees(newRoutees.ToArray());
                    }
                    else if (requestedCapacity < 0)
                    {
                        var currentRoutees = Router.Routees;
                        var enumerable     = currentRoutees as Routee[] ?? currentRoutees.ToArray();

                        var routeesToAbandon = enumerable
                                               .Drop(enumerable.Count() + requestedCapacity)
                                               .ToList();

                        RemoveRoutees(routeesToAbandon, true);
                    }
                }
                finally
                {
                    _resizeInProgress.Value = false;
                }
            }
        }
Ejemplo n.º 2
0
 internal void Resize(bool initial)
 {
     if (_resizeInProgress == ResizeInProgressState.True || initial)
     {
         try
         {
             var requestedCapacity = resizer.Resize(Router.Routees);
             if (requestedCapacity > 0)
             {
                 var newRoutees = new List <Routee>();
                 for (var i = 0; i < requestedCapacity; i++)
                 {
                     newRoutees.Add(_pool.NewRoutee(RouteeProps, this));
                 }
                 AddRoutees(newRoutees.ToArray());
             }
             else if (requestedCapacity < 0)
             {
                 var currentRoutees   = Router.Routees;
                 var enumerable       = currentRoutees as Routee[] ?? currentRoutees.ToArray();
                 var routeesToAbandon = enumerable.Drop(enumerable.Count() + requestedCapacity);
                 foreach (var routee in routeesToAbandon.OfType <ActorRefRoutee>())
                 {
                     RemoveRoutee(routee.Actor, true);
                 }
             }
         }
         finally
         {
             _resizeInProgress = ResizeInProgressState.False;
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="initial">TBD</param>
        internal void Resize(bool initial)
        {
            if (_resizeInProgress.Value || initial)
            {
                try
                {
                    var requestedCapacity = resizer.Resize(Router.Routees);
                    if (requestedCapacity > 0)
                    {
                        var newRoutees = Vector.Fill <Routee>(requestedCapacity)(() => _pool.NewRoutee(RouteeProps, this));
                        AddRoutees(newRoutees);
                    }
                    else if (requestedCapacity < 0)
                    {
                        var currentRoutees = Router.Routees.ToList();

                        var abandon = currentRoutees
                                      .Drop(currentRoutees.Count + requestedCapacity)
                                      .ToList();

                        RemoveRoutees(abandon, stopChild: true);
                    }
                }
                finally
                {
                    _resizeInProgress.Value = false;
                }
            }
        }