diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/actors/scala/actors/Actor.scala | 30 | ||||
-rw-r--r-- | src/actors/scala/actors/Reactor.scala | 31 |
2 files changed, 37 insertions, 24 deletions
diff --git a/src/actors/scala/actors/Actor.scala b/src/actors/scala/actors/Actor.scala index 988e7dda6c..8caa624f67 100644 --- a/src/actors/scala/actors/Actor.scala +++ b/src/actors/scala/actors/Actor.scala @@ -622,24 +622,22 @@ trait Actor extends AbstractActor with ReplyReactor with ActorCanReply with Inpu _state == Actor.State.Terminated } - override def start(): Actor = synchronized { - if (_state == Actor.State.New) { - _state = Actor.State.Runnable - - // Reset various flags. - // - // Note that we do *not* reset `trapExit`. The reason is that - // users should be able to set the field in the constructor - // and before `act` is called. - exitReason = 'normal - shouldExit = false + // guarded by this + private[actors] override def dostart() { + // Reset various flags. + // + // Note that we do *not* reset `trapExit`. The reason is that + // users should be able to set the field in the constructor + // and before `act` is called. + exitReason = 'normal + shouldExit = false - scheduler newActor this - scheduler execute (new Reaction(this)) + super.dostart() + } - this - } else - this + override def start(): Actor = synchronized { + super.start() + this } override def getState: Actor.State.Value = synchronized { diff --git a/src/actors/scala/actors/Reactor.scala b/src/actors/scala/actors/Reactor.scala index b5b9080c27..1c1dfdbd7a 100644 --- a/src/actors/scala/actors/Reactor.scala +++ b/src/actors/scala/actors/Reactor.scala @@ -215,17 +215,32 @@ trait Reactor[Msg >: Null] extends OutputChannel[Msg] with Combinators { scheduler executeFromActor makeReaction(null, handler, msg) } + // guarded by this + private[actors] def dostart() { + _state = Actor.State.Runnable + scheduler newActor this + scheduler execute makeReaction(() => act(), null, null) + } + /** - * Starts this $actor. + * Starts this $actor. This method is idempotent. */ def start(): Reactor[Msg] = synchronized { - if (_state == Actor.State.New) { - _state = Actor.State.Runnable - scheduler newActor this - scheduler execute makeReaction(() => act()) - this - } else - this + if (_state == Actor.State.New) + dostart() + this + } + + /** + * Restarts this $actor. + * + * @throws java.lang.IllegalStateException if the $actor is not in state `Actor.State.Terminated` + */ + def restart(): Unit = synchronized { + if (_state == Actor.State.Terminated) + dostart() + else + throw new IllegalStateException("restart only in state "+Actor.State.Terminated) } /** Returns the execution state of this $actor. |