Created
August 1, 2011 23:25
-
-
Save derekjw/1119235 to your computer and use it in GitHub Desktop.
Dirty hack for Akka Java API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/akka-actor/src/main/scala/akka/actor/ActorRef.scala b/akka-actor/src/main/scala/akka/actor/ActorRef.scala | |
index 5609489..0e7f3e7 100644 | |
--- a/akka-actor/src/main/scala/akka/actor/ActorRef.scala | |
+++ b/akka-actor/src/main/scala/akka/actor/ActorRef.scala | |
@@ -303,7 +303,7 @@ abstract class ActorRef extends ActorRefShared with ForwardableChannel with Repl | |
* | |
* If you would rather have an exception, check the <code>reply(..)</code> version. | |
*/ | |
- def tryReply(message: Any): Boolean = channel.tryTell(message, this) | |
+ def tryReply(message: Any): Boolean = channel.tryTell(message)(this) | |
/** | |
* Sets the dispatcher for this actor. Needs to be invoked before the actor is started. | |
diff --git a/akka-actor/src/main/scala/akka/actor/Channel.scala b/akka-actor/src/main/scala/akka/actor/Channel.scala | |
index 692ca8d..d25f62d 100644 | |
--- a/akka-actor/src/main/scala/akka/actor/Channel.scala | |
+++ b/akka-actor/src/main/scala/akka/actor/Channel.scala | |
@@ -4,6 +4,24 @@ | |
package akka.actor | |
+package japi { | |
+ trait Channel[-T] { self: akka.actor.Channel[T] ⇒ | |
+ /** | |
+ * Try to send the specified message to the channel, i.e. fire-and-forget semantics.<p/> | |
+ * <pre> | |
+ * channel.tell(message); | |
+ * </pre> | |
+ */ | |
+ private[japi] def tryTell(msg: T): Boolean = { | |
+ try { | |
+ self.!(msg)(NullChannel) | |
+ true | |
+ } catch { | |
+ case _: Exception ⇒ false | |
+ } | |
+ } | |
+ } | |
+} | |
/** | |
* Abstraction for unification of sender and senderFuture for later reply. | |
* Can be stored away and used at a later point in time. | |
@@ -12,7 +30,7 @@ package akka.actor | |
* untyped, as there is no way to utilize its real static type without | |
* requiring runtime-costly manifests. | |
*/ | |
-trait Channel[-T] { | |
+trait Channel[-T] extends japi.Channel[T] { | |
/** | |
* Scala API. <p/> | |
@@ -48,14 +66,6 @@ trait Channel[-T] { | |
def tell(msg: T, sender: UntypedChannel): Unit = this.!(msg)(sender) | |
/** | |
- * Try to send the specified message to the channel, i.e. fire-and-forget semantics.<p/> | |
- * <pre> | |
- * channel.tell(message); | |
- * </pre> | |
- */ | |
- def tryTell(msg: T): Boolean = this.tryTell(msg, NullChannel) | |
- | |
- /** | |
* Java API. <p/> | |
* Try to send the specified message to the channel, i.e. fire-and-forget | |
* semantics, including the sender reference if possible (not supported on | |
@@ -64,7 +74,7 @@ trait Channel[-T] { | |
* actor.tell(message, context); | |
* </pre> | |
*/ | |
- def tryTell(msg: T, sender: UntypedChannel): Boolean = { | |
+ def tryTell(msg: T)(implicit sender: UntypedChannel): Boolean = { | |
try { | |
this.!(msg)(sender) | |
true | |
@@ -120,7 +130,6 @@ case object NullChannel extends UntypedChannel { | |
2. Invoked a method on an TypedActor from an instance NOT an TypedActor. | |
You may want to have a look at safe_! for a variant returning a Boolean""") | |
} | |
- def tryTell(msg: Any)(implicit channel: UntypedChannel, dummy: Int = 0): Boolean = false | |
} | |
/** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment