From 9e896451708d850d5bc3b3d27d169f09aece912b Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Tue, 21 Jul 2009 16:20:16 +0000 Subject: Made Replyable more general. --- src/actors/scala/actors/AbstractReactor.scala | 21 +++++++++++++++++++++ src/actors/scala/actors/OutputChannel.scala | 2 +- src/actors/scala/actors/Replyable.scala | 8 +++++--- src/actors/scala/actors/ReplyableActor.scala | 4 ++-- src/actors/scala/actors/ReplyableReactor.scala | 4 ++-- src/actors/scala/actors/remote/Proxy.scala | 4 ++-- 6 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 src/actors/scala/actors/AbstractReactor.scala (limited to 'src/actors') 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 msg to this + * AbstractReactor (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 msg 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 msg 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 msg 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 msg 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] { * f. 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 = -- cgit v1.2.3