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; } } }
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; } } }
/// <summary> /// Called when [receive]. /// </summary> /// <param name="message">The message.</param> protected override void OnReceive(object message) { if (message is AdjustPoolSize poolSize) { if (poolSize.Change > 0) { var newRoutees = Vector.Fill <Routee>(poolSize.Change)(() => Pool.NewRoutee(Cell.RouteeProps, Context)); Cell.AddRoutees(newRoutees); } else if (poolSize.Change < 0) { var currentRoutees = Cell.Router.Routees.ToArray(); var abandon = currentRoutees .Skip(currentRoutees.Length + poolSize.Change) .ToList(); Cell.RemoveRoutees(abandon, true); } } else { base.OnReceive(message); } }
/// <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; } } }