summaryrefslogtreecommitdiff
path: root/src/actors
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2007-07-09 13:54:02 +0000
committerPhilipp Haller <hallerp@gmail.com>2007-07-09 13:54:02 +0000
commit2e35175f47552ea19d466e8d31153ecc7a4c894f (patch)
tree94ae3e2e4571a83d2828dac91417b4656527ff6d /src/actors
parent4e9b6b48a7c1105f5651df8e853abcb28d591a71 (diff)
downloadscala-2e35175f47552ea19d466e8d31153ecc7a4c894f.tar.gz
scala-2e35175f47552ea19d466e8d31153ecc7a4c894f.tar.bz2
scala-2e35175f47552ea19d466e8d31153ecc7a4c894f.zip
Unified sender and reply destination.
Diffstat (limited to 'src/actors')
-rw-r--r--src/actors/scala/actors/Actor.scala45
-rw-r--r--src/actors/scala/actors/Channel.scala14
-rw-r--r--src/actors/scala/actors/MessageQueue.scala4
3 files changed, 34 insertions, 29 deletions
diff --git a/src/actors/scala/actors/Actor.scala b/src/actors/scala/actors/Actor.scala
index 2d5e97433f..90ebfe7b14 100644
--- a/src/actors/scala/actors/Actor.scala
+++ b/src/actors/scala/actors/Actor.scala
@@ -152,7 +152,7 @@ object Actor {
/**
* Returns the actor which sent the last received message.
*/
- def sender: Actor = self.sender
+ def sender: OutputChannel[Any] = self.sender
/**
* Send <code>msg</code> to the actor waiting in a call to
@@ -275,10 +275,10 @@ trait Actor extends OutputChannel[Any] {
private[actors] var isSuspended = false
private val mailbox = new MessageQueue
- private[actors] var sessions: List[Channel[Any]] = Nil
- private var session1: Option[Channel[Any]] = None
+ private[actors] var sessions: List[OutputChannel[Any]] = Nil
+ private var session1: Option[OutputChannel[Any]] = None
- private def send(msg: Any, session: Channel[Any]) = synchronized {
+ private[actors] def send(msg: Any, session: OutputChannel[Any]) = synchronized {
tick()
if (waitingFor(msg)) {
received = Some(msg)
@@ -425,22 +425,24 @@ trait Actor extends OutputChannel[Any] {
* Sends <code>msg</code> to this actor (asynchronous).
*/
def !(msg: Any) {
- send(msg, Actor.self.getReplyChannel)
+ send(msg, Actor.self)
}
/**
* Forwards <code>msg</code> to this actor (asynchronous).
*/
- def forward(msg: Any): Unit = send(msg, Actor.sender.getReplyChannel)
+ def forward(msg: Any) {
+ send(msg, Actor.sender)
+ }
/**
* Sends <code>msg</code> to this actor and awaits reply
* (synchronous).
*/
def !?(msg: Any): Any = {
- val replyChannel = Actor.self.freshReply()
- this ! msg
- replyChannel.receive {
+ val replyCh = new Channel[Any](Actor.self)
+ send(msg, replyCh)
+ replyCh.receive {
case x => x
}
}
@@ -453,9 +455,9 @@ trait Actor extends OutputChannel[Any] {
* <code>value</code> is the reply value.
*/
def !?(msec: Long, msg: Any): Option[Any] = {
- val replyChannel = Actor.self.freshReply()
- this ! msg
- replyChannel.receiveWithin(msec) {
+ val replyCh = new Channel[Any](Actor.self)
+ send(msg, replyCh)
+ replyCh.receiveWithin(msec) {
case TIMEOUT => None
case x => Some(x)
}
@@ -511,14 +513,15 @@ trait Actor extends OutputChannel[Any] {
}
/**
- * Replies with <code>msg</code> to the sender waiting in
- * a synchronous send.
+ * Replies with <code>msg</code> to the sender.
*/
- def reply(msg: Any): Unit = session ! msg
+ def reply(msg: Any) {
+ sender ! msg
+ }
- private var rc = new Channel[Any](this)
- def getReplyChannel = rc
- def freshReply() = { rc = new Channel[Any]; rc }
+ //private var rc = new Channel[Any](this)
+ //def getReplyChannel = rc
+ //def freshReply() = { rc = new Channel[Any]; rc }
/**
* Receives the next message from this actor's mailbox.
@@ -527,19 +530,21 @@ trait Actor extends OutputChannel[Any] {
case x => x
}
+/*
def sender: Actor = {
val s = session
if (null ne s) s.receiver
else null
}
+*/
- private[actors] def session: Channel[Any] =
+ def sender: OutputChannel[Any] =
if (sessions.isEmpty) {
session1 match {
case None => null
case Some(s) => s
}
- } else sessions.head.asInstanceOf[Channel[Any]]
+ } else sessions.head//.asInstanceOf[OutputChannel[Any]]
private[actors] var continuation: PartialFunction[Any, Unit] = null
private[actors] var timeoutPending = false
diff --git a/src/actors/scala/actors/Channel.scala b/src/actors/scala/actors/Channel.scala
index a11545cd5d..e3db8dc8ac 100644
--- a/src/actors/scala/actors/Channel.scala
+++ b/src/actors/scala/actors/Channel.scala
@@ -28,7 +28,7 @@ package scala.actors
* @version 0.9.6
* @author Philipp Haller
*/
-case class ! [a](ch: InputChannel[a], msg: a)
+case class ! [a](ch: Channel[a], msg: a)
/**
* This class provides a means for typed communication among
@@ -137,9 +137,9 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] {
* @return the reply
*/
def !?(msg: Msg): Any = {
- val replyChannel = Actor.self.freshReply()
- receiver ! scala.actors.!(this, msg)
- replyChannel.receive {
+ val replyCh = new Channel[Any](Actor.self)
+ receiver.send(scala.actors.!(this, msg), replyCh)
+ replyCh.receive {
case x => x
}
}
@@ -154,9 +154,9 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] {
* <code>Some(x)</code> where <code>x</code> is the reply
*/
def !?(msec: Long, msg: Msg): Option[Any] = {
- val replyChannel = Actor.self.freshReply()
- receiver ! scala.actors.!(this, msg)
- replyChannel.receiveWithin(msec) {
+ val replyCh = new Channel[Any](Actor.self)
+ receiver.send(scala.actors.!(this, msg), replyCh)
+ replyCh.receiveWithin(msec) {
case TIMEOUT => None
case x => Some(x)
}
diff --git a/src/actors/scala/actors/MessageQueue.scala b/src/actors/scala/actors/MessageQueue.scala
index 51644f4471..b5f556e177 100644
--- a/src/actors/scala/actors/MessageQueue.scala
+++ b/src/actors/scala/actors/MessageQueue.scala
@@ -10,7 +10,7 @@ package scala.actors
*/
class MessageQueueElement {
var msg: Any = _
- var session: Channel[Any] = null
+ var session: OutputChannel[Any] = null
var next: MessageQueueElement = null
}
@@ -28,7 +28,7 @@ class MessageQueue {
// last == null iff list empty
var last: MessageQueueElement = null
- def append(msg: Any, session: Channel[Any]) = {
+ def append(msg: Any, session: OutputChannel[Any]) = {
if (null eq last) { // list empty
val el = new MessageQueueElement
el.msg = msg