From 5e12bab4777dc63711834cd39bf8514fb7e8da40 Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Tue, 26 May 2009 16:11:57 +0000 Subject: Fixed #1794. --- src/actors/scala/actors/Channel.scala | 36 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 23 deletions(-) (limited to 'src/actors') diff --git a/src/actors/scala/actors/Channel.scala b/src/actors/scala/actors/Channel.scala index da41318138..93525dddbd 100644 --- a/src/actors/scala/actors/Channel.scala +++ b/src/actors/scala/actors/Channel.scala @@ -38,19 +38,9 @@ case class ! [a](ch: Channel[a], msg: a) * @version 0.9.17 * @author Philipp Haller */ -class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] { +class Channel[Msg](val receiver: Actor) extends InputChannel[Msg] with OutputChannel[Msg] { - private var recv: Actor = { - // basically Actor.self, but can be null - Actor.tl.get.asInstanceOf[Actor] - } - - def receiver: Actor = recv - - def this(recv: Actor) = { - this() - this.recv = recv - } + def this() = this(Actor.self) /** * Sends a message to this Channel. @@ -58,7 +48,7 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] { * @param msg the message to be sent */ def !(msg: Msg) { - recv ! scala.actors.!(this, msg) + receiver ! scala.actors.!(this, msg) } /** @@ -69,7 +59,7 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] { * @param replyTo the reply destination */ def send(msg: Msg, replyTo: OutputChannel[Any]) { - recv.send(scala.actors.!(this, msg), replyTo) + receiver.send(scala.actors.!(this, msg), replyTo) } /** @@ -77,7 +67,7 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] { * last sender as sender instead of self. */ def forward(msg: Msg) { - recv forward scala.actors.!(this, msg) + receiver forward scala.actors.!(this, msg) } /** @@ -88,7 +78,7 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] { */ def receive[R](f: PartialFunction[Msg, R]): R = { val C = this.asInstanceOf[Channel[Any]] - recv.receive { + receiver.receive { case C ! msg if (f.isDefinedAt(msg.asInstanceOf[Msg])) => f(msg.asInstanceOf[Msg]) } } @@ -110,7 +100,7 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] { */ def receiveWithin[R](msec: Long)(f: PartialFunction[Any, R]): R = { val C = this.asInstanceOf[Channel[Any]] - recv.receiveWithin(msec) { + receiver.receiveWithin(msec) { case C ! msg if (f.isDefinedAt(msg)) => f(msg) case TIMEOUT => f(TIMEOUT) } @@ -126,7 +116,7 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] { */ def react(f: PartialFunction[Msg, Unit]): Nothing = { val C = this.asInstanceOf[Channel[Any]] - recv.react { + receiver.react { case C ! msg if (f.isDefinedAt(msg.asInstanceOf[Msg])) => f(msg.asInstanceOf[Msg]) } } @@ -143,7 +133,7 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] { */ def reactWithin(msec: Long)(f: PartialFunction[Any, Unit]): Nothing = { val C = this.asInstanceOf[Channel[Any]] - recv.reactWithin(msec) { + receiver.reactWithin(msec) { case C ! msg if (f.isDefinedAt(msg)) => f(msg) case TIMEOUT => f(TIMEOUT) } @@ -157,8 +147,8 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] { * @return the reply */ def !?(msg: Msg): Any = { - val replyCh = new Channel[Any](Actor.self(recv.scheduler)) - recv.send(scala.actors.!(this, msg), replyCh) + val replyCh = new Channel[Any](Actor.self(receiver.scheduler)) + receiver.send(scala.actors.!(this, msg), replyCh) replyCh.receive { case x => x } @@ -174,8 +164,8 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] { * Some(x) where x is the reply */ def !?(msec: Long, msg: Msg): Option[Any] = { - val replyCh = new Channel[Any](Actor.self(recv.scheduler)) - recv.send(scala.actors.!(this, msg), replyCh) + val replyCh = new Channel[Any](Actor.self(receiver.scheduler)) + receiver.send(scala.actors.!(this, msg), replyCh) replyCh.receiveWithin(msec) { case TIMEOUT => None case x => Some(x) -- cgit v1.2.3