Merge pull request #1529 from akka/wip-3429-ActorRef.noSender-∂π

add ActorRef.noSender() for the Java API, see #3429
This commit is contained in:
Roland Kuhn 2013-06-20 06:51:54 -07:00
commit 6d8e13c760
24 changed files with 92 additions and 79 deletions

View file

@ -13,6 +13,16 @@ import scala.annotation.tailrec
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
import akka.event.LoggingAdapter import akka.event.LoggingAdapter
object ActorRef {
/**
* Use this value as an argument to [[#tell]] if there is not actor to
* reply to (e.g. when sending from non-actor code).
*/
final val noSender: ActorRef = Actor.noSender
}
/** /**
* Immutable and serializable handle to an actor, which may or may not reside * Immutable and serializable handle to an actor, which may or may not reside
* on the local host or inside the same [[akka.actor.ActorSystem]]. An ActorRef * on the local host or inside the same [[akka.actor.ActorSystem]]. An ActorRef

View file

@ -189,11 +189,11 @@ public class FSMDocTest {
public void mustBunch() { public void mustBunch() {
final ActorRef buncher = system.actorOf(Props.create(MyFSM.class)); final ActorRef buncher = system.actorOf(Props.create(MyFSM.class));
final TestProbe probe = new TestProbe(system); final TestProbe probe = new TestProbe(system);
buncher.tell(new SetTarget(probe.ref()), null); buncher.tell(new SetTarget(probe.ref()), ActorRef.noSender());
buncher.tell(new Queue(1), null); buncher.tell(new Queue(1), ActorRef.noSender());
buncher.tell(new Queue(2), null); buncher.tell(new Queue(2), ActorRef.noSender());
buncher.tell(flush, null); buncher.tell(flush, ActorRef.noSender());
buncher.tell(new Queue(3), null); buncher.tell(new Queue(3), ActorRef.noSender());
final Batch b = probe.expectMsgClass(Batch.class); final Batch b = probe.expectMsgClass(Batch.class);
assert b.objects.size() == 2; assert b.objects.size() == 2;
assert b.objects.contains(1); assert b.objects.contains(1);

View file

@ -179,21 +179,21 @@ public class FaultHandlingTest {
//#create //#create
//#resume //#resume
child.tell(42, null); child.tell(42, ActorRef.noSender());
assert Await.result(ask(child, "get", 5000), timeout).equals(42); assert Await.result(ask(child, "get", 5000), timeout).equals(42);
child.tell(new ArithmeticException(), null); child.tell(new ArithmeticException(), ActorRef.noSender());
assert Await.result(ask(child, "get", 5000), timeout).equals(42); assert Await.result(ask(child, "get", 5000), timeout).equals(42);
//#resume //#resume
//#restart //#restart
child.tell(new NullPointerException(), null); child.tell(new NullPointerException(), ActorRef.noSender());
assert Await.result(ask(child, "get", 5000), timeout).equals(0); assert Await.result(ask(child, "get", 5000), timeout).equals(0);
//#restart //#restart
//#stop //#stop
final TestProbe probe = new TestProbe(system); final TestProbe probe = new TestProbe(system);
probe.watch(child); probe.watch(child);
child.tell(new IllegalArgumentException(), null); child.tell(new IllegalArgumentException(), ActorRef.noSender());
probe.expectMsgClass(Terminated.class); probe.expectMsgClass(Terminated.class);
//#stop //#stop
@ -202,7 +202,7 @@ public class FaultHandlingTest {
Props.create(Child.class), 5000), timeout); Props.create(Child.class), 5000), timeout);
probe.watch(child); probe.watch(child);
assert Await.result(ask(child, "get", 5000), timeout).equals(0); assert Await.result(ask(child, "get", 5000), timeout).equals(0);
child.tell(new Exception(), null); child.tell(new Exception(), ActorRef.noSender());
probe.expectMsgClass(Terminated.class); probe.expectMsgClass(Terminated.class);
//#escalate-kill //#escalate-kill
@ -211,9 +211,9 @@ public class FaultHandlingTest {
supervisor = system.actorOf(superprops); supervisor = system.actorOf(superprops);
child = (ActorRef) Await.result(ask(supervisor, child = (ActorRef) Await.result(ask(supervisor,
Props.create(Child.class), 5000), timeout); Props.create(Child.class), 5000), timeout);
child.tell(23, null); child.tell(23, ActorRef.noSender());
assert Await.result(ask(child, "get", 5000), timeout).equals(23); assert Await.result(ask(child, "get", 5000), timeout).equals(23);
child.tell(new Exception(), null); child.tell(new Exception(), ActorRef.noSender());
assert Await.result(ask(child, "get", 5000), timeout).equals(0); assert Await.result(ask(child, "get", 5000), timeout).equals(0);
//#escalate-restart //#escalate-restart
//#testkit //#testkit

View file

@ -16,6 +16,6 @@ public class FirstUntypedActor extends UntypedActor {
public void onReceive(Object message) { public void onReceive(Object message) {
myActor.forward(message, getContext()); myActor.forward(message, getContext());
myActor.tell(PoisonPill.getInstance(), null); myActor.tell(PoisonPill.getInstance(), ActorRef.noSender());
} }
} }

View file

@ -49,7 +49,7 @@ public class InboxDocTest {
//#watch //#watch
final Inbox inbox = Inbox.create(system); final Inbox inbox = Inbox.create(system);
inbox.watch(target); inbox.watch(target);
target.tell(PoisonPill.getInstance(), null); target.tell(PoisonPill.getInstance(), ActorRef.noSender());
assert inbox.receive(Duration.create(1, TimeUnit.SECONDS)) instanceof Terminated; assert inbox.receive(Duration.create(1, TimeUnit.SECONDS)) instanceof Terminated;
//#watch //#watch
} }

View file

@ -41,7 +41,7 @@ public class SchedulerDocTest {
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
testActor.tell(System.currentTimeMillis(), null); testActor.tell(System.currentTimeMillis(), ActorRef.noSender());
} }
}, system.dispatcher()); }, system.dispatcher());
//#schedule-one-off-thunk //#schedule-one-off-thunk

View file

@ -370,7 +370,7 @@ public class UntypedActorDocTest {
master.tell("", getRef()); master.tell("", getRef());
final ActorRef victim = expectMsgClass(ActorRef.class); final ActorRef victim = expectMsgClass(ActorRef.class);
//#kill //#kill
victim.tell(akka.actor.Kill.getInstance(), null); victim.tell(akka.actor.Kill.getInstance(), ActorRef.noSender());
//#kill //#kill
expectMsgEquals("killed"); expectMsgEquals("killed");
expectMsgEquals("stopped"); expectMsgEquals("stopped");

View file

@ -44,12 +44,12 @@ public class UntypedActorSwapper {
public static void main(String... args) { public static void main(String... args) {
ActorSystem system = ActorSystem.create("MySystem"); ActorSystem system = ActorSystem.create("MySystem");
ActorRef swap = system.actorOf(Props.create(Swapper.class)); ActorRef swap = system.actorOf(Props.create(Swapper.class));
swap.tell(SWAP, null); // logs Hi swap.tell(SWAP, ActorRef.noSender()); // logs Hi
swap.tell(SWAP, null); // logs Ho swap.tell(SWAP, ActorRef.noSender()); // logs Ho
swap.tell(SWAP, null); // logs Hi swap.tell(SWAP, ActorRef.noSender()); // logs Hi
swap.tell(SWAP, null); // logs Ho swap.tell(SWAP, ActorRef.noSender()); // logs Ho
swap.tell(SWAP, null); // logs Hi swap.tell(SWAP, ActorRef.noSender()); // logs Hi
swap.tell(SWAP, null); // logs Ho swap.tell(SWAP, ActorRef.noSender()); // logs Ho
} }
} }

View file

@ -33,7 +33,7 @@ public class DurableMailboxDocTest {
ActorRef myActor = system.actorOf(Props.create(MyUntypedActor.class). ActorRef myActor = system.actorOf(Props.create(MyUntypedActor.class).
withDispatcher("my-dispatcher"), "myactor"); withDispatcher("my-dispatcher"), "myactor");
//#dispatcher-config-use //#dispatcher-config-use
myActor.tell("test", null); myActor.tell("test", ActorRef.noSender());
} }
public static class MyUntypedActor extends UntypedActor { public static class MyUntypedActor extends UntypedActor {

View file

@ -14,7 +14,7 @@ public class OnRouteResponseTestBase {
Forwarder.class, "http://localhost:8080/news/akka", receiver)); Forwarder.class, "http://localhost:8080/news/akka", receiver));
// the Forwarder sends out a request to the web page and forwards the response to // the Forwarder sends out a request to the web page and forwards the response to
// the ResponseReceiver // the ResponseReceiver
forwardResponse.tell("some request", null); forwardResponse.tell("some request", ActorRef.noSender());
//#RouteResponse //#RouteResponse
system.stop(receiver); system.stop(receiver);
system.stop(forwardResponse); system.stop(forwardResponse);

View file

@ -17,7 +17,8 @@ public class ProducerTestBase {
ActorSystem system = ActorSystem.create("some-system"); ActorSystem system = ActorSystem.create("some-system");
Props props = Props.create(Orders.class); Props props = Props.create(Orders.class);
ActorRef producer = system.actorOf(props, "jmsproducer"); ActorRef producer = system.actorOf(props, "jmsproducer");
producer.tell("<order amount=\"100\" currency=\"PLN\" itemId=\"12345\"/>", null); producer.tell("<order amount=\"100\" currency=\"PLN\" itemId=\"12345\"/>",
ActorRef.noSender());
//#TellProducer //#TellProducer
JavaTestKit.shutdownActorSystem(system); JavaTestKit.shutdownActorSystem(system);
} }
@ -42,7 +43,7 @@ public class ProducerTestBase {
Map<String,Object> headers = new HashMap<String, Object>(); Map<String,Object> headers = new HashMap<String, Object>();
headers.put(CamelMessage.MessageExchangeId(),"123"); headers.put(CamelMessage.MessageExchangeId(),"123");
producer.tell(new CamelMessage("<order amount=\"100\" currency=\"PLN\" " + producer.tell(new CamelMessage("<order amount=\"100\" currency=\"PLN\" " +
"itemId=\"12345\"/>",headers), null); "itemId=\"12345\"/>",headers), ActorRef.noSender());
//#Correlate //#Correlate
system.stop(producer); system.stop(producer);
JavaTestKit.shutdownActorSystem(system); JavaTestKit.shutdownActorSystem(system);

View file

@ -36,7 +36,7 @@ public class LoggingDocTest {
public void useLoggingActor() { public void useLoggingActor() {
ActorSystem system = ActorSystem.create("MySystem"); ActorSystem system = ActorSystem.create("MySystem");
ActorRef myActor = system.actorOf(Props.create(MyActor.class, this)); ActorRef myActor = system.actorOf(Props.create(MyActor.class, this));
myActor.tell("test", null); myActor.tell("test", ActorRef.noSender());
JavaTestKit.shutdownActorSystem(system); JavaTestKit.shutdownActorSystem(system);
} }

View file

@ -24,8 +24,8 @@ public class EchoServer {
final ActorRef watcher = system.actorOf(Props.create(Watcher.class, latch), "watcher"); final ActorRef watcher = system.actorOf(Props.create(Watcher.class, latch), "watcher");
final ActorRef nackServer = system.actorOf(Props.create(EchoManager.class, EchoHandler.class), "nack"); final ActorRef nackServer = system.actorOf(Props.create(EchoManager.class, EchoHandler.class), "nack");
final ActorRef ackServer = system.actorOf(Props.create(EchoManager.class, SimpleEchoHandler.class), "ack"); final ActorRef ackServer = system.actorOf(Props.create(EchoManager.class, SimpleEchoHandler.class), "ack");
watcher.tell(nackServer, null); watcher.tell(nackServer, ActorRef.noSender());
watcher.tell(ackServer, null); watcher.tell(ackServer, ActorRef.noSender());
latch.await(10, TimeUnit.MINUTES); latch.await(10, TimeUnit.MINUTES);
} finally { } finally {
system.shutdown(); system.shutdown();

View file

@ -95,7 +95,7 @@ public class MessageStage extends
if (cmd instanceof PipelineTest.SetTarget) { if (cmd instanceof PipelineTest.SetTarget) {
target = ((PipelineTest.SetTarget) cmd).getRef(); target = ((PipelineTest.SetTarget) cmd).getRef();
} else if (cmd instanceof TickGenerator.Tick && target != null) { } else if (cmd instanceof TickGenerator.Tick && target != null) {
target.tell(cmd, null); target.tell(cmd, ActorRef.noSender());
} }
//#omitted //#omitted
if (cmd instanceof TickGenerator.Tick) { if (cmd instanceof TickGenerator.Tick) {

View file

@ -72,12 +72,12 @@ public class PipelineTest {
@Override @Override
public void onCommand(ByteString cmd) throws Throwable { public void onCommand(ByteString cmd) throws Throwable {
commandHandler.tell(cmd, null); commandHandler.tell(cmd, ActorRef.noSender());
} }
@Override @Override
public void onEvent(Message evt) throws Throwable { public void onEvent(Message evt) throws Throwable {
eventHandler.tell(evt, null); eventHandler.tell(evt, ActorRef.noSender());
} }
}; };
@ -127,9 +127,9 @@ public class PipelineTest {
final ActorRef proc = system.actorOf(Props.create( final ActorRef proc = system.actorOf(Props.create(
P.class, this, getRef(), getRef()), "processor"); P.class, this, getRef(), getRef()), "processor");
expectMsgClass(TickGenerator.Tick.class); expectMsgClass(TickGenerator.Tick.class);
proc.tell(msg, null); proc.tell(msg, ActorRef.noSender());
final ByteString encoded = expectMsgClass(ByteString.class); final ByteString encoded = expectMsgClass(ByteString.class);
proc.tell(encoded, null); proc.tell(encoded, ActorRef.noSender());
final Message decoded = expectMsgClass(Message.class); final Message decoded = expectMsgClass(Message.class);
assert msg == decoded; assert msg == decoded;
@ -140,13 +140,13 @@ public class PipelineTest {
expectMsgClass(TickGenerator.Tick.class); expectMsgClass(TickGenerator.Tick.class);
} }
}; };
proc.tell("fail!", null); proc.tell("fail!", ActorRef.noSender());
new Within(Duration.create(1700, TimeUnit.MILLISECONDS), new Within(Duration.create(1700, TimeUnit.MILLISECONDS),
Duration.create(3, TimeUnit.SECONDS)) { Duration.create(3, TimeUnit.SECONDS)) {
protected void run() { protected void run() {
expectMsgClass(TickGenerator.Tick.class); expectMsgClass(TickGenerator.Tick.class);
expectMsgClass(TickGenerator.Tick.class); expectMsgClass(TickGenerator.Tick.class);
proc.tell(PoisonPill.getInstance(), null); proc.tell(PoisonPill.getInstance(), ActorRef.noSender());
expectNoMsg(); expectNoMsg();
} }
}; };

View file

@ -9,6 +9,7 @@ import java.util.Collections;
import scala.concurrent.duration.Deadline; import scala.concurrent.duration.Deadline;
import scala.concurrent.duration.FiniteDuration; import scala.concurrent.duration.FiniteDuration;
import scala.util.Either; import scala.util.Either;
import akka.actor.ActorRef;
import akka.actor.ActorSystem; import akka.actor.ActorSystem;
import akka.io.AbstractPipePair; import akka.io.AbstractPipePair;
import akka.io.PipePair; import akka.io.PipePair;
@ -74,7 +75,8 @@ public class TickGenerator<Cmd, Evt> extends
@Override @Override
public Iterable<Either<Evt, Cmd>> onManagementCommand(Object cmd) { public Iterable<Either<Evt, Cmd>> onManagementCommand(Object cmd) {
if (cmd == trigger) { if (cmd == trigger) {
ctx.getContext().self().tell(new Tick(Deadline.now().time()), null); ctx.getContext().self().tell(new Tick(Deadline.now().time()),
ActorRef.noSender());
schedule(); schedule();
} }
return Collections.emptyList(); return Collections.emptyList();

View file

@ -77,11 +77,11 @@ public class CustomRouterDocTest {
public void countVotesAsIntendedNotAsInFlorida() throws Exception { public void countVotesAsIntendedNotAsInFlorida() throws Exception {
ActorRef routedActor = system.actorOf( ActorRef routedActor = system.actorOf(
Props.empty().withRouter(new VoteCountRouter())); Props.empty().withRouter(new VoteCountRouter()));
routedActor.tell(DemocratVote, null); routedActor.tell(DemocratVote, ActorRef.noSender());
routedActor.tell(DemocratVote, null); routedActor.tell(DemocratVote, ActorRef.noSender());
routedActor.tell(RepublicanVote, null); routedActor.tell(RepublicanVote, ActorRef.noSender());
routedActor.tell(DemocratVote, null); routedActor.tell(DemocratVote, ActorRef.noSender());
routedActor.tell(RepublicanVote, null); routedActor.tell(RepublicanVote, ActorRef.noSender());
Timeout timeout = new Timeout(Duration.create(1, "seconds")); Timeout timeout = new Timeout(Duration.create(1, "seconds"));
Future<Object> democratsResult = Future<Object> democratsResult =
ask(routedActor, DemocratCountResult, timeout); ask(routedActor, DemocratCountResult, timeout);

View file

@ -47,7 +47,7 @@ public class RouterViaConfigExample {
Props.create(ExampleActor.class).withRouter(new FromConfig()), "myrouter1"); Props.create(ExampleActor.class).withRouter(new FromConfig()), "myrouter1");
//#configurableRouting //#configurableRouting
for (int i = 1; i <= 10; i++) { for (int i = 1; i <= 10; i++) {
router.tell(new ExampleActor.Message(i), null); router.tell(new ExampleActor.Message(i), ActorRef.noSender());
} }
//#configurableRoutingWithResizer //#configurableRoutingWithResizer
@ -55,7 +55,7 @@ public class RouterViaConfigExample {
Props.create(ExampleActor.class).withRouter(new FromConfig()), "myrouter2"); Props.create(ExampleActor.class).withRouter(new FromConfig()), "myrouter2");
//#configurableRoutingWithResizer //#configurableRoutingWithResizer
for (int i = 1; i <= 10; i++) { for (int i = 1; i <= 10; i++) {
router2.tell(new ExampleActor.Message(i), null); router2.tell(new ExampleActor.Message(i), ActorRef.noSender());
} }
} }
} }

View file

@ -55,7 +55,7 @@ public class RouterViaProgramDocTest {
Props.empty().withRouter(new RoundRobinRouter(routees))); Props.empty().withRouter(new RoundRobinRouter(routees)));
//#programmaticRoutingRouteePaths //#programmaticRoutingRouteePaths
for (int i = 1; i <= 6; i++) { for (int i = 1; i <= 6; i++) {
router.tell(new ExampleActor.Message(i), null); router.tell(new ExampleActor.Message(i), ActorRef.noSender());
} }
}}; }};
} }

View file

@ -50,7 +50,7 @@ public class RouterViaProgramExample {
Props.create(ExampleActor.class).withRouter(new RoundRobinRouter(nrOfInstances))); Props.create(ExampleActor.class).withRouter(new RoundRobinRouter(nrOfInstances)));
//#programmaticRoutingNrOfInstances //#programmaticRoutingNrOfInstances
for (int i = 1; i <= 6; i++) { for (int i = 1; i <= 6; i++) {
router1.tell(new ExampleActor.Message(i), null); router1.tell(new ExampleActor.Message(i), ActorRef.noSender());
} }
//#programmaticRoutingRoutees //#programmaticRoutingRoutees
@ -63,7 +63,7 @@ public class RouterViaProgramExample {
Props.empty().withRouter(RoundRobinRouter.create(routees))); Props.empty().withRouter(RoundRobinRouter.create(routees)));
//#programmaticRoutingRoutees //#programmaticRoutingRoutees
for (int i = 1; i <= 6; i++) { for (int i = 1; i <= 6; i++) {
router2.tell(new ExampleActor.Message(i), null); router2.tell(new ExampleActor.Message(i), ActorRef.noSender());
} }
//#programmaticRoutingWithResizer //#programmaticRoutingWithResizer
@ -74,7 +74,7 @@ public class RouterViaProgramExample {
Props.create(ExampleActor.class).withRouter(new RoundRobinRouter(resizer))); Props.create(ExampleActor.class).withRouter(new RoundRobinRouter(resizer)));
//#programmaticRoutingWithResizer //#programmaticRoutingWithResizer
for (int i = 1; i <= 6; i++) { for (int i = 1; i <= 6; i++) {
router3.tell(new ExampleActor.Message(i), null); router3.tell(new ExampleActor.Message(i), ActorRef.noSender());
} }
//#remoteRoutees //#remoteRoutees

View file

@ -53,7 +53,7 @@ public class RemoteDeploymentDocTest {
//#sample-actor //#sample-actor
ActorRef actor = system.actorOf(Props.create(SampleActor.class), "sampleActor"); ActorRef actor = system.actorOf(Props.create(SampleActor.class), "sampleActor");
actor.tell("Pretty slick", null); actor.tell("Pretty slick", ActorRef.noSender());
//#sample-actor //#sample-actor
} }

View file

@ -84,7 +84,7 @@ public class TestKitDocTest {
public void demonstrateWithin() { public void demonstrateWithin() {
//#test-within //#test-within
new JavaTestKit(system) {{ new JavaTestKit(system) {{
getRef().tell(42, null); getRef().tell(42, ActorRef.noSender());
new Within(Duration.Zero(), Duration.create(1, "second")) { new Within(Duration.Zero(), Duration.create(1, "second")) {
// do not put code outside this method, will run afterwards // do not put code outside this method, will run afterwards
public void run() { public void run() {
@ -99,7 +99,7 @@ public class TestKitDocTest {
public void demonstrateExpectMsg() { public void demonstrateExpectMsg() {
//#test-expectmsg //#test-expectmsg
new JavaTestKit(system) {{ new JavaTestKit(system) {{
getRef().tell(42, null); getRef().tell(42, ActorRef.noSender());
final String out = new ExpectMsg<String>("match hint") { final String out = new ExpectMsg<String>("match hint") {
// do not put code outside this method, will run afterwards // do not put code outside this method, will run afterwards
protected String match(Object in) { protected String match(Object in) {
@ -119,9 +119,9 @@ public class TestKitDocTest {
public void demonstrateReceiveWhile() { public void demonstrateReceiveWhile() {
//#test-receivewhile //#test-receivewhile
new JavaTestKit(system) {{ new JavaTestKit(system) {{
getRef().tell(42, null); getRef().tell(42, ActorRef.noSender());
getRef().tell(43, null); getRef().tell(43, ActorRef.noSender());
getRef().tell("hello", null); getRef().tell("hello", ActorRef.noSender());
final String[] out = final String[] out =
new ReceiveWhile<String>(String.class, duration("1 second")) { new ReceiveWhile<String>(String.class, duration("1 second")) {
// do not put code outside this method, will run afterwards // do not put code outside this method, will run afterwards
@ -159,7 +159,7 @@ public class TestKitDocTest {
public void demonstrateAwaitCond() { public void demonstrateAwaitCond() {
//#test-awaitCond //#test-awaitCond
new JavaTestKit(system) {{ new JavaTestKit(system) {{
getRef().tell(42, null); getRef().tell(42, ActorRef.noSender());
new AwaitCond( new AwaitCond(
duration("1 second"), // maximum wait time duration("1 second"), // maximum wait time
duration("100 millis") // interval at which to check the condition duration("100 millis") // interval at which to check the condition
@ -178,7 +178,7 @@ public class TestKitDocTest {
public void demonstrateAwaitAssert() { public void demonstrateAwaitAssert() {
//#test-awaitAssert //#test-awaitAssert
new JavaTestKit(system) {{ new JavaTestKit(system) {{
getRef().tell(42, null); getRef().tell(42, ActorRef.noSender());
new AwaitAssert( new AwaitAssert(
duration("1 second"), // maximum wait time duration("1 second"), // maximum wait time
duration("100 millis") // interval at which to check the condition duration("100 millis") // interval at which to check the condition
@ -196,12 +196,12 @@ public class TestKitDocTest {
@SuppressWarnings({ "unchecked", "unused" }) // due to generic varargs @SuppressWarnings({ "unchecked", "unused" }) // due to generic varargs
public void demonstrateExpect() { public void demonstrateExpect() {
new JavaTestKit(system) {{ new JavaTestKit(system) {{
getRef().tell("hello", null); getRef().tell("hello", ActorRef.noSender());
getRef().tell("hello", null); getRef().tell("hello", ActorRef.noSender());
getRef().tell("hello", null); getRef().tell("hello", ActorRef.noSender());
getRef().tell("world", null); getRef().tell("world", ActorRef.noSender());
getRef().tell(42, null); getRef().tell(42, ActorRef.noSender());
getRef().tell(42, null); getRef().tell(42, ActorRef.noSender());
//#test-expect //#test-expect
final String hello = expectMsgEquals("hello"); final String hello = expectMsgEquals("hello");
final Object any = expectMsgAnyOf("hello", "world"); final Object any = expectMsgAnyOf("hello", "world");
@ -210,8 +210,8 @@ public class TestKitDocTest {
final Number j = expectMsgAnyClassOf(Integer.class, Long.class); final Number j = expectMsgAnyClassOf(Integer.class, Long.class);
expectNoMsg(); expectNoMsg();
//#test-expect //#test-expect
getRef().tell("receveN-1", null); getRef().tell("receveN-1", ActorRef.noSender());
getRef().tell("receveN-2", null); getRef().tell("receveN-2", ActorRef.noSender());
//#test-expect //#test-expect
final Object[] two = receiveN(2); final Object[] two = receiveN(2);
//#test-expect //#test-expect
@ -233,12 +233,12 @@ public class TestKitDocTest {
return msg instanceof String; return msg instanceof String;
} }
}; };
getRef().tell("hello", null); getRef().tell("hello", ActorRef.noSender());
getRef().tell(42, null); getRef().tell(42, ActorRef.noSender());
expectMsgEquals(42); expectMsgEquals(42);
// remove message filter // remove message filter
ignoreNoMsg(); ignoreNoMsg();
getRef().tell("hello", null); getRef().tell("hello", ActorRef.noSender());
expectMsgEquals("hello"); expectMsgEquals("hello");
}}; }};
//#test-ignoreMsg //#test-ignoreMsg
@ -300,7 +300,7 @@ public class TestKitDocTest {
} }
final MyProbe probe = new MyProbe(); final MyProbe probe = new MyProbe();
probe.getRef().tell("hello", null); probe.getRef().tell("hello", ActorRef.noSender());
probe.assertHello(); probe.assertHello();
}}; }};
//#test-special-probe //#test-special-probe
@ -313,7 +313,7 @@ public class TestKitDocTest {
new JavaTestKit(system) {{ new JavaTestKit(system) {{
final JavaTestKit probe = new JavaTestKit(system); final JavaTestKit probe = new JavaTestKit(system);
probe.watch(target); probe.watch(target);
target.tell(PoisonPill.getInstance(), null); target.tell(PoisonPill.getInstance(), ActorRef.noSender());
final Terminated msg = probe.expectMsgClass(Terminated.class); final Terminated msg = probe.expectMsgClass(Terminated.class);
assertEquals(msg.getActor(), target); assertEquals(msg.getActor(), target);
}}; }};
@ -374,7 +374,7 @@ public class TestKitDocTest {
// install auto-pilot // install auto-pilot
probe.setAutoPilot(new TestActor.AutoPilot() { probe.setAutoPilot(new TestActor.AutoPilot() {
public AutoPilot run(ActorRef sender, Object msg) { public AutoPilot run(ActorRef sender, Object msg) {
sender.tell(msg, null); sender.tell(msg, ActorRef.noSender());
return noAutoPilot(); return noAutoPilot();
} }
}); });
@ -406,7 +406,7 @@ public class TestKitDocTest {
final int result = new EventFilter<Integer>(ActorKilledException.class) { final int result = new EventFilter<Integer>(ActorKilledException.class) {
protected Integer run() { protected Integer run() {
victim.tell(Kill.getInstance(), null); victim.tell(Kill.getInstance(), ActorRef.noSender());
return 42; return 42;
} }
}.from("akka://TestKitDocTest/user/victim").occurrences(1).exec(); }.from("akka://TestKitDocTest/user/victim").occurrences(1).exec();

View file

@ -30,7 +30,7 @@ public class TransactorDocTest {
Timeout timeout = new Timeout(5, SECONDS); Timeout timeout = new Timeout(5, SECONDS);
counter1.tell(new Coordinated(new Increment(counter2), timeout), null); counter1.tell(new Coordinated(new Increment(counter2), timeout), ActorRef.noSender());
Integer count = (Integer) Await.result( Integer count = (Integer) Await.result(
ask(counter1, "GetCount", timeout), timeout.duration()); ask(counter1, "GetCount", timeout), timeout.duration());
@ -52,11 +52,11 @@ public class TransactorDocTest {
ActorRef actor = system.actorOf(Props.create(Coordinator.class)); ActorRef actor = system.actorOf(Props.create(Coordinator.class));
//#send-coordinated //#send-coordinated
actor.tell(new Coordinated(new Message(), timeout), null); actor.tell(new Coordinated(new Message(), timeout), ActorRef.noSender());
//#send-coordinated //#send-coordinated
//#include-coordinated //#include-coordinated
actor.tell(coordinated.coordinate(new Message()), null); actor.tell(coordinated.coordinate(new Message()), ActorRef.noSender());
//#include-coordinated //#include-coordinated
coordinated.await(); coordinated.await();
@ -71,7 +71,7 @@ public class TransactorDocTest {
Timeout timeout = new Timeout(5, SECONDS); Timeout timeout = new Timeout(5, SECONDS);
Coordinated coordinated = new Coordinated(timeout); Coordinated coordinated = new Coordinated(timeout);
counter.tell(coordinated.coordinate(new Increment()), null); counter.tell(coordinated.coordinate(new Increment()), ActorRef.noSender());
coordinated.await(); coordinated.await();
Integer count = (Integer) Await.result(ask(counter, "GetCount", timeout), timeout.duration()); Integer count = (Integer) Await.result(ask(counter, "GetCount", timeout), timeout.duration());
@ -88,7 +88,7 @@ public class TransactorDocTest {
Timeout timeout = new Timeout(5, SECONDS); Timeout timeout = new Timeout(5, SECONDS);
Coordinated coordinated = new Coordinated(timeout); Coordinated coordinated = new Coordinated(timeout);
friendlyCounter.tell(coordinated.coordinate(new Increment(friend)), null); friendlyCounter.tell(coordinated.coordinate(new Increment(friend)), ActorRef.noSender());
coordinated.await(); coordinated.await();
Integer count1 = (Integer) Await.result(ask(friendlyCounter, "GetCount", timeout), timeout.duration()); Integer count1 = (Integer) Await.result(ask(friendlyCounter, "GetCount", timeout), timeout.duration());

View file

@ -83,13 +83,13 @@ public class ZeromqDocTest {
//#sub-topic-socket //#sub-topic-socket
//#unsub-topic-socket //#unsub-topic-socket
subTopicSocket.tell(new Unsubscribe("foo.bar"), null); subTopicSocket.tell(new Unsubscribe("foo.bar"), ActorRef.noSender());
//#unsub-topic-socket //#unsub-topic-socket
byte[] payload = new byte[0]; byte[] payload = new byte[0];
//#pub-topic //#pub-topic
pubSocket.tell(ZMQMessage.withFrames(ByteString.fromString("foo.bar"), pubSocket.tell(ZMQMessage.withFrames(ByteString.fromString("foo.bar"),
ByteString.fromArray(payload)), null); ByteString.fromArray(payload)), ActorRef.noSender());
//#pub-topic //#pub-topic
system.stop(subSocket); system.stop(subSocket);
@ -193,7 +193,7 @@ public class ZeromqDocTest {
public void preStart() { public void preStart() {
getContext().system().scheduler() getContext().system().scheduler()
.schedule(Duration.create(1, "second"), Duration.create(1, "second"), .schedule(Duration.create(1, "second"), Duration.create(1, "second"),
getSelf(), TICK, getContext().dispatcher(), null); getSelf(), TICK, getContext().dispatcher(), ActorRef.noSender());
} }
@Override @Override