Abstraction for unification of sender and senderFuture for later reply
abstract class Channel[T] = { def !(msg: T): Unit } def channel: Channel = { if (senderFuture.isDefined) { new Channel[Any] { val future = senderFuture.get def !(msg: Any) = future completeWithResult msg } } else if (sender.isDefined) { new Channel[Any] { val client = sender def !(msg: Any) = client ! msg } } else IllegalActorStateException("No channel available") }
So the server does, say
replyTo = channel
(or put it in a queue, or whatever) and then later uses it like this
replyTo ! response
just like sender would be used in a direct reply in fire-and-forget
mode.
"replyTarget ! response" would be equivalent to "reply(response)"
(the implementation of replyTarget is, of course, very similar to that
of reply).
MsgTarget is identical to Lift's SimpleActor - maybe better called
SimpleActorRef or so?
Leave a comment
on 2010-07-13 06:17 *
By Heiko Seeberger
Better call MsgTarget Channel. That's almost aligned with Scala's OutputChannel.
on 2010-07-13 10:06 *
By Jonas Bonér
Description changed from
abstract class MsgT... to
abstract class Chan...
Agree. It should be called Channel. Changed the sample.