From 4f90ace880fd8a9560d5840d183b1ca4783fa075 Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Sat, 24 Apr 2010 14:57:32 +0200 Subject: [PATCH] Added reply_? that discards messages if it cannot find reply target --- akka-core/src/main/scala/actor/Actor.scala | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/akka-core/src/main/scala/actor/Actor.scala b/akka-core/src/main/scala/actor/Actor.scala index 37a297d5ca..7947848634 100644 --- a/akka-core/src/main/scala/actor/Actor.scala +++ b/akka-core/src/main/scala/actor/Actor.scala @@ -566,11 +566,9 @@ trait Actor extends TransactionManagement with Logging { /** * Use reply(..) to reply with a message to the original sender of the message currently * being processed. + * Throws an IllegalStateException if unable to determine what to reply to */ - protected[this] def reply(message: Any) = replyTo match { - case Some(Left(actor)) => actor ! message - case Some(Right(future)) => future.completeWithResult(message) - case _ => throw new IllegalStateException( + protected[this] def reply(message: Any) = if(!reply_?(message)) throw new IllegalStateException( "\n\tNo sender in scope, can't reply. " + "\n\tYou have probably used the '!' method to either; " + "\n\t\t1. Send a message to a remote actor which does not have a contact address." + @@ -579,6 +577,23 @@ trait Actor extends TransactionManagement with Logging { "\n\tIf so, switch to '!!' (or remove '@oneway') which passes on an implicit future" + "\n\tthat will be bound by the argument passed to 'reply'." + "\n\tAlternatively, you can use setReplyToAddress to make sure the actor can be contacted over the network.") + + /** + * Use reply_?(..) to reply with a message to the original sender of the message currently + * being processed. + * Returns true if reply was sent, and false if unable to determine what to reply to. + */ + protected[this] def reply_?(message: Any) : Boolean = replyTo match { + case Some(Left(actor)) => + actor ! message + true + + case Some(Right(future)) => + future.completeWithResult(message) + true + + case _ => + false } /**