diff --git a/akka-actor-tests/src/test/java/akka/actor/JavaAPITestActor.java b/akka-actor-tests/src/test/java/akka/actor/JavaAPITestActor.java index f8e9d1c3ee..e84f45f885 100644 --- a/akka-actor-tests/src/test/java/akka/actor/JavaAPITestActor.java +++ b/akka-actor-tests/src/test/java/akka/actor/JavaAPITestActor.java @@ -2,7 +2,7 @@ package akka.actor; public class JavaAPITestActor extends UntypedActor { public void onReceive(Object msg) { - getSender().tell("got it!"); + getSender().tell("got it!", getSelf()); getContext().getChildren(); } } diff --git a/akka-actor-tests/src/test/java/akka/actor/NonPublicClass.java b/akka-actor-tests/src/test/java/akka/actor/NonPublicClass.java index 850d82cd62..047492e00f 100644 --- a/akka-actor-tests/src/test/java/akka/actor/NonPublicClass.java +++ b/akka-actor-tests/src/test/java/akka/actor/NonPublicClass.java @@ -12,6 +12,6 @@ public class NonPublicClass { class MyNonPublicActorClass extends UntypedActor { @Override public void onReceive(Object msg) { - getSender().tell(msg); + getSender().tell(msg, getSelf()); } } \ No newline at end of file diff --git a/akka-actor-tests/src/test/java/akka/actor/StashJavaAPI.java b/akka-actor-tests/src/test/java/akka/actor/StashJavaAPI.java index 50df3d0a6b..3c17f2fe45 100644 --- a/akka-actor-tests/src/test/java/akka/actor/StashJavaAPI.java +++ b/akka-actor-tests/src/test/java/akka/actor/StashJavaAPI.java @@ -1,36 +1,34 @@ package akka.actor; -import akka.actor.ActorSystem; -import akka.japi.Creator; -import akka.testkit.AkkaSpec; -import com.typesafe.config.ConfigFactory; - import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import static org.junit.Assert.*; + +import com.typesafe.config.ConfigFactory; public class StashJavaAPI { - private static ActorSystem system; + private static ActorSystem system; - @BeforeClass - public static void beforeAll() { - system = ActorSystem.create("StashJavaAPI", ConfigFactory.parseString(ActorWithStashSpec.testConf())); - } + @BeforeClass + public static void beforeAll() { + system = ActorSystem.create("StashJavaAPI", + ConfigFactory.parseString(ActorWithStashSpec.testConf())); + } - @AfterClass - public static void afterAll() { - system.shutdown(); - system = null; - } + @AfterClass + public static void afterAll() { + system.shutdown(); + system = null; + } - @Test - public void mustBeAbleToUseStash() { - ActorRef ref = system.actorOf(new Props(StashJavaAPITestActor.class).withDispatcher("my-dispatcher")); - ref.tell("Hello", ref); - ref.tell("Hello", ref); - ref.tell(new Object()); - } + @Test + public void mustBeAbleToUseStash() { + ActorRef ref = system.actorOf(new Props(StashJavaAPITestActor.class) + .withDispatcher("my-dispatcher")); + ref.tell("Hello", ref); + ref.tell("Hello", ref); + ref.tell(new Object(), null); + } } diff --git a/akka-actor-tests/src/test/java/akka/actor/StashJavaAPITestActor.java b/akka-actor-tests/src/test/java/akka/actor/StashJavaAPITestActor.java index 8bc1bcc0d6..5d12f5d8e2 100644 --- a/akka-actor-tests/src/test/java/akka/actor/StashJavaAPITestActor.java +++ b/akka-actor-tests/src/test/java/akka/actor/StashJavaAPITestActor.java @@ -3,21 +3,22 @@ package akka.actor; import static org.junit.Assert.*; public class StashJavaAPITestActor extends UntypedActorWithStash { - int count = 0; - public void onReceive(Object msg) { - if (msg instanceof String) { - if (count < 0) { - getSender().tell(new Integer(((String) msg).length())); - } else if (count == 2) { - count = -1; - unstashAll(); - } else { - count += 1; - stash(); - } - } else if (msg instanceof Integer) { - int value = ((Integer) msg).intValue(); - assertEquals(value, 5); - } + int count = 0; + + public void onReceive(Object msg) { + if (msg instanceof String) { + if (count < 0) { + getSender().tell(new Integer(((String) msg).length()), getSelf()); + } else if (count == 2) { + count = -1; + unstashAll(); + } else { + count += 1; + stash(); + } + } else if (msg instanceof Integer) { + int value = ((Integer) msg).intValue(); + assertEquals(value, 5); } + } } diff --git a/akka-actor-tests/src/test/java/akka/routing/CustomRouteTest.java b/akka-actor-tests/src/test/java/akka/routing/CustomRouteTest.java index dc92ace228..d47c49e28d 100644 --- a/akka-actor-tests/src/test/java/akka/routing/CustomRouteTest.java +++ b/akka-actor-tests/src/test/java/akka/routing/CustomRouteTest.java @@ -3,14 +3,9 @@ */ package akka.routing; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - import akka.actor.ActorRef; import akka.actor.ActorSystem; import akka.actor.Props; -import akka.routing.RoundRobinRouter; import akka.testkit.ExtractRoute; public class CustomRouteTest { diff --git a/akka-actor-tests/src/test/scala/akka/actor/ActorRefSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/ActorRefSpec.scala index a95e2d84b8..ae956e968a 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/ActorRefSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/ActorRefSpec.scala @@ -371,8 +371,8 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout { val timeout = Timeout(20000) val ref = system.actorOf(Props(new Actor { def receive = { - case 5 ⇒ sender.tell("five") - case 0 ⇒ sender.tell("null") + case 5 ⇒ sender ! "five" + case 0 ⇒ sender ! "null" } })) diff --git a/akka-actor-tests/src/test/scala/akka/actor/ConsistencySpec.scala b/akka-actor-tests/src/test/scala/akka/actor/ConsistencySpec.scala index 8dbd9f6b4f..dbba376054 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/ConsistencySpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/ConsistencySpec.scala @@ -32,7 +32,7 @@ object ConsistencySpec { case step: Long ⇒ if (lastStep != (step - 1)) - sender.tell("Test failed: Last step %s, this step %s".format(lastStep, step)) + sender ! "Test failed: Last step %s, this step %s".format(lastStep, step) var shouldBeFortyTwo = left.value + right.value if (shouldBeFortyTwo != 42) diff --git a/akka-actor-tests/src/test/scala/akka/actor/Ticket669Spec.scala b/akka-actor-tests/src/test/scala/akka/actor/Ticket669Spec.scala index e6ac2a13f3..6c96ae28a8 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/Ticket669Spec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/Ticket669Spec.scala @@ -59,11 +59,11 @@ object Ticket669Spec { } override def preRestart(reason: scala.Throwable, msg: Option[Any]) { - sender.tell("failure1") + sender ! "failure1" } override def postStop() { - sender.tell("failure2") + sender ! "failure2" } } } diff --git a/akka-actor-tests/src/test/scala/akka/actor/dispatch/ActorModelSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/dispatch/ActorModelSpec.scala index 3a3371ad51..d67acd9ac1 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/dispatch/ActorModelSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/dispatch/ActorModelSpec.scala @@ -86,7 +86,7 @@ object ActorModelSpec { case Wait(time) ⇒ ack; Thread.sleep(time); busy.switchOff() case WaitAck(time, l) ⇒ ack; Thread.sleep(time); l.countDown(); busy.switchOff() case Reply(msg) ⇒ ack; sender ! msg; busy.switchOff() - case TryReply(msg) ⇒ ack; sender.tell(msg); busy.switchOff() + case TryReply(msg) ⇒ ack; sender.tell(msg, null); busy.switchOff() case Forward(to, msg) ⇒ ack; to.forward(msg); busy.switchOff() case CountDown(latch) ⇒ ack; latch.countDown(); busy.switchOff() case Increment(count) ⇒ ack; count.incrementAndGet(); busy.switchOff() diff --git a/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala b/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala index a1de1f84bd..58a785ccf3 100644 --- a/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/dispatch/PriorityDispatcherSpec.scala @@ -56,7 +56,7 @@ class PriorityDispatcherSpec extends AkkaSpec(PriorityDispatcherSpec.config) wit def receive = { case i: Int ⇒ acc = i :: acc - case 'Result ⇒ sender.tell(acc) + case 'Result ⇒ sender ! acc } }).withDispatcher(dispatcherKey)).asInstanceOf[InternalActorRef] diff --git a/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala b/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala index 9e126e75ed..588b0635cc 100644 --- a/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/routing/RoutingSpec.scala @@ -537,7 +537,7 @@ class RoutingSpec extends AkkaSpec(RoutingSpec.config) with DefaultTimeout with case _id: Int if (_id == id) ⇒ case x ⇒ { Thread sleep 100 * id - sender.tell(id) + sender ! id } } diff --git a/akka-actor/src/main/java/akka/dispatch/AbstractMessageDispatcher.java b/akka-actor/src/main/java/akka/dispatch/AbstractMessageDispatcher.java index c701931edc..183812428e 100644 --- a/akka-actor/src/main/java/akka/dispatch/AbstractMessageDispatcher.java +++ b/akka-actor/src/main/java/akka/dispatch/AbstractMessageDispatcher.java @@ -6,9 +6,6 @@ package akka.dispatch; import akka.util.Unsafe; -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; -import java.util.concurrent.atomic.AtomicLongFieldUpdater; - abstract class AbstractMessageDispatcher { final static long shutdownScheduleOffset; final static long inhabitantsOffset; diff --git a/akka-actor/src/main/scala/akka/actor/ActorRef.scala b/akka-actor/src/main/scala/akka/actor/ActorRef.scala index c5e49ece70..615c4ef92e 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorRef.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorRef.scala @@ -92,13 +92,14 @@ abstract class ActorRef extends java.lang.Comparable[ActorRef] with Serializable * actor.tell(message); * */ + @deprecated("use the two-arg variant (typically getSelf() as second arg)", "2.1") final def tell(msg: Any): Unit = this.!(msg)(null: ActorRef) /** * Java API.

* Sends the specified message to the sender, i.e. fire-and-forget - * semantics, including the sender reference if possible (not supported on - * all senders).

+ * semantics, including the sender reference if possible (pass `null` if + * there is nobody to reply to).

*

    * actor.tell(message, context);
    * 
diff --git a/akka-actor/src/main/scala/akka/actor/RepointableActorRef.scala b/akka-actor/src/main/scala/akka/actor/RepointableActorRef.scala index 8ca8ab5cb7..7bbc5517d8 100644 --- a/akka-actor/src/main/scala/akka/actor/RepointableActorRef.scala +++ b/akka-actor/src/main/scala/akka/actor/RepointableActorRef.scala @@ -195,7 +195,7 @@ private[akka] class UnstartedCell(val systemImpl: ActorSystemImpl, val self: Rep lock.unlock() } } else { - system.deadLetters.tell(DeadLetter(message, sender, self)) + system.deadLetters ! DeadLetter(message, sender, self) } } def sendSystemMessage(msg: SystemMessage): Unit = { @@ -209,7 +209,7 @@ private[akka] class UnstartedCell(val systemImpl: ActorSystemImpl, val self: Rep } else { // FIXME: once we have guaranteed delivery of system messages, hook this in! system.eventStream.publish(Warning(self.path.toString, getClass, "dropping system message " + msg + " due to lock timeout")) - system.deadLetters.tell(DeadLetter(msg, self, self)) + system.deadLetters ! DeadLetter(msg, self, self) } } def isLocal = true diff --git a/akka-actor/src/main/scala/akka/actor/dungeon/Dispatch.scala b/akka-actor/src/main/scala/akka/actor/dungeon/Dispatch.scala index e071c1605d..1b9476acb1 100644 --- a/akka-actor/src/main/scala/akka/actor/dungeon/Dispatch.scala +++ b/akka-actor/src/main/scala/akka/actor/dungeon/Dispatch.scala @@ -57,7 +57,7 @@ private[akka] trait Dispatch { this: ActorCell ⇒ if (sendSupervise) { // ➡➡➡ NEVER SEND THE SAME SYSTEM MESSAGE OBJECT TO TWO ACTORS ⬅⬅⬅ parent.sendSystemMessage(akka.dispatch.Supervise(self, uid)) - parent.tell(NullMessage) // read ScalaDoc of NullMessage to see why + parent ! NullMessage // read ScalaDoc of NullMessage to see why } // This call is expected to start off the actor by scheduling its mailbox. diff --git a/akka-actor/src/main/scala/akka/actor/dungeon/FaultHandling.scala b/akka-actor/src/main/scala/akka/actor/dungeon/FaultHandling.scala index f7c06032c8..a42d15c6f5 100644 --- a/akka-actor/src/main/scala/akka/actor/dungeon/FaultHandling.scala +++ b/akka-actor/src/main/scala/akka/actor/dungeon/FaultHandling.scala @@ -194,7 +194,7 @@ private[akka] trait FaultHandling { this: ActorCell ⇒ try if (a ne null) a.postStop() finally try dispatcher.detach(this) finally try parent.sendSystemMessage(ChildTerminated(self)) - finally try parent.tell(NullMessage) // read ScalaDoc of NullMessage to see why + finally try parent ! NullMessage // read ScalaDoc of NullMessage to see why finally try tellWatchersWeDied(a) finally try unwatchWatchedActors(a) finally { diff --git a/akka-actor/src/main/scala/akka/pattern/AskSupport.scala b/akka-actor/src/main/scala/akka/pattern/AskSupport.scala index 7e3c3ce14d..92e34a2294 100644 --- a/akka-actor/src/main/scala/akka/pattern/AskSupport.scala +++ b/akka-actor/src/main/scala/akka/pattern/AskSupport.scala @@ -75,7 +75,7 @@ trait AskSupport { */ def ask(actorRef: ActorRef, message: Any)(implicit timeout: Timeout): Future[Any] = actorRef match { case ref: InternalActorRef if ref.isTerminated ⇒ - actorRef.tell(message) + actorRef ! message Future.failed[Any](new AskTimeoutException("Recipient[%s] had already been terminated." format actorRef)) case ref: InternalActorRef ⇒ if (timeout.duration.length <= 0) Future.failed[Any](new IllegalArgumentException("Timeout length for an `ask` must be greater or equal to 1. Question not sent to [%s]" format actorRef)) diff --git a/akka-camel/src/test/java/akka/camel/ConsumerJavaTestBase.java b/akka-camel/src/test/java/akka/camel/ConsumerJavaTestBase.java index e1e87f8903..466f213092 100644 --- a/akka-camel/src/test/java/akka/camel/ConsumerJavaTestBase.java +++ b/akka-camel/src/test/java/akka/camel/ConsumerJavaTestBase.java @@ -21,39 +21,42 @@ import akka.actor.Props; import akka.testkit.AkkaSpec; import akka.testkit.JavaTestKit; - /** * @author Martin Krasser */ public class ConsumerJavaTestBase { - static ActorSystem system = ActorSystem.create("test", AkkaSpec.testConf()); + static ActorSystem system = ActorSystem.create("test", AkkaSpec.testConf()); - @AfterClass - public static void tearDownAfterClass() { - system.shutdown(); - } + @AfterClass + public static void tearDownAfterClass() { + system.shutdown(); + } - @Test - public void shouldHandleExceptionThrownByActorAndGenerateCustomResponse() throws Exception { - new JavaTestKit(system) {{ - String result = new EventFilter(Exception.class) { - protected String run() { - FiniteDuration timeout = Duration.create(1, TimeUnit.SECONDS); - Camel camel = CamelExtension.get(system); - ExecutionContext executionContext = system.dispatcher(); - try { - ActorRef ref = Await.result( - camel.activationFutureFor(system.actorOf(new Props(SampleErrorHandlingConsumer.class)), timeout, executionContext), - timeout); - return camel.template().requestBody("direct:error-handler-test-java", "hello", String.class); - } - catch (Exception e) { - return e.getMessage(); - } - } - }.occurrences(1).exec(); - assertEquals("error: hello", result); - }}; - } + @Test + public void shouldHandleExceptionThrownByActorAndGenerateCustomResponse() + throws Exception { + new JavaTestKit(system) { + { + String result = new EventFilter(Exception.class) { + protected String run() { + FiniteDuration timeout = Duration.create(1, TimeUnit.SECONDS); + Camel camel = CamelExtension.get(system); + ExecutionContext executionContext = system.dispatcher(); + try { + @SuppressWarnings("unused") + ActorRef ref = Await.result(camel.activationFutureFor( + system.actorOf(new Props(SampleErrorHandlingConsumer.class)), + timeout, executionContext), timeout); + return camel.template().requestBody( + "direct:error-handler-test-java", "hello", String.class); + } catch (Exception e) { + return e.getMessage(); + } + } + }.occurrences(1).exec(); + assertEquals("error: hello", result); + } + }; + } } diff --git a/akka-camel/src/test/java/akka/camel/CustomRouteTestBase.java b/akka-camel/src/test/java/akka/camel/CustomRouteTestBase.java index 5454dd0074..db26c9e8ab 100644 --- a/akka-camel/src/test/java/akka/camel/CustomRouteTestBase.java +++ b/akka-camel/src/test/java/akka/camel/CustomRouteTestBase.java @@ -208,7 +208,7 @@ public class CustomRouteTestBase { @Override public void onReceive(Object message) { this.getProducerTemplate().sendBody(to, "test"); - getSender().tell(Ack.getInstance()); + getSender().tell(Ack.getInstance(), getSelf()); } } } diff --git a/akka-camel/src/test/java/akka/camel/SampleErrorHandlingConsumer.java b/akka-camel/src/test/java/akka/camel/SampleErrorHandlingConsumer.java index f0bd9ebf3f..e5603acec1 100644 --- a/akka-camel/src/test/java/akka/camel/SampleErrorHandlingConsumer.java +++ b/akka-camel/src/test/java/akka/camel/SampleErrorHandlingConsumer.java @@ -42,7 +42,7 @@ public class SampleErrorHandlingConsumer extends UntypedConsumerActor { @Override public void preRestart(Throwable reason, Option message){ - getSender().tell(new Status.Failure(reason)); + getSender().tell(new Status.Failure(reason), getSelf()); } } diff --git a/akka-camel/src/test/java/akka/camel/SampleUntypedConsumer.java b/akka-camel/src/test/java/akka/camel/SampleUntypedConsumer.java index f52a484ccc..be293c21b9 100644 --- a/akka-camel/src/test/java/akka/camel/SampleUntypedConsumer.java +++ b/akka-camel/src/test/java/akka/camel/SampleUntypedConsumer.java @@ -19,7 +19,7 @@ public class SampleUntypedConsumer extends UntypedConsumerActor { CamelMessage msg = (CamelMessage)message; String body = msg.getBodyAs(String.class, getCamelContext()); String header = msg.getHeaderAs("test", String.class,getCamelContext()); - sender().tell(String.format("%s %s", body, header)); + sender().tell(String.format("%s %s", body, header), getSelf()); } } diff --git a/akka-docs/common/code/docs/circuitbreaker/DangerousJavaActor.java b/akka-docs/common/code/docs/circuitbreaker/DangerousJavaActor.java index 071affb831..ec5928a07a 100644 --- a/akka-docs/common/code/docs/circuitbreaker/DangerousJavaActor.java +++ b/akka-docs/common/code/docs/circuitbreaker/DangerousJavaActor.java @@ -64,7 +64,7 @@ public class DangerousJavaActor extends UntypedActor { public Future call() throws Exception { return f; } - })); + }), getSelf()); } if ("block for me".equals(m)) { getSender().tell(breaker @@ -74,7 +74,7 @@ public class DangerousJavaActor extends UntypedActor { public String call() throws Exception { return dangerousCall(); } - })); + }), getSelf()); } } } diff --git a/akka-docs/common/code/docs/duration/Java.java b/akka-docs/common/code/docs/duration/Java.java index 9b7fb93c3a..06bea4d3e3 100644 --- a/akka-docs/common/code/docs/duration/Java.java +++ b/akka-docs/common/code/docs/duration/Java.java @@ -22,5 +22,6 @@ class Java { final Deadline deadline = Duration.create(10, "seconds").fromNow(); final Duration rest = deadline.timeLeft(); //#deadline + rest.toString(); } } diff --git a/akka-docs/java/code/docs/actor/FSMDocTestBase.java b/akka-docs/java/code/docs/actor/FSMDocTestBase.java index 9064833cb0..5cec824bc6 100644 --- a/akka-docs/java/code/docs/actor/FSMDocTestBase.java +++ b/akka-docs/java/code/docs/actor/FSMDocTestBase.java @@ -147,7 +147,7 @@ public class FSMDocTestBase { @Override public void transition(State old, State next) { if (old == State.ACTIVE) { - getTarget().tell(new Batch(drainQueue())); + getTarget().tell(new Batch(drainQueue()), getSelf()); } } @@ -175,11 +175,11 @@ public class FSMDocTestBase { public void mustBunch() { final ActorRef buncher = system.actorOf(new Props(MyFSM.class)); final TestProbe probe = new TestProbe(system); - buncher.tell(new SetTarget(probe.ref())); - buncher.tell(new Queue(1)); - buncher.tell(new Queue(2)); - buncher.tell(flush); - buncher.tell(new Queue(3)); + buncher.tell(new SetTarget(probe.ref()), null); + buncher.tell(new Queue(1), null); + buncher.tell(new Queue(2), null); + buncher.tell(flush, null); + buncher.tell(new Queue(3), null); final Batch b = probe.expectMsgClass(Batch.class); assert b.objects.size() == 2; assert b.objects.contains(1); diff --git a/akka-docs/java/code/docs/actor/FaultHandlingTestBase.java b/akka-docs/java/code/docs/actor/FaultHandlingTestBase.java index 6f31be6ef4..2860ed707b 100644 --- a/akka-docs/java/code/docs/actor/FaultHandlingTestBase.java +++ b/akka-docs/java/code/docs/actor/FaultHandlingTestBase.java @@ -64,7 +64,7 @@ public class FaultHandlingTestBase { public void onReceive(Object o) { if (o instanceof Props) { - getSender().tell(getContext().actorOf((Props) o)); + getSender().tell(getContext().actorOf((Props) o), getSelf()); } else { unhandled(o); } @@ -102,7 +102,7 @@ public class FaultHandlingTestBase { public void onReceive(Object o) { if (o instanceof Props) { - getSender().tell(getContext().actorOf((Props) o)); + getSender().tell(getContext().actorOf((Props) o), getSelf()); } else { unhandled(o); } @@ -126,7 +126,7 @@ public class FaultHandlingTestBase { } else if (o instanceof Integer) { state = (Integer) o; } else if (o.equals("get")) { - getSender().tell(state); + getSender().tell(state, getSelf()); } else { unhandled(o); } @@ -167,21 +167,21 @@ public class FaultHandlingTestBase { //#create //#resume - child.tell(42); + child.tell(42, null); assert Await.result(ask(child, "get", 5000), timeout).equals(42); - child.tell(new ArithmeticException()); + child.tell(new ArithmeticException(), null); assert Await.result(ask(child, "get", 5000), timeout).equals(42); //#resume //#restart - child.tell(new NullPointerException()); + child.tell(new NullPointerException(), null); assert Await.result(ask(child, "get", 5000), timeout).equals(0); //#restart //#stop final TestProbe probe = new TestProbe(system); probe.watch(child); - child.tell(new IllegalArgumentException()); + child.tell(new IllegalArgumentException(), null); probe.expectMsgClass(Terminated.class); //#stop @@ -189,7 +189,7 @@ public class FaultHandlingTestBase { child = (ActorRef) Await.result(ask(supervisor, new Props(Child.class), 5000), timeout); probe.watch(child); assert Await.result(ask(child, "get", 5000), timeout).equals(0); - child.tell(new Exception()); + child.tell(new Exception(), null); probe.expectMsgClass(Terminated.class); //#escalate-kill @@ -197,9 +197,9 @@ public class FaultHandlingTestBase { superprops = new Props(Supervisor2.class); supervisor = system.actorOf(superprops); child = (ActorRef) Await.result(ask(supervisor, new Props(Child.class), 5000), timeout); - child.tell(23); + child.tell(23, null); assert Await.result(ask(child, "get", 5000), timeout).equals(23); - child.tell(new Exception()); + child.tell(new Exception(), null); assert Await.result(ask(child, "get", 5000), timeout).equals(0); //#escalate-restart //#testkit diff --git a/akka-docs/java/code/docs/actor/FirstUntypedActor.java b/akka-docs/java/code/docs/actor/FirstUntypedActor.java index fa5d3d35a0..a4aea8c1cd 100644 --- a/akka-docs/java/code/docs/actor/FirstUntypedActor.java +++ b/akka-docs/java/code/docs/actor/FirstUntypedActor.java @@ -16,6 +16,6 @@ public class FirstUntypedActor extends UntypedActor { public void onReceive(Object message) { myActor.forward(message, getContext()); - myActor.tell(PoisonPill.getInstance()); + myActor.tell(PoisonPill.getInstance(), null); } } diff --git a/akka-docs/java/code/docs/actor/MyReceivedTimeoutUntypedActor.java b/akka-docs/java/code/docs/actor/MyReceivedTimeoutUntypedActor.java index 3f24e9cb1f..b1fb899be7 100644 --- a/akka-docs/java/code/docs/actor/MyReceivedTimeoutUntypedActor.java +++ b/akka-docs/java/code/docs/actor/MyReceivedTimeoutUntypedActor.java @@ -16,7 +16,7 @@ public class MyReceivedTimeoutUntypedActor extends UntypedActor { public void onReceive(Object message) { if (message.equals("Hello")) { - getSender().tell("Hello world"); + getSender().tell("Hello world", getSelf()); } else if (message == ReceiveTimeout.getInstance()) { throw new RuntimeException("received timeout"); } else { diff --git a/akka-docs/java/code/docs/actor/SchedulerDocTestBase.java b/akka-docs/java/code/docs/actor/SchedulerDocTestBase.java index a5837ac85c..96aa0bcf1e 100644 --- a/akka-docs/java/code/docs/actor/SchedulerDocTestBase.java +++ b/akka-docs/java/code/docs/actor/SchedulerDocTestBase.java @@ -24,7 +24,6 @@ import akka.testkit.AkkaSpec; import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.*; public class SchedulerDocTestBase { @@ -54,7 +53,7 @@ public class SchedulerDocTestBase { system.scheduler().scheduleOnce(Duration.create(50, TimeUnit.MILLISECONDS), new Runnable() { @Override public void run() { - testActor.tell(System.currentTimeMillis()); + testActor.tell(System.currentTimeMillis(), null); } }, system.dispatcher()); //#schedule-one-off-thunk diff --git a/akka-docs/java/code/docs/actor/UntypedActorDocTestBase.java b/akka-docs/java/code/docs/actor/UntypedActorDocTestBase.java index 2b335dee99..e79d73ec1d 100644 --- a/akka-docs/java/code/docs/actor/UntypedActorDocTestBase.java +++ b/akka-docs/java/code/docs/actor/UntypedActorDocTestBase.java @@ -54,21 +54,15 @@ import java.util.ArrayList; import akka.actor.UntypedActorWithStash; //#import-stash -import akka.actor.Props; import akka.actor.UntypedActor; import akka.actor.UntypedActorFactory; -import akka.dispatch.MessageDispatcher; import org.junit.Test; import scala.Option; import java.lang.Object; -import java.util.ArrayList; import java.util.Iterator; -import java.util.concurrent.TimeUnit; import akka.pattern.Patterns; -import static org.junit.Assert.*; - public class UntypedActorDocTestBase { @Test @@ -95,7 +89,7 @@ public class UntypedActorDocTestBase { ActorSystem system = ActorSystem.create("MySystem"); ActorRef myActor = system.actorOf(new Props(MyUntypedActor.class), "myactor"); //#system-actorOf - myActor.tell("test"); + myActor.tell("test", null); system.shutdown(); } @@ -105,7 +99,7 @@ public class UntypedActorDocTestBase { ActorSystem system = ActorSystem.create("MySystem"); ActorRef myActor = system.actorOf(new Props(MyUntypedActor.class), "myactor"); //#context-actorOf - myActor.tell("test"); + myActor.tell("test", null); system.shutdown(); } @@ -120,7 +114,7 @@ public class UntypedActorDocTestBase { } }), "myactor"); //#creating-constructor - myActor.tell("test"); + myActor.tell("test", null); system.shutdown(); } @@ -130,7 +124,7 @@ public class UntypedActorDocTestBase { //#creating-props ActorRef myActor = system.actorOf(new Props(MyUntypedActor.class).withDispatcher("my-dispatcher"), "myactor"); //#creating-props - myActor.tell("test"); + myActor.tell("test", null); system.shutdown(); } @@ -154,7 +148,7 @@ public class UntypedActorDocTestBase { public void receiveTimeout() { ActorSystem system = ActorSystem.create("MySystem"); ActorRef myActor = system.actorOf(new Props(MyReceivedTimeoutUntypedActor.class)); - myActor.tell("Hello"); + myActor.tell("Hello", null); system.shutdown(); } @@ -163,7 +157,7 @@ public class UntypedActorDocTestBase { ActorSystem system = ActorSystem.create("MySystem"); ActorRef myActor = system.actorOf(new Props(MyUntypedActor.class)); //#poison-pill - myActor.tell(PoisonPill.getInstance()); + myActor.tell(PoisonPill.getInstance(), null); //#poison-pill system.shutdown(); } @@ -173,7 +167,7 @@ public class UntypedActorDocTestBase { ActorSystem system = ActorSystem.create("MySystem"); ActorRef victim = system.actorOf(new Props(MyUntypedActor.class)); //#kill - victim.tell(Kill.getInstance()); + victim.tell(Kill.getInstance(), null); //#kill system.shutdown(); } @@ -186,9 +180,9 @@ public class UntypedActorDocTestBase { return new HotSwapActor(); } })); - myActor.tell("foo"); - myActor.tell("bar"); - myActor.tell("bar"); + myActor.tell("foo", null); + myActor.tell("bar", null); + myActor.tell("bar", null); system.shutdown(); } @@ -265,7 +259,7 @@ public class UntypedActorDocTestBase { try { operation(); } catch (Exception e) { - getSender().tell(new akka.actor.Status.Failure(e)); + getSender().tell(new akka.actor.Status.Failure(e), getSelf()); throw e; } } @@ -298,9 +292,9 @@ public class UntypedActorDocTestBase { //#reply-exception try { String result = operation(); - getSender().tell(result); + getSender().tell(result, getSelf()); } catch (Exception e) { - getSender().tell(new akka.actor.Status.Failure(e)); + getSender().tell(new akka.actor.Status.Failure(e), getSelf()); throw e; } //#reply-exception @@ -318,7 +312,7 @@ public class UntypedActorDocTestBase { @Override public void apply(Object message) { if (message.equals("bar")) { - getSender().tell("I am already angry?"); + getSender().tell("I am already angry?", getSelf()); } else if (message.equals("foo")) { getContext().become(happy); } @@ -329,7 +323,7 @@ public class UntypedActorDocTestBase { @Override public void apply(Object message) { if (message.equals("bar")) { - getSender().tell("I am already happy :-)"); + getSender().tell("I am already happy :-)", getSelf()); } else if (message.equals("foo")) { getContext().become(angry); } @@ -390,7 +384,7 @@ public class UntypedActorDocTestBase { } else if (message instanceof Terminated) { final Terminated t = (Terminated) message; if (t.getActor() == child) { - lastSender.tell("finished"); + lastSender.tell("finished", getSelf()); } } else { unhandled(message); diff --git a/akka-docs/java/code/docs/actor/UntypedActorSwapper.java b/akka-docs/java/code/docs/actor/UntypedActorSwapper.java index 985c75bfd7..c882ac015a 100644 --- a/akka-docs/java/code/docs/actor/UntypedActorSwapper.java +++ b/akka-docs/java/code/docs/actor/UntypedActorSwapper.java @@ -44,12 +44,12 @@ public class UntypedActorSwapper { public static void main(String... args) { ActorSystem system = ActorSystem.create("MySystem"); ActorRef swap = system.actorOf(new Props(Swapper.class)); - swap.tell(SWAP); // logs Hi - swap.tell(SWAP); // logs Ho - swap.tell(SWAP); // logs Hi - swap.tell(SWAP); // logs Ho - swap.tell(SWAP); // logs Hi - swap.tell(SWAP); // logs Ho + swap.tell(SWAP, null); // logs Hi + swap.tell(SWAP, null); // logs Ho + swap.tell(SWAP, null); // logs Hi + swap.tell(SWAP, null); // logs Ho + swap.tell(SWAP, null); // logs Hi + swap.tell(SWAP, null); // logs Ho } } diff --git a/akka-docs/java/code/docs/camel/ActivationTestBase.java b/akka-docs/java/code/docs/camel/ActivationTestBase.java index d75b59b02b..e0b9b60c2b 100644 --- a/akka-docs/java/code/docs/camel/ActivationTestBase.java +++ b/akka-docs/java/code/docs/camel/ActivationTestBase.java @@ -14,8 +14,6 @@ package docs.camel; import org.junit.Test; -import java.util.concurrent.TimeUnit; - public class ActivationTestBase { @Test diff --git a/akka-docs/java/code/docs/camel/Consumer2.java b/akka-docs/java/code/docs/camel/Consumer2.java index b22c324877..7f1836a9e1 100644 --- a/akka-docs/java/code/docs/camel/Consumer2.java +++ b/akka-docs/java/code/docs/camel/Consumer2.java @@ -12,7 +12,7 @@ public class Consumer2 extends UntypedConsumerActor { if (message instanceof CamelMessage) { CamelMessage camelMessage = (CamelMessage) message; String body = camelMessage.getBodyAs(String.class, getCamelContext()); - getSender().tell(String.format("Received message: %s",body)); + getSender().tell(String.format("Received message: %s",body), getSelf()); } else unhandled(message); } diff --git a/akka-docs/java/code/docs/camel/Consumer3.java b/akka-docs/java/code/docs/camel/Consumer3.java index bf661cb8ea..95c24f2f82 100644 --- a/akka-docs/java/code/docs/camel/Consumer3.java +++ b/akka-docs/java/code/docs/camel/Consumer3.java @@ -18,12 +18,12 @@ public class Consumer3 extends UntypedConsumerActor{ public void onReceive(Object message) { if (message instanceof CamelMessage) { - getSender().tell(Ack.getInstance()); + getSender().tell(Ack.getInstance(), getSelf()); // on success // .. Exception someException = new Exception("e1"); // on failure - getSender().tell(new Status.Failure(someException)); + getSender().tell(new Status.Failure(someException), getSelf()); } else unhandled(message); } diff --git a/akka-docs/java/code/docs/camel/Consumer4.java b/akka-docs/java/code/docs/camel/Consumer4.java index 144d79965b..960b523f3a 100644 --- a/akka-docs/java/code/docs/camel/Consumer4.java +++ b/akka-docs/java/code/docs/camel/Consumer4.java @@ -23,7 +23,7 @@ public class Consumer4 extends UntypedConsumerActor { if (message instanceof CamelMessage) { CamelMessage camelMessage = (CamelMessage) message; String body = camelMessage.getBodyAs(String.class, getCamelContext()); - getSender().tell(String.format("Hello %s",body)); + getSender().tell(String.format("Hello %s",body), getSelf()); } else unhandled(message); } diff --git a/akka-docs/java/code/docs/camel/ErrorThrowingConsumer.java b/akka-docs/java/code/docs/camel/ErrorThrowingConsumer.java index 23790021be..9a01717287 100644 --- a/akka-docs/java/code/docs/camel/ErrorThrowingConsumer.java +++ b/akka-docs/java/code/docs/camel/ErrorThrowingConsumer.java @@ -36,7 +36,7 @@ public class ErrorThrowingConsumer extends UntypedConsumerActor{ @Override public void preRestart(Throwable reason, Option message) { - getSender().tell(new Status.Failure(reason)); + getSender().tell(new Status.Failure(reason), getSelf()); } } //#ErrorThrowingConsumer \ No newline at end of file diff --git a/akka-docs/java/code/docs/camel/OnRouteResponseTestBase.java b/akka-docs/java/code/docs/camel/OnRouteResponseTestBase.java index 7bcb9e16db..54248c8cfd 100644 --- a/akka-docs/java/code/docs/camel/OnRouteResponseTestBase.java +++ b/akka-docs/java/code/docs/camel/OnRouteResponseTestBase.java @@ -1,7 +1,6 @@ package docs.camel; import akka.actor.*; -import org.junit.Test; public class OnRouteResponseTestBase { @@ -18,7 +17,7 @@ public class OnRouteResponseTestBase { ActorRef forwardResponse = system.actorOf(new Props(factory)); // the Forwarder sends out a request to the web page and forwards the response to // the ResponseReceiver - forwardResponse.tell("some request"); + forwardResponse.tell("some request", null); //#RouteResponse system.stop(receiver); system.stop(forwardResponse); diff --git a/akka-docs/java/code/docs/camel/ProducerTestBase.java b/akka-docs/java/code/docs/camel/ProducerTestBase.java index 2cab47d02c..e2954e06f8 100644 --- a/akka-docs/java/code/docs/camel/ProducerTestBase.java +++ b/akka-docs/java/code/docs/camel/ProducerTestBase.java @@ -1,20 +1,14 @@ package docs.camel; -import akka.actor.*; -import akka.camel.Camel; -import akka.camel.CamelExtension; -import akka.camel.CamelMessage; -import akka.pattern.Patterns; -import scala.concurrent.Future; -import scala.concurrent.util.Duration; -import scala.concurrent.util.FiniteDuration; -import org.apache.camel.CamelContext; -import org.apache.camel.ProducerTemplate; -import org.junit.Test; - import java.util.HashMap; import java.util.Map; -import java.util.concurrent.TimeUnit; + +import scala.concurrent.Future; +import akka.actor.ActorRef; +import akka.actor.ActorSystem; +import akka.actor.Props; +import akka.camel.CamelMessage; +import akka.pattern.Patterns; public class ProducerTestBase { public void tellJmsProducer() { @@ -22,7 +16,7 @@ public class ProducerTestBase { ActorSystem system = ActorSystem.create("some-system"); Props props = new Props(Orders.class); ActorRef producer = system.actorOf(props, "jmsproducer"); - producer.tell(""); + producer.tell("", null); //#TellProducer system.shutdown(); } @@ -45,7 +39,7 @@ public class ProducerTestBase { ActorRef producer = system.actorOf(props,"jmsproducer"); Map headers = new HashMap(); headers.put(CamelMessage.MessageExchangeId(),"123"); - producer.tell(new CamelMessage("",headers)); + producer.tell(new CamelMessage("",headers), null); //#Correlate system.stop(producer); system.shutdown(); diff --git a/akka-docs/java/code/docs/camel/RequestBodyActor.java b/akka-docs/java/code/docs/camel/RequestBodyActor.java index 009b0f380f..dfa5599069 100644 --- a/akka-docs/java/code/docs/camel/RequestBodyActor.java +++ b/akka-docs/java/code/docs/camel/RequestBodyActor.java @@ -9,7 +9,7 @@ public class RequestBodyActor extends UntypedActor { public void onReceive(Object message) { Camel camel = CamelExtension.get(getContext().system()); ProducerTemplate template = camel.template(); - getSender().tell(template.requestBody("direct:news", message)); + getSender().tell(template.requestBody("direct:news", message), getSelf()); } } //#RequestProducerTemplate \ No newline at end of file diff --git a/akka-docs/java/code/docs/camel/Responder.java b/akka-docs/java/code/docs/camel/Responder.java index 304ed4bb5d..12ca8603cf 100644 --- a/akka-docs/java/code/docs/camel/Responder.java +++ b/akka-docs/java/code/docs/camel/Responder.java @@ -9,7 +9,7 @@ public class Responder extends UntypedActor{ public void onReceive(Object message) { if (message instanceof CamelMessage) { CamelMessage camelMessage = (CamelMessage) message; - getSender().tell(createResponse(camelMessage)); + getSender().tell(createResponse(camelMessage), getSelf()); } else unhandled(message); } diff --git a/akka-docs/java/code/docs/camel/sample/http/HttpTransformer.java b/akka-docs/java/code/docs/camel/sample/http/HttpTransformer.java index 36a620379f..267d828cd7 100644 --- a/akka-docs/java/code/docs/camel/sample/http/HttpTransformer.java +++ b/akka-docs/java/code/docs/camel/sample/http/HttpTransformer.java @@ -16,9 +16,9 @@ public class HttpTransformer extends UntypedActor{ return text.replaceAll("Akka ", "AKKA "); } }); - getSender().tell(replacedMessage); + getSender().tell(replacedMessage, getSelf()); } else if (message instanceof Status.Failure) { - getSender().tell(message); + getSender().tell(message, getSelf()); } else unhandled(message); } diff --git a/akka-docs/java/code/docs/dispatcher/DispatcherDocTestBase.java b/akka-docs/java/code/docs/dispatcher/DispatcherDocTestBase.java index ca5569657e..c3fbd03d14 100644 --- a/akka-docs/java/code/docs/dispatcher/DispatcherDocTestBase.java +++ b/akka-docs/java/code/docs/dispatcher/DispatcherDocTestBase.java @@ -37,12 +37,10 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import scala.Option; -import static org.junit.Assert.*; import com.typesafe.config.ConfigFactory; import docs.actor.MyUntypedActor; -import docs.actor.UntypedActorDocTestBase.MyActor; import akka.testkit.AkkaSpec; public class DispatcherDocTestBase { @@ -89,14 +87,14 @@ public class DispatcherDocTestBase { LoggingAdapter log = Logging.getLogger(getContext().system(), this); { - getSelf().tell("lowpriority"); - getSelf().tell("lowpriority"); - getSelf().tell("highpriority"); - getSelf().tell("pigdog"); - getSelf().tell("pigdog2"); - getSelf().tell("pigdog3"); - getSelf().tell("highpriority"); - getSelf().tell(PoisonPill.getInstance()); + getSelf().tell("lowpriority", getSelf()); + getSelf().tell("lowpriority", getSelf()); + getSelf().tell("highpriority", getSelf()); + getSelf().tell("pigdog", getSelf()); + getSelf().tell("pigdog2", getSelf()); + getSelf().tell("pigdog3", getSelf()); + getSelf().tell("highpriority", getSelf()); + getSelf().tell(PoisonPill.getInstance(), getSelf()); } public void onReceive(Object message) { diff --git a/akka-docs/java/code/docs/event/LoggingDocTestBase.java b/akka-docs/java/code/docs/event/LoggingDocTestBase.java index 77e46b3f92..d19915708e 100644 --- a/akka-docs/java/code/docs/event/LoggingDocTestBase.java +++ b/akka-docs/java/code/docs/event/LoggingDocTestBase.java @@ -21,7 +21,6 @@ import akka.event.Logging.Debug; import org.junit.Test; import scala.Option; -import static org.junit.Assert.*; import akka.actor.UntypedActorFactory; //#imports-deadletter @@ -42,7 +41,7 @@ public class LoggingDocTestBase { return new MyActor(); } })); - myActor.tell("test"); + myActor.tell("test", null); system.shutdown(); } @@ -96,7 +95,7 @@ public class LoggingDocTestBase { class MyEventListener extends UntypedActor { public void onReceive(Object message) { if (message instanceof InitializeLogger) { - getSender().tell(Logging.loggerInitialized()); + getSender().tell(Logging.loggerInitialized(), getSelf()); } else if (message instanceof Error) { // ... } else if (message instanceof Warning) { diff --git a/akka-docs/java/code/docs/future/FutureDocTestBase.java b/akka-docs/java/code/docs/future/FutureDocTestBase.java index ca23065661..74dc3a6e28 100644 --- a/akka-docs/java/code/docs/future/FutureDocTestBase.java +++ b/akka-docs/java/code/docs/future/FutureDocTestBase.java @@ -534,13 +534,13 @@ public class FutureDocTestBase { public static class MyActor extends UntypedActor { public void onReceive(Object message) { if (message instanceof String) { - getSender().tell(((String) message).toUpperCase()); + getSender().tell(((String) message).toUpperCase(), getSelf()); } else if (message instanceof Integer) { int i = ((Integer) message).intValue(); if (i < 0) { - getSender().tell(new Failure(new ArithmeticException("Negative values not supported"))); + getSender().tell(new Failure(new ArithmeticException("Negative values not supported")), getSelf()); } else { - getSender().tell(i); + getSender().tell(i, getSelf()); } } else { unhandled(message); diff --git a/akka-docs/java/code/docs/jrouting/CustomRouterDocTestBase.java b/akka-docs/java/code/docs/jrouting/CustomRouterDocTestBase.java index d47419ee60..5918c07d12 100644 --- a/akka-docs/java/code/docs/jrouting/CustomRouterDocTestBase.java +++ b/akka-docs/java/code/docs/jrouting/CustomRouterDocTestBase.java @@ -3,28 +3,37 @@ */ package docs.jrouting; -import java.util.List; +import static akka.pattern.Patterns.ask; +import static docs.jrouting.CustomRouterDocTestBase.Message.DemocratCountResult; +import static docs.jrouting.CustomRouterDocTestBase.Message.DemocratVote; +import static docs.jrouting.CustomRouterDocTestBase.Message.RepublicanCountResult; +import static docs.jrouting.CustomRouterDocTestBase.Message.RepublicanVote; +import static org.junit.Assert.assertEquals; + import java.util.Arrays; +import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import akka.actor.*; -import akka.routing.*; -import scala.concurrent.util.Duration; -import akka.util.Timeout; import scala.concurrent.Await; import scala.concurrent.Future; +import scala.concurrent.util.Duration; +import akka.actor.ActorRef; +import akka.actor.ActorSystem; +import akka.actor.OneForOneStrategy; +import akka.actor.Props; +import akka.actor.SupervisorStrategy; +import akka.actor.UntypedActor; import akka.dispatch.Dispatchers; +import akka.routing.CustomRoute; +import akka.routing.CustomRouterConfig; +import akka.routing.Destination; +import akka.routing.RoundRobinRouter; +import akka.routing.RouteeProvider; import akka.testkit.AkkaSpec; -import com.typesafe.config.ConfigFactory; -import static akka.pattern.Patterns.ask; - -import static docs.jrouting.CustomRouterDocTestBase.DemocratActor; -import static docs.jrouting.CustomRouterDocTestBase.RepublicanActor; -import static docs.jrouting.CustomRouterDocTestBase.Message.*; +import akka.util.Timeout; public class CustomRouterDocTestBase { @@ -67,11 +76,11 @@ public class CustomRouterDocTestBase { @Test public void countVotesAsIntendedNotAsInFlorida() throws Exception { ActorRef routedActor = system.actorOf(new Props().withRouter(new VoteCountRouter())); - routedActor.tell(DemocratVote); - routedActor.tell(DemocratVote); - routedActor.tell(RepublicanVote); - routedActor.tell(DemocratVote); - routedActor.tell(RepublicanVote); + routedActor.tell(DemocratVote, null); + routedActor.tell(DemocratVote, null); + routedActor.tell(RepublicanVote, null); + routedActor.tell(DemocratVote, null); + routedActor.tell(RepublicanVote, null); Timeout timeout = new Timeout(Duration.create(1, "seconds")); Future democratsResult = ask(routedActor, DemocratCountResult, timeout); Future republicansResult = ask(routedActor, RepublicanCountResult, timeout); diff --git a/akka-docs/java/code/docs/jrouting/FibonacciActor.java b/akka-docs/java/code/docs/jrouting/FibonacciActor.java index e316f27bce..7c084849b7 100644 --- a/akka-docs/java/code/docs/jrouting/FibonacciActor.java +++ b/akka-docs/java/code/docs/jrouting/FibonacciActor.java @@ -12,7 +12,7 @@ public class FibonacciActor extends UntypedActor { public void onReceive(Object msg) { if (msg instanceof FibonacciNumber) { FibonacciNumber fibonacciNumber = (FibonacciNumber) msg; - getSender().tell(fibonacci(fibonacciNumber.getNbr())); + getSender().tell(fibonacci(fibonacciNumber.getNbr()), getSelf()); } else { unhandled(msg); } diff --git a/akka-docs/java/code/docs/jrouting/RouterViaConfigExample.java b/akka-docs/java/code/docs/jrouting/RouterViaConfigExample.java index 1505766196..4a89948c88 100644 --- a/akka-docs/java/code/docs/jrouting/RouterViaConfigExample.java +++ b/akka-docs/java/code/docs/jrouting/RouterViaConfigExample.java @@ -45,14 +45,14 @@ public class RouterViaConfigExample { ActorRef router = system.actorOf(new Props(ExampleActor.class).withRouter(new FromConfig()), "router"); //#configurableRouting for (int i = 1; i <= 10; i++) { - router.tell(new ExampleActor.Message(i)); + router.tell(new ExampleActor.Message(i), null); } //#configurableRoutingWithResizer ActorRef router2 = system.actorOf(new Props(ExampleActor.class).withRouter(new FromConfig()), "router2"); //#configurableRoutingWithResizer for (int i = 1; i <= 10; i++) { - router2.tell(new ExampleActor.Message(i)); + router2.tell(new ExampleActor.Message(i), null); } } } \ No newline at end of file diff --git a/akka-docs/java/code/docs/jrouting/RouterViaProgramExample.java b/akka-docs/java/code/docs/jrouting/RouterViaProgramExample.java index 99b924d09b..b403a98915 100644 --- a/akka-docs/java/code/docs/jrouting/RouterViaProgramExample.java +++ b/akka-docs/java/code/docs/jrouting/RouterViaProgramExample.java @@ -47,7 +47,7 @@ public class RouterViaProgramExample { ActorRef router1 = system.actorOf(new Props(ExampleActor.class).withRouter(new RoundRobinRouter(nrOfInstances))); //#programmaticRoutingNrOfInstances for (int i = 1; i <= 6; i++) { - router1.tell(new ExampleActor.Message(i)); + router1.tell(new ExampleActor.Message(i), null); } //#programmaticRoutingRoutees @@ -58,7 +58,7 @@ public class RouterViaProgramExample { ActorRef router2 = system.actorOf(new Props().withRouter(RoundRobinRouter.create(routees))); //#programmaticRoutingRoutees for (int i = 1; i <= 6; i++) { - router2.tell(new ExampleActor.Message(i)); + router2.tell(new ExampleActor.Message(i), null); } //#programmaticRoutingWithResizer @@ -68,7 +68,7 @@ public class RouterViaProgramExample { ActorRef router3 = system.actorOf(new Props(ExampleActor.class).withRouter(new RoundRobinRouter(nrOfInstances))); //#programmaticRoutingWithResizer for (int i = 1; i <= 6; i++) { - router3.tell(new ExampleActor.Message(i)); + router3.tell(new ExampleActor.Message(i), null); } //#remoteRoutees diff --git a/akka-docs/java/code/docs/serialization/SerializationDocTestBase.java b/akka-docs/java/code/docs/serialization/SerializationDocTestBase.java index e30385e1d0..da111f7fbb 100644 --- a/akka-docs/java/code/docs/serialization/SerializationDocTestBase.java +++ b/akka-docs/java/code/docs/serialization/SerializationDocTestBase.java @@ -9,7 +9,6 @@ import static org.junit.Assert.*; import akka.actor.*; import akka.remote.RemoteActorRefProvider; import akka.serialization.*; -import com.typesafe.config.*; //#imports diff --git a/akka-docs/java/code/docs/testkit/TestKitDocTest.java b/akka-docs/java/code/docs/testkit/TestKitDocTest.java index f0c2263c3e..14a51f9957 100644 --- a/akka-docs/java/code/docs/testkit/TestKitDocTest.java +++ b/akka-docs/java/code/docs/testkit/TestKitDocTest.java @@ -97,7 +97,7 @@ public class TestKitDocTest { public void demonstrateWithin() { //#test-within new JavaTestKit(system) {{ - getRef().tell(42); + getRef().tell(42, null); new Within(Duration.Zero(), Duration.create(1, "second")) { // do not put code outside this method, will run afterwards public void run() { @@ -112,7 +112,7 @@ public class TestKitDocTest { public void demonstrateExpectMsg() { //#test-expectmsg new JavaTestKit(system) {{ - getRef().tell(42); + getRef().tell(42, null); final String out = new ExpectMsg("match hint") { // do not put code outside this method, will run afterwards protected String match(Object in) { @@ -132,9 +132,9 @@ public class TestKitDocTest { public void demonstrateReceiveWhile() { //#test-receivewhile new JavaTestKit(system) {{ - getRef().tell(42); - getRef().tell(43); - getRef().tell("hello"); + getRef().tell(42, null); + getRef().tell(43, null); + getRef().tell("hello", null); final String[] out = new ReceiveWhile(String.class, duration("1 second")) { // do not put code outside this method, will run afterwards @@ -172,7 +172,7 @@ public class TestKitDocTest { public void demonstrateAwaitCond() { //#test-awaitCond new JavaTestKit(system) {{ - getRef().tell(42); + getRef().tell(42, null); new AwaitCond( duration("1 second"), // maximum wait time duration("100 millis") // interval at which to check the condition @@ -191,12 +191,12 @@ public class TestKitDocTest { @SuppressWarnings("unchecked") // due to generic varargs public void demonstrateExpect() { new JavaTestKit(system) {{ - getRef().tell("hello"); - getRef().tell("hello"); - getRef().tell("hello"); - getRef().tell("world"); - getRef().tell(42); - getRef().tell(42); + getRef().tell("hello", null); + getRef().tell("hello", null); + getRef().tell("hello", null); + getRef().tell("world", null); + getRef().tell(42, null); + getRef().tell(42, null); //#test-expect final String hello = expectMsgEquals("hello"); final Object any = expectMsgAnyOf("hello", "world"); @@ -223,12 +223,12 @@ public class TestKitDocTest { return msg instanceof String; } }; - getRef().tell("hello"); - getRef().tell(42); + getRef().tell("hello", null); + getRef().tell(42, null); expectMsgEquals(42); // remove message filter ignoreNoMsg(); - getRef().tell("hello"); + getRef().tell("hello", null); expectMsgEquals("hello"); }}; //#test-ignoreMsg @@ -294,7 +294,7 @@ public class TestKitDocTest { } final MyProbe probe = new MyProbe(); - probe.getRef().tell("hello"); + probe.getRef().tell("hello", null); probe.assertHello(); }}; //#test-special-probe @@ -354,7 +354,7 @@ public class TestKitDocTest { // install auto-pilot probe.setAutoPilot(new TestActor.AutoPilot() { public AutoPilot run(ActorRef sender, Object msg) { - sender.tell(msg); + sender.tell(msg, null); return noAutoPilot(); } }); @@ -386,7 +386,7 @@ public class TestKitDocTest { final int result = new EventFilter(ActorKilledException.class) { protected Integer run() { - victim.tell(Kill.getInstance()); + victim.tell(Kill.getInstance(), null); return 42; } }.from("akka://demoSystem/user/victim").occurrences(1).exec(); diff --git a/akka-docs/java/code/docs/testkit/TestKitSampleTest.java b/akka-docs/java/code/docs/testkit/TestKitSampleTest.java index e09daae2fd..b86cc366da 100644 --- a/akka-docs/java/code/docs/testkit/TestKitSampleTest.java +++ b/akka-docs/java/code/docs/testkit/TestKitSampleTest.java @@ -24,12 +24,12 @@ public class TestKitSampleTest { public void onReceive(Object msg) { if (msg.equals("hello")) { - getSender().tell("world"); + getSender().tell("world", getSelf()); if (target != null) target.forward(msg, getContext()); } else if (msg instanceof ActorRef) { target = (ActorRef) msg; - getSender().tell("done"); + getSender().tell("done", getSelf()); } } } diff --git a/akka-docs/java/code/docs/transactor/CoordinatedCounter.java b/akka-docs/java/code/docs/transactor/CoordinatedCounter.java index 4bd679f1eb..8461fd7bf5 100644 --- a/akka-docs/java/code/docs/transactor/CoordinatedCounter.java +++ b/akka-docs/java/code/docs/transactor/CoordinatedCounter.java @@ -20,7 +20,7 @@ public class CoordinatedCounter extends UntypedActor { if (message instanceof Increment) { Increment increment = (Increment) message; if (increment.hasFriend()) { - increment.getFriend().tell(coordinated.coordinate(new Increment())); + increment.getFriend().tell(coordinated.coordinate(new Increment()), getSelf()); } coordinated.atomic(new Runnable() { public void run() { @@ -29,7 +29,7 @@ public class CoordinatedCounter extends UntypedActor { }); } } else if ("GetCount".equals(incoming)) { - getSender().tell(count.get()); + getSender().tell(count.get(), getSelf()); } else { unhandled(incoming); } diff --git a/akka-docs/java/code/docs/transactor/Counter.java b/akka-docs/java/code/docs/transactor/Counter.java index 06092c5db0..c72151e916 100644 --- a/akka-docs/java/code/docs/transactor/Counter.java +++ b/akka-docs/java/code/docs/transactor/Counter.java @@ -20,7 +20,7 @@ public class Counter extends UntypedTransactor { @Override public boolean normally(Object message) { if ("GetCount".equals(message)) { - getSender().tell(count.get()); + getSender().tell(count.get(), getSelf()); return true; } else return false; } diff --git a/akka-docs/java/code/docs/transactor/FriendlyCounter.java b/akka-docs/java/code/docs/transactor/FriendlyCounter.java index f24c044750..3dc4df9cb7 100644 --- a/akka-docs/java/code/docs/transactor/FriendlyCounter.java +++ b/akka-docs/java/code/docs/transactor/FriendlyCounter.java @@ -5,7 +5,6 @@ package docs.transactor; //#class -import akka.actor.*; import akka.transactor.*; import java.util.Set; import scala.concurrent.stm.Ref; @@ -31,7 +30,7 @@ public class FriendlyCounter extends UntypedTransactor { @Override public boolean normally(Object message) { if ("GetCount".equals(message)) { - getSender().tell(count.get()); + getSender().tell(count.get(), getSelf()); return true; } else return false; } diff --git a/akka-docs/java/code/docs/transactor/TransactorDocTest.java b/akka-docs/java/code/docs/transactor/TransactorDocTest.java index f0b15da925..a8b44c9c97 100644 --- a/akka-docs/java/code/docs/transactor/TransactorDocTest.java +++ b/akka-docs/java/code/docs/transactor/TransactorDocTest.java @@ -12,7 +12,6 @@ import akka.actor.*; import scala.concurrent.Await; import static akka.pattern.Patterns.ask; import akka.transactor.Coordinated; -import scala.concurrent.util.Duration; import akka.util.Timeout; import static java.util.concurrent.TimeUnit.SECONDS; //#imports @@ -29,7 +28,7 @@ public class TransactorDocTest { Timeout timeout = new Timeout(5, SECONDS); - counter1.tell(new Coordinated(new Increment(counter2), timeout)); + counter1.tell(new Coordinated(new Increment(counter2), timeout), null); Integer count = (Integer) Await.result(ask(counter1, "GetCount", timeout), timeout.duration()); //#coordinated-example @@ -50,11 +49,11 @@ public class TransactorDocTest { ActorRef actor = system.actorOf(new Props(Coordinator.class)); //#send-coordinated - actor.tell(new Coordinated(new Message(), timeout)); + actor.tell(new Coordinated(new Message(), timeout), null); //#send-coordinated //#include-coordinated - actor.tell(coordinated.coordinate(new Message())); + actor.tell(coordinated.coordinate(new Message()), null); //#include-coordinated coordinated.await(); @@ -69,7 +68,7 @@ public class TransactorDocTest { Timeout timeout = new Timeout(5, SECONDS); Coordinated coordinated = new Coordinated(timeout); - counter.tell(coordinated.coordinate(new Increment())); + counter.tell(coordinated.coordinate(new Increment()), null); coordinated.await(); Integer count = (Integer) Await.result(ask(counter, "GetCount", timeout), timeout.duration()); @@ -86,7 +85,7 @@ public class TransactorDocTest { Timeout timeout = new Timeout(5, SECONDS); Coordinated coordinated = new Coordinated(timeout); - friendlyCounter.tell(coordinated.coordinate(new Increment(friend))); + friendlyCounter.tell(coordinated.coordinate(new Increment(friend)), null); coordinated.await(); Integer count1 = (Integer) Await.result(ask(friendlyCounter, "GetCount", timeout), timeout.duration()); diff --git a/akka-docs/java/code/docs/zeromq/ZeromqDocTestBase.java b/akka-docs/java/code/docs/zeromq/ZeromqDocTestBase.java index c392cf131f..1980011f9e 100644 --- a/akka-docs/java/code/docs/zeromq/ZeromqDocTestBase.java +++ b/akka-docs/java/code/docs/zeromq/ZeromqDocTestBase.java @@ -46,7 +46,6 @@ import com.typesafe.config.ConfigFactory; import java.lang.management.MemoryMXBean; import java.lang.management.MemoryUsage; import java.lang.management.OperatingSystemMXBean; -import java.util.concurrent.TimeUnit; import java.util.Date; import java.text.SimpleDateFormat; @@ -58,8 +57,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.Assume; -import akka.zeromq.SocketType; - public class ZeromqDocTestBase { ActorSystem system; @@ -95,12 +92,12 @@ public class ZeromqDocTestBase { //#sub-topic-socket //#unsub-topic-socket - subTopicSocket.tell(new Unsubscribe("foo.bar")); + subTopicSocket.tell(new Unsubscribe("foo.bar"), null); //#unsub-topic-socket byte[] payload = new byte[0]; //#pub-topic - pubSocket.tell(new ZMQMessage(new Frame("foo.bar"), new Frame(payload))); + pubSocket.tell(new ZMQMessage(new Frame("foo.bar"), new Frame(payload)), null); //#pub-topic //#high-watermark @@ -205,12 +202,12 @@ public class ZeromqDocTestBase { byte[] heapPayload = ser.serializerFor(Heap.class).toBinary( new Heap(timestamp, currentHeap.getUsed(), currentHeap.getMax())); // the first frame is the topic, second is the message - pubSocket.tell(new ZMQMessage(new Frame("health.heap"), new Frame(heapPayload))); + pubSocket.tell(new ZMQMessage(new Frame("health.heap"), new Frame(heapPayload)), getSelf()); // use akka SerializationExtension to convert to bytes byte[] loadPayload = ser.serializerFor(Load.class).toBinary(new Load(timestamp, os.getSystemLoadAverage())); // the first frame is the topic, second is the message - pubSocket.tell(new ZMQMessage(new Frame("health.load"), new Frame(loadPayload))); + pubSocket.tell(new ZMQMessage(new Frame("health.load"), new Frame(loadPayload)), getSelf()); } else { unhandled(message); } diff --git a/akka-docs/modules/code/docs/actor/mailbox/DurableMailboxDocTestBase.java b/akka-docs/modules/code/docs/actor/mailbox/DurableMailboxDocTestBase.java index 06e867c786..331aee0da7 100644 --- a/akka-docs/modules/code/docs/actor/mailbox/DurableMailboxDocTestBase.java +++ b/akka-docs/modules/code/docs/actor/mailbox/DurableMailboxDocTestBase.java @@ -18,8 +18,6 @@ import com.typesafe.config.ConfigFactory; import akka.actor.ActorSystem; import akka.actor.UntypedActor; -import static org.junit.Assert.*; - public class DurableMailboxDocTestBase { ActorSystem system; @@ -41,7 +39,7 @@ public class DurableMailboxDocTestBase { ActorRef myActor = system.actorOf(new Props(MyUntypedActor.class). withDispatcher("my-dispatcher"), "myactor"); //#dispatcher-config-use - myActor.tell("test"); + myActor.tell("test", null); } public static class MyUntypedActor extends UntypedActor { diff --git a/akka-docs/scala/code/docs/routing/RouterTypeExample.scala b/akka-docs/scala/code/docs/routing/RouterTypeExample.scala index db711b565a..be43c4e48f 100644 --- a/akka-docs/scala/code/docs/routing/RouterTypeExample.scala +++ b/akka-docs/scala/code/docs/routing/RouterTypeExample.scala @@ -29,7 +29,7 @@ class PrintlnActor extends Actor { //#fibonacciActor class FibonacciActor extends Actor { def receive = { - case FibonacciNumber(nbr) ⇒ sender tell fibonacci(nbr) + case FibonacciNumber(nbr) ⇒ sender ! fibonacci(nbr) } private def fibonacci(n: Int): Int = { diff --git a/akka-samples/akka-sample-hello-kernel/src/main/java/sample/kernel/hello/java/HelloKernel.java b/akka-samples/akka-sample-hello-kernel/src/main/java/sample/kernel/hello/java/HelloKernel.java index d0ccc4ad79..77e579aa1e 100644 --- a/akka-samples/akka-sample-hello-kernel/src/main/java/sample/kernel/hello/java/HelloKernel.java +++ b/akka-samples/akka-sample-hello-kernel/src/main/java/sample/kernel/hello/java/HelloKernel.java @@ -13,28 +13,31 @@ public class HelloKernel implements Bootable { final ActorSystem system = ActorSystem.create("hellokernel"); static class HelloActor extends UntypedActor { - final ActorRef worldActor = - getContext().actorOf(new Props(WorldActor.class)); + final ActorRef worldActor = getContext().actorOf( + new Props(WorldActor.class)); - public void onReceive(Object message) { - if (message == "start") - worldActor.tell("Hello"); - else if (message instanceof String) - System.out.println("Received message '%s'".format((String)message)); - else unhandled(message); + public void onReceive(Object message) { + if (message == "start") + worldActor.tell("Hello", getSelf()); + else if (message instanceof String) + System.out.println(String.format("Received message '%s'", message)); + else + unhandled(message); + } } -} -static class WorldActor extends UntypedActor { - public void onReceive(Object message) { - if (message instanceof String) - getSender().tell(((String)message).toUpperCase() + " world!"); - else unhandled(message); + static class WorldActor extends UntypedActor { + public void onReceive(Object message) { + if (message instanceof String) + getSender().tell(((String) message).toUpperCase() + " world!", + getSelf()); + else + unhandled(message); + } } -} public void startup() { - system.actorOf(new Props(HelloActor.class)).tell("start"); + system.actorOf(new Props(HelloActor.class)).tell("start", null); } public void shutdown() { diff --git a/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JAdvancedCalculatorActor.java b/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JAdvancedCalculatorActor.java index a8eaade104..bb04e4631d 100644 --- a/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JAdvancedCalculatorActor.java +++ b/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JAdvancedCalculatorActor.java @@ -7,22 +7,28 @@ import akka.actor.UntypedActor; //#actor public class JAdvancedCalculatorActor extends UntypedActor { - @Override - public void onReceive(Object message) throws Exception { - - if (message instanceof Op.Multiply) { - Op.Multiply multiply = (Op.Multiply) message; - System.out.println("Calculating " + multiply.getN1() + " * " + multiply.getN2()); - getSender().tell(new Op.MultiplicationResult(multiply.getN1(), multiply.getN2(), multiply.getN1() * multiply.getN2())); - - } else if (message instanceof Op.Divide) { - Op.Divide divide = (Op.Divide) message; - System.out.println("Calculating " + divide.getN1() + " / " + divide.getN2()); - getSender().tell(new Op.DivisionResult(divide.getN1(), divide.getN2(), divide.getN1() / divide.getN2())); + @Override + public void onReceive(Object message) throws Exception { - } else { - unhandled(message); - } + if (message instanceof Op.Multiply) { + Op.Multiply multiply = (Op.Multiply) message; + System.out.println("Calculating " + multiply.getN1() + " * " + + multiply.getN2()); + getSender().tell( + new Op.MultiplicationResult(multiply.getN1(), multiply.getN2(), + multiply.getN1() * multiply.getN2()), getSelf()); + + } else if (message instanceof Op.Divide) { + Op.Divide divide = (Op.Divide) message; + System.out.println("Calculating " + divide.getN1() + " / " + + divide.getN2()); + getSender().tell( + new Op.DivisionResult(divide.getN1(), divide.getN2(), divide.getN1() + / divide.getN2()), getSelf()); + + } else { + unhandled(message); } + } } -//#actor +// #actor diff --git a/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JCalcApp.java b/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JCalcApp.java index 1bd183fcf0..2e840a1ff4 100644 --- a/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JCalcApp.java +++ b/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JCalcApp.java @@ -5,9 +5,9 @@ package sample.remote.calculator.java; public class JCalcApp { - public static void main(String[] args) { - JCalculatorApplication app = new JCalculatorApplication(); - System.out.println("Started Calculator Application - waiting for messages"); - } + public static void main(String[] args) { + JCalculatorApplication app = new JCalculatorApplication(); + System.out.println("Started Calculator Application - waiting for messages"); + } } diff --git a/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JCalculatorApplication.java b/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JCalculatorApplication.java index 8699e92ca2..916af2f5f8 100644 --- a/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JCalculatorApplication.java +++ b/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JCalculatorApplication.java @@ -11,20 +11,22 @@ import com.typesafe.config.ConfigFactory; //#setup public class JCalculatorApplication implements Bootable { - private ActorSystem system; + private ActorSystem system; - public JCalculatorApplication() { - system = ActorSystem.create("CalculatorApplication", ConfigFactory.load().getConfig("calculator")); - ActorRef actor = system.actorOf(new Props(JSimpleCalculatorActor.class), "simpleCalculator"); - } + public JCalculatorApplication() { + system = ActorSystem.create("CalculatorApplication", ConfigFactory.load() + .getConfig("calculator")); + ActorRef actor = system.actorOf(new Props(JSimpleCalculatorActor.class), + "simpleCalculator"); + } - @Override - public void startup() { - } + @Override + public void startup() { + } - @Override - public void shutdown() { - system.shutdown(); - } + @Override + public void shutdown() { + system.shutdown(); + } } -//#setup \ No newline at end of file +// #setup \ No newline at end of file diff --git a/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JCreationApplication.java b/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JCreationApplication.java index 5b3d4f15a9..07a3a86d79 100644 --- a/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JCreationApplication.java +++ b/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JCreationApplication.java @@ -11,27 +11,29 @@ import com.typesafe.config.ConfigFactory; //#setup public class JCreationApplication implements Bootable { - private ActorSystem system; - private ActorRef actor; - private ActorRef remoteActor; + private ActorSystem system; + private ActorRef actor; + private ActorRef remoteActor; - public JCreationApplication() { - system = ActorSystem.create("CreationApplication", ConfigFactory.load().getConfig("remotecreation")); - actor = system.actorOf(new Props(JCreationActor.class)); - remoteActor = system.actorOf(new Props(JAdvancedCalculatorActor.class), "advancedCalculator"); - } + public JCreationApplication() { + system = ActorSystem.create("CreationApplication", ConfigFactory.load() + .getConfig("remotecreation")); + actor = system.actorOf(new Props(JCreationActor.class)); + remoteActor = system.actorOf(new Props(JAdvancedCalculatorActor.class), + "advancedCalculator"); + } - public void doSomething(Op.MathOp mathOp) { - actor.tell(new InternalMsg.MathOpMsg(remoteActor, mathOp)); - } + public void doSomething(Op.MathOp mathOp) { + actor.tell(new InternalMsg.MathOpMsg(remoteActor, mathOp), null); + } - @Override - public void startup() { - } + @Override + public void startup() { + } - @Override - public void shutdown() { - system.shutdown(); - } + @Override + public void shutdown() { + system.shutdown(); + } } -//#setup +// #setup diff --git a/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JLookupApplication.java b/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JLookupApplication.java index 5c2d050888..29294b6747 100644 --- a/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JLookupApplication.java +++ b/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JLookupApplication.java @@ -7,34 +7,35 @@ package sample.remote.calculator.java; import akka.actor.ActorRef; import akka.actor.ActorSystem; import akka.actor.Props; -import akka.actor.UntypedActor; import akka.kernel.Bootable; import com.typesafe.config.ConfigFactory; //#imports //#setup public class JLookupApplication implements Bootable { - private ActorSystem system; - private ActorRef actor; - private ActorRef remoteActor; + private ActorSystem system; + private ActorRef actor; + private ActorRef remoteActor; - public JLookupApplication() { - system = ActorSystem.create("LookupApplication", ConfigFactory.load().getConfig("remotelookup")); - actor = system.actorOf(new Props(JLookupActor.class)); - remoteActor = system.actorFor("akka://CalculatorApplication@127.0.0.1:2552/user/simpleCalculator"); - } + public JLookupApplication() { + system = ActorSystem.create("LookupApplication", ConfigFactory.load() + .getConfig("remotelookup")); + actor = system.actorOf(new Props(JLookupActor.class)); + remoteActor = system + .actorFor("akka://CalculatorApplication@127.0.0.1:2552/user/simpleCalculator"); + } - public void doSomething(Op.MathOp mathOp) { - actor.tell(new InternalMsg.MathOpMsg(remoteActor, mathOp)); - } + public void doSomething(Op.MathOp mathOp) { + actor.tell(new InternalMsg.MathOpMsg(remoteActor, mathOp), null); + } - @Override - public void startup() { - } + @Override + public void startup() { + } - @Override - public void shutdown() { - system.shutdown(); - } + @Override + public void shutdown() { + system.shutdown(); + } } -//#setup +// #setup diff --git a/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JSimpleCalculatorActor.java b/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JSimpleCalculatorActor.java index 1b3373d84c..958fb6bee4 100644 --- a/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JSimpleCalculatorActor.java +++ b/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/JSimpleCalculatorActor.java @@ -7,22 +7,28 @@ import akka.actor.UntypedActor; //#actor public class JSimpleCalculatorActor extends UntypedActor { - @Override - public void onReceive(Object message) { - - if (message instanceof Op.Add) { - Op.Add add = (Op.Add) message; - System.out.println("Calculating " + add.getN1() + " + " + add.getN2()); - getSender().tell(new Op.AddResult(add.getN1(), add.getN2(), add.getN1() + add.getN2())); - - } else if (message instanceof Op.Subtract) { - Op.Subtract subtract = (Op.Subtract) message; - System.out.println("Calculating " + subtract.getN1() + " - " + subtract.getN2()); - getSender().tell(new Op.SubtractResult(subtract.getN1(), subtract.getN2(), subtract.getN1() - subtract.getN2())); + @Override + public void onReceive(Object message) { - } else { - unhandled(message); - } + if (message instanceof Op.Add) { + Op.Add add = (Op.Add) message; + System.out.println("Calculating " + add.getN1() + " + " + add.getN2()); + getSender() + .tell( + new Op.AddResult(add.getN1(), add.getN2(), add.getN1() + + add.getN2()), getSelf()); + + } else if (message instanceof Op.Subtract) { + Op.Subtract subtract = (Op.Subtract) message; + System.out.println("Calculating " + subtract.getN1() + " - " + + subtract.getN2()); + getSender().tell( + new Op.SubtractResult(subtract.getN1(), subtract.getN2(), + subtract.getN1() - subtract.getN2()), getSelf()); + + } else { + unhandled(message); } + } } -//#actor +// #actor diff --git a/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/Op.java b/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/Op.java index 750d6dd705..17bd550d61 100644 --- a/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/Op.java +++ b/akka-samples/akka-sample-remote/src/main/java/sample/remote/calculator/java/Op.java @@ -7,175 +7,185 @@ import java.io.Serializable; public class Op { - public interface MathOp extends Serializable {} + public interface MathOp extends Serializable { + } - public interface MathResult extends Serializable {} + public interface MathResult extends Serializable { + } - static class Add implements MathOp { - private final int n1; - private final int n2; + static class Add implements MathOp { + private static final long serialVersionUID = 1L; + private final int n1; + private final int n2; - public Add(int n1, int n2) { - this.n1 = n1; - this.n2 = n2; - } - - public int getN1() { - return n1; - } - - public int getN2() { - return n2; - } - } - - static class AddResult implements MathResult { - private final int n1; - private final int n2; - private final int result; - - public AddResult(int n1, int n2, int result) { - this.n1 = n1; - this.n2 = n2; - this.result = result; - } - - public int getN1() { - return n1; - } - - public int getN2() { - return n2; - } - - public int getResult() { - return result; - } + public Add(int n1, int n2) { + this.n1 = n1; + this.n2 = n2; } - static class Subtract implements MathOp { - private final int n1; - private final int n2; - - public Subtract(int n1, int n2) { - this.n1 = n1; - this.n2 = n2; - } - - public int getN1() { - return n1; - } - - public int getN2() { - return n2; - } + public int getN1() { + return n1; } - static class SubtractResult implements MathResult { - private final int n1; - private final int n2; - private final int result; + public int getN2() { + return n2; + } + } - public SubtractResult(int n1, int n2, int result) { - this.n1 = n1; - this.n2 = n2; - this.result = result; - } + static class AddResult implements MathResult { + private static final long serialVersionUID = 1L; + private final int n1; + private final int n2; + private final int result; - public int getN1() { - return n1; - } - - public int getN2() { - return n2; - } - - public int getResult() { - return result; - } + public AddResult(int n1, int n2, int result) { + this.n1 = n1; + this.n2 = n2; + this.result = result; } - static class Multiply implements MathOp { - private final int n1; - private final int n2; - - public Multiply(int n1, int n2) { - this.n1 = n1; - this.n2 = n2; - } - - public int getN1() { - return n1; - } - - public int getN2() { - return n2; - } + public int getN1() { + return n1; } - static class MultiplicationResult implements MathResult { - private final int n1; - private final int n2; - private final int result; - - public MultiplicationResult(int n1, int n2, int result) { - this.n1 = n1; - this.n2 = n2; - this.result = result; - } - - public int getN1() { - return n1; - } - - public int getN2() { - return n2; - } - - public int getResult() { - return result; - } + public int getN2() { + return n2; } - static class Divide implements MathOp { - private final double n1; - private final int n2; + public int getResult() { + return result; + } + } - public Divide(double n1, int n2) { - this.n1 = n1; - this.n2 = n2; - } + static class Subtract implements MathOp { + private static final long serialVersionUID = 1L; + private final int n1; + private final int n2; - public double getN1() { - return n1; - } - - public int getN2() { - return n2; - } + public Subtract(int n1, int n2) { + this.n1 = n1; + this.n2 = n2; } - static class DivisionResult implements MathResult { - private final double n1; - private final int n2; - private final double result; - - public DivisionResult(double n1, int n2, double result) { - this.n1 = n1; - this.n2 = n2; - this.result = result; - } - - public double getN1() { - return n1; - } - - public int getN2() { - return n2; - } - - public double getResult() { - return result; - } + public int getN1() { + return n1; } + + public int getN2() { + return n2; + } + } + + static class SubtractResult implements MathResult { + private static final long serialVersionUID = 1L; + private final int n1; + private final int n2; + private final int result; + + public SubtractResult(int n1, int n2, int result) { + this.n1 = n1; + this.n2 = n2; + this.result = result; + } + + public int getN1() { + return n1; + } + + public int getN2() { + return n2; + } + + public int getResult() { + return result; + } + } + + static class Multiply implements MathOp { + private static final long serialVersionUID = 1L; + private final int n1; + private final int n2; + + public Multiply(int n1, int n2) { + this.n1 = n1; + this.n2 = n2; + } + + public int getN1() { + return n1; + } + + public int getN2() { + return n2; + } + } + + static class MultiplicationResult implements MathResult { + private static final long serialVersionUID = 1L; + private final int n1; + private final int n2; + private final int result; + + public MultiplicationResult(int n1, int n2, int result) { + this.n1 = n1; + this.n2 = n2; + this.result = result; + } + + public int getN1() { + return n1; + } + + public int getN2() { + return n2; + } + + public int getResult() { + return result; + } + } + + static class Divide implements MathOp { + private static final long serialVersionUID = 1L; + private final double n1; + private final int n2; + + public Divide(double n1, int n2) { + this.n1 = n1; + this.n2 = n2; + } + + public double getN1() { + return n1; + } + + public int getN2() { + return n2; + } + } + + static class DivisionResult implements MathResult { + private static final long serialVersionUID = 1L; + private final double n1; + private final int n2; + private final double result; + + public DivisionResult(double n1, int n2, double result) { + this.n1 = n1; + this.n2 = n2; + this.result = result; + } + + public double getN1() { + return n1; + } + + public int getN2() { + return n2; + } + + public double getResult() { + return result; + } + } } diff --git a/akka-transactor/src/main/scala/akka/transactor/UntypedTransactor.scala b/akka-transactor/src/main/scala/akka/transactor/UntypedTransactor.scala index 353695fd73..98899e0a13 100644 --- a/akka-transactor/src/main/scala/akka/transactor/UntypedTransactor.scala +++ b/akka-transactor/src/main/scala/akka/transactor/UntypedTransactor.scala @@ -23,7 +23,7 @@ abstract class UntypedTransactor extends UntypedActor { case coordinated @ Coordinated(message) ⇒ { val others = coordinate(message) for (sendTo ← others) { - sendTo.actor.tell(coordinated(sendTo.message.getOrElse(message))) + sendTo.actor ! coordinated(sendTo.message.getOrElse(message)) } before(message) coordinated.atomic { txn ⇒ atomically(message) } diff --git a/akka-transactor/src/test/java/akka/transactor/UntypedCoordinatedCounter.java b/akka-transactor/src/test/java/akka/transactor/UntypedCoordinatedCounter.java index 8760db5084..d1b3140416 100644 --- a/akka-transactor/src/test/java/akka/transactor/UntypedCoordinatedCounter.java +++ b/akka-transactor/src/test/java/akka/transactor/UntypedCoordinatedCounter.java @@ -4,13 +4,13 @@ package akka.transactor; -import akka.actor.ActorRef; -import akka.actor.UntypedActor; -import scala.concurrent.stm.Ref; -import scala.concurrent.stm.japi.STM; import java.util.List; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; + +import scala.concurrent.stm.Ref; +import scala.concurrent.stm.japi.STM; +import akka.actor.ActorRef; +import akka.actor.UntypedActor; public class UntypedCoordinatedCounter extends UntypedActor { private String name; @@ -35,7 +35,7 @@ public class UntypedCoordinatedCounter extends UntypedActor { }; if (!friends.isEmpty()) { Increment coordMessage = new Increment(friends.subList(1, friends.size()), latch); - friends.get(0).tell(coordinated.coordinate(coordMessage)); + friends.get(0).tell(coordinated.coordinate(coordMessage), getSelf()); } coordinated.atomic(new Runnable() { public void run() { @@ -45,7 +45,7 @@ public class UntypedCoordinatedCounter extends UntypedActor { }); } } else if ("GetCount".equals(incoming)) { - getSender().tell(count.get()); + getSender().tell(count.get(), getSelf()); } } } diff --git a/akka-transactor/src/test/java/akka/transactor/UntypedCoordinatedIncrementTest.java b/akka-transactor/src/test/java/akka/transactor/UntypedCoordinatedIncrementTest.java index 60c4873b27..5aecd341e0 100644 --- a/akka-transactor/src/test/java/akka/transactor/UntypedCoordinatedIncrementTest.java +++ b/akka-transactor/src/test/java/akka/transactor/UntypedCoordinatedIncrementTest.java @@ -75,7 +75,7 @@ public class UntypedCoordinatedIncrementTest { public void incrementAllCountersWithSuccessfulTransaction() throws Exception { CountDownLatch incrementLatch = new CountDownLatch(numCounters); Increment message = new Increment(counters.subList(1, counters.size()), incrementLatch); - counters.get(0).tell(new Coordinated(message, timeout)); + counters.get(0).tell(new Coordinated(message, timeout), null); try { incrementLatch.await(timeoutSeconds, TimeUnit.SECONDS); } catch (InterruptedException exception) { @@ -97,7 +97,7 @@ public class UntypedCoordinatedIncrementTest { List actors = new ArrayList(counters); actors.add(failer); Increment message = new Increment(actors.subList(1, actors.size()), incrementLatch); - actors.get(0).tell(new Coordinated(message, timeout)); + actors.get(0).tell(new Coordinated(message, timeout), null); try { incrementLatch.await(timeoutSeconds, TimeUnit.SECONDS); } catch (InterruptedException exception) { diff --git a/akka-transactor/src/test/java/akka/transactor/UntypedCounter.java b/akka-transactor/src/test/java/akka/transactor/UntypedCounter.java index 452e528a5c..1437adc805 100644 --- a/akka-transactor/src/test/java/akka/transactor/UntypedCounter.java +++ b/akka-transactor/src/test/java/akka/transactor/UntypedCounter.java @@ -4,15 +4,12 @@ package akka.transactor; -import akka.actor.ActorRef; -import akka.transactor.UntypedTransactor; -import akka.transactor.SendTo; -import scala.concurrent.stm.Ref; -import scala.concurrent.stm.japi.STM; import java.util.List; import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; + +import scala.concurrent.stm.Ref; +import scala.concurrent.stm.japi.STM; +import akka.actor.ActorRef; public class UntypedCounter extends UntypedTransactor { private String name; @@ -52,7 +49,7 @@ public class UntypedCounter extends UntypedTransactor { @Override public boolean normally(Object message) { if ("GetCount".equals(message)) { - getSender().tell(count.get()); + getSender().tell(count.get(), getSelf()); return true; } else return false; } diff --git a/akka-transactor/src/test/java/akka/transactor/UntypedFailer.java b/akka-transactor/src/test/java/akka/transactor/UntypedFailer.java index 2bc1c556d8..1e9b67998d 100644 --- a/akka-transactor/src/test/java/akka/transactor/UntypedFailer.java +++ b/akka-transactor/src/test/java/akka/transactor/UntypedFailer.java @@ -4,8 +4,6 @@ package akka.transactor; -import scala.concurrent.stm.InTxn; - public class UntypedFailer extends UntypedTransactor { public void atomically(Object message) throws Exception { throw new ExpectedFailureException(); diff --git a/akka-transactor/src/test/java/akka/transactor/UntypedTransactorTest.java b/akka-transactor/src/test/java/akka/transactor/UntypedTransactorTest.java index b24d000ced..5aae61d9c1 100644 --- a/akka-transactor/src/test/java/akka/transactor/UntypedTransactorTest.java +++ b/akka-transactor/src/test/java/akka/transactor/UntypedTransactorTest.java @@ -63,6 +63,8 @@ public class UntypedTransactorTest { for (int i = 1; i <= numCounters; i++) { final String name = "counter" + i; ActorRef counter = system.actorOf(new Props(new UntypedActorFactory() { + private static final long serialVersionUID = 1L; + public UntypedActor create() { return new UntypedCounter(name); } @@ -75,8 +77,9 @@ public class UntypedTransactorTest { @Test public void incrementAllCountersWithSuccessfulTransaction() throws Exception { CountDownLatch incrementLatch = new CountDownLatch(numCounters); - Increment message = new Increment(counters.subList(1, counters.size()), incrementLatch); - counters.get(0).tell(message); + Increment message = new Increment(counters.subList(1, counters.size()), + incrementLatch); + counters.get(0).tell(message, null); try { incrementLatch.await(timeoutSeconds, TimeUnit.SECONDS); } catch (InterruptedException exception) { @@ -90,15 +93,19 @@ public class UntypedTransactorTest { @Test public void incrementNoCountersWithFailingTransaction() throws Exception { - EventFilter expectedFailureFilter = (EventFilter) new ErrorFilter(ExpectedFailureException.class); - EventFilter coordinatedFilter = (EventFilter) new ErrorFilter(CoordinatedTransactionException.class); - Seq ignoreExceptions = seq(expectedFailureFilter, coordinatedFilter); + EventFilter expectedFailureFilter = (EventFilter) new ErrorFilter( + ExpectedFailureException.class); + EventFilter coordinatedFilter = (EventFilter) new ErrorFilter( + CoordinatedTransactionException.class); + Seq ignoreExceptions = seq(expectedFailureFilter, + coordinatedFilter); system.eventStream().publish(new TestEvent.Mute(ignoreExceptions)); CountDownLatch incrementLatch = new CountDownLatch(numCounters); List actors = new ArrayList(counters); actors.add(failer); - Increment message = new Increment(actors.subList(1, actors.size()), incrementLatch); - actors.get(0).tell(message); + Increment message = new Increment(actors.subList(1, actors.size()), + incrementLatch); + actors.get(0).tell(message, null); try { incrementLatch.await(timeoutSeconds, TimeUnit.SECONDS); } catch (InterruptedException exception) { @@ -111,6 +118,8 @@ public class UntypedTransactorTest { } public Seq seq(A... args) { - return JavaConverters.collectionAsScalaIterableConverter(Arrays.asList(args)).asScala().toSeq(); + return JavaConverters + .collectionAsScalaIterableConverter(Arrays.asList(args)).asScala() + .toSeq(); } }