Moving all the logic for cleaning up mailboxes into the mailbox implementation itself

This commit is contained in:
Viktor Klang 2011-12-07 15:51:46 +01:00
parent bf3ce9bb87
commit 72d69cb7cc
3 changed files with 37 additions and 41 deletions

View file

@ -168,36 +168,9 @@ abstract class MessageDispatcher(val prerequisites: DispatcherPrerequisites) ext
val mailBox = actor.mailbox
mailBox.becomeClosed() // FIXME reschedule in tell if possible race with cleanUp is detected in order to properly clean up
actor.mailbox = deadLetterMailbox
cleanUpMailboxFor(actor, mailBox)
mailBox.cleanUp()
}
/**
* Overridable callback to clean up the mailbox for a given actor,
* called when an actor is unregistered.
*/
protected def cleanUpMailboxFor(actor: ActorCell, mailBox: Mailbox) {
if (mailBox.hasSystemMessages) {
var message = mailBox.systemDrain()
while (message ne null) {
// message must be virgin before being able to systemEnqueue again
val next = message.next
message.next = null
deadLetterMailbox.systemEnqueue(actor.self, message)
message = next
}
}
if (mailBox.hasMessages) {
var envelope = mailBox.dequeue
while (envelope ne null) {
deadLetterMailbox.enqueue(actor.self, envelope)
envelope = mailBox.dequeue
}
}
}
private val shutdownAction = new Runnable {
@tailrec
final def run() {