This commit is contained in:
Viktor Klang 2010-11-11 18:19:45 +01:00
parent a89f79a7b4
commit 8c2ed8bd03
2 changed files with 14 additions and 2 deletions

View file

@ -413,8 +413,14 @@ trait Actor extends Logging {
/**
* Changes tha Actor's behavior to become the new 'Receive' (PartialFunction[Any, Unit]) handler.
* Puts the behavior on top of the hotswap stack.
* If "discardOld" is true, an unbecome will be issued prior to pushing the new behavior to the stack
*/
def become(behavior: Receive): Unit = self.hotswap = self.hotswap.push(behavior)
def become(behavior: Receive, discardOld: Boolean = false) {
if (discardOld)
unbecome
self.hotswap = self.hotswap.push(behavior)
}
/**
* Reverts the Actor behavior to the previous one in the hotswap stack.

View file

@ -72,7 +72,13 @@ abstract class UntypedActor extends Actor {
/**
* Java API for become
*/
def become(behavior: Procedure[Any]): Unit = super.become { case msg => behavior.apply(msg) }
def become(behavior: Procedure[Any]):Unit = become(behavior,false)
/*
* Java API for become with optional discardOld
*/
def become(behavior: Procedure[Any], discardOld: Boolean): Unit =
super.become({ case msg => behavior.apply(msg) }, discardOld)
@throws(classOf[Exception])
def onReceive(message: Any): Unit