diff options
author | Philipp Haller <hallerp@gmail.com> | 2007-02-04 19:00:53 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2007-02-04 19:00:53 +0000 |
commit | 39d6b1f81e3ddfe39ee8605cacf3b2c4b343bf94 (patch) | |
tree | 659505f9b0a517cab8e06849d8dbe5847560245d | |
parent | 100951d18780675748fdc548a60fd5df629d8aba (diff) | |
download | scala-39d6b1f81e3ddfe39ee8605cacf3b2c4b343bf94.tar.gz scala-39d6b1f81e3ddfe39ee8605cacf3b2c4b343bf94.tar.bz2 scala-39d6b1f81e3ddfe39ee8605cacf3b2c4b343bf94.zip |
scala.actors: removed Exit class.
-rw-r--r-- | src/actors/scala/actors/Actor.scala | 53 | ||||
-rw-r--r-- | src/actors/scala/actors/ActorProxy.scala | 6 | ||||
-rw-r--r-- | src/actors/scala/actors/Reaction.scala | 4 | ||||
-rw-r--r-- | src/actors/scala/actors/remote/TcpService.scala | 6 |
4 files changed, 36 insertions, 33 deletions
diff --git a/src/actors/scala/actors/Actor.scala b/src/actors/scala/actors/Actor.scala index c4ebeef27b..fb2978ec9f 100644 --- a/src/actors/scala/actors/Actor.scala +++ b/src/actors/scala/actors/Actor.scala @@ -239,16 +239,16 @@ object Actor { * <p> * For each linked actor <code>a</code> with * <code>trapExit</code> set to <code>true</code>, send message - * <code>Exit(self, reason)</code> to <code>a</code>. + * <code>{'EXIT, self, reason}</code> to <code>a</code>. * </p> * <p> * For each linked actor <code>a</code> with * <code>trapExit</code> set to <code>false</code> (default), * call <code>a.exit(reason)</code> if - * <code>!reason.equals("normal")</code>. + * <code>reason != 'normal</code>. * </p> */ - def exit(reason: String): Nothing = self.exit(reason) + def exit(reason: AnyRef): Nothing = self.exit(reason) } /** @@ -569,7 +569,7 @@ trait Actor extends OutputChannel[Any] { } var trapExit = false - private[actors] var exitReason: String = "normal" + private[actors] var exitReason: AnyRef = 'normal private[actors] var exiting = false private[actors] var shouldExit = false @@ -581,17 +581,17 @@ trait Actor extends OutputChannel[Any] { * <p> * For each linked actor <code>a</code> with * <code>trapExit</code> set to <code>true</code>, send message - * <code>Exit(self, reason)</code> to <code>a</code>. + * <code>{'EXIT, self, reason}</code> to <code>a</code>. * </p> * <p> * For each linked actor <code>a</code> with * <code>trapExit</code> set to <code>false</code> (default), * call <code>a.exit(reason)</code> if - * <code>!reason.equals("normal")</code>. + * <code>reason != 'normal</code>. * </p> */ - def exit(reason: String): Nothing = { - if (reason.equals("normal")) kill() + def exit(reason: AnyRef): Nothing = { + if (reason == 'normal) kill() // links if (!links.isEmpty) { exitReason = reason @@ -600,7 +600,7 @@ trait Actor extends OutputChannel[Any] { throw new ExitActorException } - def exit(): Nothing = exit("normal") + def exit(): Nothing = exit('normal) // Assume !links.isEmpty private[actors] def exitLinked() { @@ -615,11 +615,26 @@ trait Actor extends OutputChannel[Any] { }) } + // Assume !links.isEmpty + private[actors] def exitLinked(reason: AnyRef) { + exitReason = reason + exiting = true + // remove this from links + links = links.remove(this.==) + // exit linked processes + links.foreach((linked: Actor) => { + unlink(linked) + if (!linked.exiting) + linked.exit(this, exitReason) + }) + } + // Assume !this.exiting - private[actors] def exit(from: Actor, reason: String) { - if (trapExit) - this ! Exit(from, reason) - else if (!reason.equals("normal")) + private[actors] def exit(from: Actor, reason: AnyRef) { + if (trapExit) { + this ! {'EXIT, from, reason} + } + else if (reason != 'normal) this.synchronized { shouldExit = true exitReason = reason @@ -634,18 +649,6 @@ trait Actor extends OutputChannel[Any] { /** - * Messages of this type are sent to each actor <code>a</code> - * that is linked to an actor <code>b</code> whenever - * <code>b</code> terminates and <code>a</code> has - * <code>trapExit</code> set to <code>true</code>. - * - * @version 0.9.2 - * @author Philipp Haller - */ -case class Exit(from: Actor, reason: String) - - -/** * <p>This object is used as the timeout pattern in * <code>receiveWithin</code> and <code>reactWithin</code>. * </p> diff --git a/src/actors/scala/actors/ActorProxy.scala b/src/actors/scala/actors/ActorProxy.scala index d0fb23d83b..0903e3daf2 100644 --- a/src/actors/scala/actors/ActorProxy.scala +++ b/src/actors/scala/actors/ActorProxy.scala @@ -33,18 +33,18 @@ private[actors] class ActorProxy(t: Thread) extends Actor { * <p> * For each linked actor <code>a</code> with * <code>trapExit</code> set to <code>true</code>, send message - * <code>Exit(self, reason)</code> to <code>a</code>. + * <code>{'EXIT, self, reason}</code> to <code>a</code>. * </p> * <p> * For each linked actor <code>a</code> with * <code>trapExit</code> set to <code>false</code> (default), * call <code>a.exit(reason)</code> if - * <code>!reason.equals("normal")</code>. + * <code>reason != 'normal</code>. * </p> * * @param reason the exit reason of the interrupted thread. */ - override def exit(reason: String): Nothing = { + override def exit(reason: AnyRef): Nothing = { kill() // links if (!links.isEmpty) { diff --git a/src/actors/scala/actors/Reaction.scala b/src/actors/scala/actors/Reaction.scala index fd3f8df0e9..931d2cd17b 100644 --- a/src/actors/scala/actors/Reaction.scala +++ b/src/actors/scala/actors/Reaction.scala @@ -67,10 +67,10 @@ private[actors] class Reaction(a: Actor, case _: SuspendActorException => { // do nothing (continuation is already saved) } - case _: Throwable => { + case t: Throwable => { // links if (!a.links.isEmpty) { - a.exitLinked() + a.exitLinked(t) } } } diff --git a/src/actors/scala/actors/remote/TcpService.scala b/src/actors/scala/actors/remote/TcpService.scala index 09fb80a80b..d17f072ecc 100644 --- a/src/actors/scala/actors/remote/TcpService.scala +++ b/src/actors/scala/actors/remote/TcpService.scala @@ -12,8 +12,7 @@ package scala.actors.remote -import java.lang.Thread -import java.lang.SecurityException +import java.lang.{Thread, SecurityException} import java.io.{BufferedReader, DataInputStream, DataOutputStream, IOException, InputStreamReader, OutputStreamWriter, @@ -34,7 +33,8 @@ object TcpService { } catch { case ioe: IOException => - // this happens when trying to open a socket twice at the same port + // this happens when trying to open a socket twice + // at the same port // try again generatePort case se: SecurityException => |