diff options
author | Philipp Haller <hallerp@gmail.com> | 2006-11-14 10:09:35 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2006-11-14 10:09:35 +0000 |
commit | d0dd6b7eee6bf0321fd39d43ececb54fe8761334 (patch) | |
tree | 735d19d73f00dadd3c4e18b6afc6410af6b51bfc /src/actors | |
parent | 8e2cb2b07a2fa55055afd5d85143ccc2a7adbebf (diff) | |
download | scala-d0dd6b7eee6bf0321fd39d43ececb54fe8761334.tar.gz scala-d0dd6b7eee6bf0321fd39d43ececb54fe8761334.tar.bz2 scala-d0dd6b7eee6bf0321fd39d43ececb54fe8761334.zip |
Small refactoring of Reaction.
Diffstat (limited to 'src/actors')
-rw-r--r-- | src/actors/scala/actors/Actor.scala | 8 | ||||
-rw-r--r-- | src/actors/scala/actors/Reaction.scala | 80 | ||||
-rw-r--r-- | src/actors/scala/actors/Scheduler.scala | 5 |
3 files changed, 22 insertions, 71 deletions
diff --git a/src/actors/scala/actors/Actor.scala b/src/actors/scala/actors/Actor.scala index 3efa508d65..6484f3f454 100644 --- a/src/actors/scala/actors/Actor.scala +++ b/src/actors/scala/actors/Actor.scala @@ -368,9 +368,9 @@ trait Actor extends OutputChannel[Any] { // do nothing (timeout is handled instead) } else { - val task = new ActorTask(this, - if (f eq null) continuation else f, - msg) + val task = new Reaction(this, + if (f eq null) continuation else f, + msg) Scheduler.execute(task) } @@ -447,7 +447,7 @@ trait Actor extends OutputChannel[Any] { * Starts this reactor. */ def start(): Unit = - Scheduler.execute(new StartTask(this)) + Scheduler.execute(new Reaction(this)) private val links = new HashSet[Actor] diff --git a/src/actors/scala/actors/Reaction.scala b/src/actors/scala/actors/Reaction.scala index 4ee0a6a11e..fb9064989f 100644 --- a/src/actors/scala/actors/Reaction.scala +++ b/src/actors/scala/actors/Reaction.scala @@ -15,17 +15,19 @@ import java.lang.{InterruptedException, Runnable} import java.util.logging.{Level, Logger} /** - * The abstract class <code>Reaction</code> associates an instance - * of an <code>Actor</code> with a - * <code>java.lang.Runnable</code>. It is also the super class of - * the different kinds of tasks used for the execution of - * event-based <code>Actor</code>s. + * The abstract class <code>Reaction</code> associates + * an instance of an <code>Actor</code> with a + * <code>java.lang.Runnable</code>. * * @version 0.9.0 * @author Philipp Haller */ -private[actors] abstract class Reaction extends Runnable { - def actor: Actor +private[actors] class Reaction(a: Actor, + f: PartialFunction[Any, Unit], + msg: Any) extends Runnable { + def this(a: Actor) = this(a, null, null) + + def actor = a /** * @param t ... @@ -42,17 +44,6 @@ private[actors] abstract class Reaction extends Runnable { } logger.log(Level.FINE, buf.toString()) } -} - -/** - * This class represents task items used to start the execution - * of <code>Actor</code>s. - * - * @version 0.9.0 - * @author Philipp Haller - */ -private[actors] class StartTask(a: Actor) extends Reaction { - def actor = a def run(): Unit = { val t = currentThread @@ -60,58 +51,19 @@ private[actors] class StartTask(a: Actor) extends Reaction { Actor.selfs.put(t, a) Scheduler.unPendReaction try { - a.act() - if (currentThread.isInterrupted()) - throw new InterruptedException - a.kill() - if (currentThread.isInterrupted()) - throw new InterruptedException - a.exit("normal") - } - catch { - case ie: InterruptedException => { - log(ie) - a.exitLinked() - } - case d: SuspendActorException => { - // do nothing (continuation is already saved) - } - case t: Throwable => { - log(t) - a.exit(t.toString()) - } - } - finally { - Actor.selfs.put(t, saved) - } - } -} + if (f == null) + a.act() + else + f(msg) -/** - * This class represents task items used to execute actions - * specified in arguments of <code>react</code> and - * <code>reactWithin</code>. - * - * @version 0.9.0 - * @author Philipp Haller - */ -private[actors] class ActorTask(a: Actor, - f: PartialFunction[Any, Unit], - msg: Any) extends Reaction { - def actor = a - - def run(): Unit = { - val t = currentThread - val saved = Actor.selfs.get(t).asInstanceOf[Actor] - Actor.selfs.put(t, a) - Scheduler.unPendReaction - try { - f(msg) if (currentThread.isInterrupted()) throw new InterruptedException + a.kill() + if (currentThread.isInterrupted()) throw new InterruptedException + a.exit("normal") } catch { diff --git a/src/actors/scala/actors/Scheduler.scala b/src/actors/scala/actors/Scheduler.scala index ca1a3ddcf6..2f4c2827c6 100644 --- a/src/actors/scala/actors/Scheduler.scala +++ b/src/actors/scala/actors/Scheduler.scala @@ -68,9 +68,8 @@ trait IScheduler { def shutdown(): unit - val QUIT_TASK = new Reaction() { - def actor: Actor = null - def run(): unit = {} + val QUIT_TASK = new Reaction(null) { + override def run(): unit = {} override def toString() = "QUIT_TASK" } |