summaryrefslogtreecommitdiff
path: root/src/actors
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2007-03-08 10:06:20 +0000
committerPhilipp Haller <hallerp@gmail.com>2007-03-08 10:06:20 +0000
commit5303be8340fa4f18962fd36757f9c143a0b105b8 (patch)
treed26aabcd36abda58a0426863b8f1ad758fdbf705 /src/actors
parenta41182e5fdbdf890f68ef0ff4b185c1cf5522016 (diff)
downloadscala-5303be8340fa4f18962fd36757f9c143a0b105b8.tar.gz
scala-5303be8340fa4f18962fd36757f9c143a0b105b8.tar.bz2
scala-5303be8340fa4f18962fd36757f9c143a0b105b8.zip
scala.actors: removed commented code
Diffstat (limited to 'src/actors')
-rw-r--r--src/actors/scala/actors/Actor.scala68
-rw-r--r--src/actors/scala/actors/Channel.scala1
-rw-r--r--src/actors/scala/actors/Reaction.scala10
3 files changed, 36 insertions, 43 deletions
diff --git a/src/actors/scala/actors/Actor.scala b/src/actors/scala/actors/Actor.scala
index 3524f8cdb5..d2098a2813 100644
--- a/src/actors/scala/actors/Actor.scala
+++ b/src/actors/scala/actors/Actor.scala
@@ -24,8 +24,6 @@ import scala.compat.Platform
*/
object Actor {
- //private[actors] val selfs = new java.util.WeakHashMap(16, 0.5f)
-
private[actors] val tl = new ThreadLocal
/**
@@ -42,13 +40,6 @@ object Actor {
tl.set(a)
}
a
- /*val t = currentThread
- var a = selfs.get(t).asInstanceOf[Actor]
- if (a eq null) {
- a = new ActorProxy(t)
- selfs.put(t, a)
- }
- a*/
}
/**
@@ -73,22 +64,6 @@ object Actor {
}
/**
- * Creates an instance of a thread-based actor specifying a
- * channel which can be used for typed communication with other
- * actors.
- */
-/*
- def actor[a](ch: Channel[a])(body: => Unit): Actor = synchronized {
- val actor = new Actor {
- def act() = body
- }
- ch.receiver = actor
- actor.start()
- actor
- }
-*/
-
- /**
* Receives the next message from the mailbox of the current actor
* <code>self</code>.
*/
@@ -302,8 +277,7 @@ trait Actor extends OutputChannel[Any] {
def receive[R](f: PartialFunction[Any, R]): R = {
assert(Actor.self == this, "receive from channel belonging to other actor")
- // links
- if (shouldExit) exit()
+ if (shouldExit) exit() // links
this.synchronized {
tick()
val qel = mailbox.extractFirst((m: Any) => f.isDefinedAt(m))
@@ -325,8 +299,7 @@ trait Actor extends OutputChannel[Any] {
def receiveWithin[R](msec: long)(f: PartialFunction[Any, R]): R = {
assert(Actor.self == this, "receive from channel belonging to other actor")
- // links
- if (shouldExit) exit()
+ if (shouldExit) exit() // links
this.synchronized {
tick()
// first, remove spurious TIMEOUT message from mailbox if any
@@ -370,8 +343,7 @@ trait Actor extends OutputChannel[Any] {
def react(f: PartialFunction[Any, Unit]): Nothing = {
assert(Actor.self == this, "react on channel belonging to other actor")
- // links
- if (shouldExit) exit()
+ if (shouldExit) exit() // links
Scheduler.pendReaction
this.synchronized {
tick()
@@ -390,8 +362,7 @@ trait Actor extends OutputChannel[Any] {
def reactWithin(msec: long)(f: PartialFunction[Any, Unit]): Nothing = {
assert(Actor.self == this, "react on channel belonging to other actor")
- // links
- if (shouldExit) exit()
+ if (shouldExit) exit() // links
Scheduler.pendReaction
this.synchronized {
tick()
@@ -428,6 +399,9 @@ trait Actor extends OutputChannel[Any] {
send(msg, Actor.self.getReplyChannel)
}
+ /**
+ * Forwards <code>msg</code> to this actor (asynchronous).
+ */
def forward(msg: Any): Unit = send(msg, Actor.sender.getReplyChannel)
/**
@@ -442,6 +416,13 @@ trait Actor extends OutputChannel[Any] {
}
}
+ /**
+ * Sends <code>msg</code> to this actor and awaits reply
+ * (synchronous) within <code>msec</code> milliseconds.
+ * When the timeout occurs, <code>None</code> is returned.
+ * Otherwise, returns <code>Some(value)</code> where
+ * <code>value</code> is the reply value.
+ */
def !?(msec: long, msg: Any): Option[Any] = {
val replyChannel = Actor.self.freshReply()
this ! msg
@@ -451,6 +432,10 @@ trait Actor extends OutputChannel[Any] {
}
}
+ /**
+ * Sends <code>msg</code> to this actor and immediately
+ * returns a future representing the reply value.
+ */
def !!(msg: Any): Future[Any] = {
val ftch = new Channel[Any](Actor.self)
send(msg, ftch)
@@ -470,6 +455,13 @@ trait Actor extends OutputChannel[Any] {
}
}
+ /**
+ * Sends <code>msg</code> to this actor and immediately
+ * returns a future representing the reply value.
+ * The reply is post-processed using the partial function
+ * <code>f</code>. This also allows to recover a more
+ * precise type for the reply value.
+ */
def !![a](msg: Any, f: PartialFunction[Any, a]): Future[a] = {
val ftch = new Channel[Any](Actor.self)
send(msg, ftch)
@@ -489,12 +481,19 @@ trait Actor extends OutputChannel[Any] {
}
}
+ /**
+ * Replies with <code>msg</code> to the sender waiting in
+ * a synchronous send.
+ */
def reply(msg: Any): Unit = session ! msg
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.
+ */
def ? : Any = receive {
case x => x
}
@@ -652,6 +651,9 @@ trait Actor extends OutputChannel[Any] {
throw new ExitActorException
}
+ /**
+ * Terminates with exit reason <code>'normal</code>.
+ */
def exit(): Nothing = exit('normal)
// Assume !links.isEmpty
diff --git a/src/actors/scala/actors/Channel.scala b/src/actors/scala/actors/Channel.scala
index 8031ea297e..cc2c351050 100644
--- a/src/actors/scala/actors/Channel.scala
+++ b/src/actors/scala/actors/Channel.scala
@@ -42,7 +42,6 @@ class Channel[Msg] extends InputChannel[Msg] with OutputChannel[Msg] {
private[actors] var receiver: Actor = synchronized {
// basically Actor.self, but can be null
- //Actor.selfs.get(currentThread).asInstanceOf[Actor]
Actor.tl.get.asInstanceOf[Actor]
}
diff --git a/src/actors/scala/actors/Reaction.scala b/src/actors/scala/actors/Reaction.scala
index a7d2ee47fb..0b9f33a98c 100644
--- a/src/actors/scala/actors/Reaction.scala
+++ b/src/actors/scala/actors/Reaction.scala
@@ -40,17 +40,13 @@ private[actors] class Reaction(a: Actor,
def actor = a
def run(): Unit = {
- /*val t = currentThread
- val saved = Actor.selfs.get(t).asInstanceOf[Actor]
- Actor.selfs.put(t, a)*/
val saved = Actor.tl.get.asInstanceOf[Actor]
Actor.tl.set(a)
Scheduler.unPendReaction
a.isDetached = false
try {
try {
- // links
- if (a.shouldExit)
+ if (a.shouldExit) // links
a.exit()
else {
if (f == null)
@@ -74,10 +70,6 @@ private[actors] class Reaction(a: Actor,
}
}
}
- /*finally {
- //Actor.selfs.put(t, saved)
- Actor.tl.set(saved)
- }*/
Actor.tl.set(saved)
}