Restructuring some methods in ActorPool, and switch to PoisonPill for postStop cleanup, to let workers finish their tasks before shutting down
This commit is contained in:
parent
f7e215c1be
commit
d237e09740
1 changed files with 13 additions and 12 deletions
|
|
@ -56,7 +56,11 @@ trait DefaultActorPool extends ActorPool { this: Actor =>
|
|||
private var _lastCapacityChange = 0
|
||||
private var _lastSelectorCount = 0
|
||||
|
||||
override def postStop = _delegates foreach {_ stop}
|
||||
override def postStop = _delegates foreach {
|
||||
delegate => try {
|
||||
delegate ! PoisonPill
|
||||
} catch { case e: Exception => } //Ignore any exceptions here
|
||||
}
|
||||
|
||||
protected def _route(): Receive = {
|
||||
// for testing...
|
||||
|
|
@ -65,11 +69,16 @@ trait DefaultActorPool extends ActorPool { this: Actor =>
|
|||
case max: MaximumNumberOfRestartsWithinTimeRangeReached =>
|
||||
_delegates = _delegates filterNot { _.uuid == max.victim.uuid }
|
||||
case msg =>
|
||||
_capacity()
|
||||
_select() foreach { _ forward msg }
|
||||
resizeIfAppropriate()
|
||||
|
||||
select(_delegates) match {
|
||||
case (selectedDelegates, count) =>
|
||||
_lastSelectorCount = count
|
||||
selectedDelegates foreach { _ forward msg }
|
||||
}
|
||||
}
|
||||
|
||||
private def _capacity() {
|
||||
private def resizeIfAppropriate() {
|
||||
val requestedCapacity = capacity(_delegates)
|
||||
val newDelegates = requestedCapacity match {
|
||||
case qty if qty > 0 =>
|
||||
|
|
@ -79,26 +88,18 @@ trait DefaultActorPool extends ActorPool { this: Actor =>
|
|||
delegate
|
||||
}
|
||||
}
|
||||
|
||||
case qty if qty < 0 =>
|
||||
_delegates.splitAt(_delegates.length + requestedCapacity) match {
|
||||
case (keep, abandon) =>
|
||||
abandon foreach { _ ! PoisonPill }
|
||||
keep
|
||||
}
|
||||
|
||||
case _ => _delegates //No change
|
||||
}
|
||||
|
||||
_lastCapacityChange = requestedCapacity
|
||||
_delegates = newDelegates
|
||||
}
|
||||
|
||||
private def _select() = select(_delegates) match {
|
||||
case (delegates, count) =>
|
||||
_lastSelectorCount = count
|
||||
delegates
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue