summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2009-07-21 16:20:16 +0000
committerPhilipp Haller <hallerp@gmail.com>2009-07-21 16:20:16 +0000
commit9e896451708d850d5bc3b3d27d169f09aece912b (patch)
treefcc664a42231efe7f54c04911f515ebe8772e008
parent64342a3d920ea055739f94d1f10119bcfeabd12e (diff)
downloadscala-9e896451708d850d5bc3b3d27d169f09aece912b.tar.gz
scala-9e896451708d850d5bc3b3d27d169f09aece912b.tar.bz2
scala-9e896451708d850d5bc3b3d27d169f09aece912b.zip
Made Replyable more general.
-rw-r--r--src/actors/scala/actors/AbstractReactor.scala21
-rw-r--r--src/actors/scala/actors/OutputChannel.scala2
-rw-r--r--src/actors/scala/actors/Replyable.scala8
-rw-r--r--src/actors/scala/actors/ReplyableActor.scala4
-rw-r--r--src/actors/scala/actors/ReplyableReactor.scala4
-rw-r--r--src/actors/scala/actors/remote/Proxy.scala4
6 files changed, 33 insertions, 10 deletions
diff --git a/src/actors/scala/actors/AbstractReactor.scala b/src/actors/scala/actors/AbstractReactor.scala
new file mode 100644
index 0000000000..602639cbf6
--- /dev/null
+++ b/src/actors/scala/actors/AbstractReactor.scala
@@ -0,0 +1,21 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2005-2009, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id$
+
+package scala.actors
+
+trait AbstractReactor[-T] {
+
+ /**
+ * Sends <code>msg</code> to this
+ * <code>AbstractReactor</code> (asynchronous).
+ */
+ def !(msg: T): Unit
+
+}
diff --git a/src/actors/scala/actors/OutputChannel.scala b/src/actors/scala/actors/OutputChannel.scala
index 261ef56359..92bd12a55b 100644
--- a/src/actors/scala/actors/OutputChannel.scala
+++ b/src/actors/scala/actors/OutputChannel.scala
@@ -17,7 +17,7 @@ package scala.actors
* @version 0.9.17
* @author Philipp Haller
*/
-trait OutputChannel[-Msg] {
+trait OutputChannel[-Msg] extends AbstractReactor[Msg] {
/**
* Sends <code>msg</code> to this
diff --git a/src/actors/scala/actors/Replyable.scala b/src/actors/scala/actors/Replyable.scala
index 330b16461d..99c65d29f3 100644
--- a/src/actors/scala/actors/Replyable.scala
+++ b/src/actors/scala/actors/Replyable.scala
@@ -16,7 +16,7 @@ package scala.actors
*
* @author Philipp Haller
*/
-trait Replyable[T, R] {
+trait Replyable[-T, +R] {
/**
* Sends <code>msg</code> to this Replyable and awaits reply
@@ -45,7 +45,8 @@ trait Replyable[T, R] {
* @param msg the message to be sent
* @return the future
*/
- def !!(msg: T): Future[R]
+ def !!(msg: T): (() => R) =
+ () => this !? msg
/**
* Sends <code>msg</code> to this actor and immediately
@@ -58,6 +59,7 @@ trait Replyable[T, R] {
* @param f the function to be applied to the response
* @return the future
*/
- def !![P](msg: T, f: PartialFunction[R, P]): Future[P]
+ def !![P](msg: T, f: PartialFunction[R, P]): (() => P) =
+ () => f(this !? msg)
}
diff --git a/src/actors/scala/actors/ReplyableActor.scala b/src/actors/scala/actors/ReplyableActor.scala
index b9576a837b..709bb0ef98 100644
--- a/src/actors/scala/actors/ReplyableActor.scala
+++ b/src/actors/scala/actors/ReplyableActor.scala
@@ -47,12 +47,12 @@ trait ReplyableActor extends ReplyableReactor {
// should never be invoked; return dummy value
def !?(msec: Long, msg: Any): Option[Any] = Some(msg)
// should never be invoked; return dummy value
- def !!(msg: Any): Future[Any] = {
+ override def !!(msg: Any): Future[Any] = {
val someChan = new Channel[Any](Actor.self(thiz.scheduler))
Futures.fromInputChannel(someChan)
}
// should never be invoked; return dummy value
- def !![A](msg: Any, f: PartialFunction[Any, A]): Future[A] = {
+ override def !![A](msg: Any, f: PartialFunction[Any, A]): Future[A] = {
val someChan = new Channel[A](Actor.self(thiz.scheduler))
Futures.fromInputChannel(someChan)
}
diff --git a/src/actors/scala/actors/ReplyableReactor.scala b/src/actors/scala/actors/ReplyableReactor.scala
index 1f7c774f4a..cc2519e3ee 100644
--- a/src/actors/scala/actors/ReplyableReactor.scala
+++ b/src/actors/scala/actors/ReplyableReactor.scala
@@ -57,7 +57,7 @@ trait ReplyableReactor extends Replyable[Any, Any] {
* Sends <code>msg</code> to this actor and immediately
* returns a future representing the reply value.
*/
- def !!(msg: Any): Future[Any] = {
+ override def !!(msg: Any): Future[Any] = {
val ftch = new Channel[Any](Actor.rawSelf(thiz.scheduler))
thiz.send(msg, ftch)
Futures.fromInputChannel(ftch)
@@ -70,7 +70,7 @@ trait ReplyableReactor extends Replyable[Any, Any] {
* <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] = {
+ override def !![A](msg: Any, f: PartialFunction[Any, A]): Future[A] = {
val ftch = new Channel[A](Actor.rawSelf(thiz.scheduler))
thiz.send(msg, new OutputChannel[Any] {
def !(msg: Any) =
diff --git a/src/actors/scala/actors/remote/Proxy.scala b/src/actors/scala/actors/remote/Proxy.scala
index 1c7e6f4e55..dca3c55bdb 100644
--- a/src/actors/scala/actors/remote/Proxy.scala
+++ b/src/actors/scala/actors/remote/Proxy.scala
@@ -63,10 +63,10 @@ private[remote] class Proxy(node: Node, name: Symbol, @transient var kernel: Net
def !?(msec: Long, msg: Any): Option[Any] =
del !? (msec, msg)
- def !!(msg: Any): Future[Any] =
+ override def !!(msg: Any): Future[Any] =
del !! msg
- def !![A](msg: Any, f: PartialFunction[Any, A]): Future[A] =
+ override def !![A](msg: Any, f: PartialFunction[Any, A]): Future[A] =
del !! (msg, f)
def linkTo(to: AbstractActor): Unit =