summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2010-05-25 14:58:42 +0000
committerPhilipp Haller <hallerp@gmail.com>2010-05-25 14:58:42 +0000
commit4b10a4ca64f3d96a33a7f7badbf2a74e1c176fc4 (patch)
tree52b5047b7cfb01993c5ab674ab0520ef9da6ce3c /src
parent5628970b43eefcd892320941ea6f937a7ce09b6a (diff)
downloadscala-4b10a4ca64f3d96a33a7f7badbf2a74e1c176fc4.tar.gz
scala-4b10a4ca64f3d96a33a7f7badbf2a74e1c176fc4.tar.bz2
scala-4b10a4ca64f3d96a33a7f7badbf2a74e1c176fc4.zip
Addresses see #3470 by adding a method Reactor....
Addresses see #3470 by adding a method Reactor.restart. Review by rompf.
Diffstat (limited to 'src')
-rw-r--r--src/actors/scala/actors/Actor.scala30
-rw-r--r--src/actors/scala/actors/Reactor.scala31
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.