public ResizablePoolCell(ActorSystemImpl system, IInternalActorRef self, Props routerProps, MessageDispatcher dispatcher, Props routeeProps, IInternalActorRef supervisor, Pool pool) : base(system,self, routerProps,dispatcher, routeeProps, supervisor) { if (pool.Resizer == null) throw new ArgumentException("RouterConfig must be a Pool with defined resizer"); resizer = pool.Resizer; _routerProps = routerProps; _pool = pool; _resizeCounter = new AtomicCounterLong(0); _resizeInProgress = new AtomicBoolean(); }
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 = false; } }