2014-02-21 12:43:30 +01:00
|
|
|
|
/**
|
2017-01-04 17:37:10 +01:00
|
|
|
|
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
2014-02-21 12:43:30 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2015-05-05 16:44:49 +02:00
|
|
|
|
package docs.actorlambda;
|
2014-02-21 12:43:30 +01:00
|
|
|
|
|
|
|
|
|
|
import akka.actor.*;
|
2014-03-20 12:05:32 +01:00
|
|
|
|
import com.typesafe.config.Config;
|
|
|
|
|
|
import com.typesafe.config.ConfigFactory;
|
2016-02-11 16:39:25 +01:00
|
|
|
|
import docs.AbstractJavaTest;
|
2015-05-05 16:44:49 +02:00
|
|
|
|
import static docs.actorlambda.Messages.Swap.Swap;
|
|
|
|
|
|
import static docs.actorlambda.Messages.*;
|
2016-12-01 18:49:38 +01:00
|
|
|
|
import akka.actor.CoordinatedShutdown;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
|
2016-12-01 18:49:38 +01:00
|
|
|
|
import akka.util.Timeout;
|
|
|
|
|
|
import akka.Done;
|
2014-02-21 12:43:30 +01:00
|
|
|
|
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
import java.util.Optional;
|
2014-02-21 12:43:30 +01:00
|
|
|
|
import java.util.concurrent.TimeUnit;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
import akka.testkit.TestActors;
|
2017-03-14 15:51:44 +05:00
|
|
|
|
import scala.concurrent.Await;
|
2014-02-21 12:43:30 +01:00
|
|
|
|
|
|
|
|
|
|
import akka.testkit.JavaTestKit;
|
|
|
|
|
|
import org.junit.AfterClass;
|
|
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
|
|
|
|
|
|
//#import-props
|
|
|
|
|
|
import akka.actor.Props;
|
|
|
|
|
|
//#import-props
|
|
|
|
|
|
//#import-actorRef
|
|
|
|
|
|
import akka.actor.ActorRef;
|
|
|
|
|
|
import akka.actor.ActorSystem;
|
|
|
|
|
|
//#import-actorRef
|
|
|
|
|
|
//#import-identify
|
|
|
|
|
|
import akka.actor.ActorIdentity;
|
|
|
|
|
|
import akka.actor.ActorSelection;
|
|
|
|
|
|
import akka.actor.Identify;
|
|
|
|
|
|
//#import-identify
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
//#import-ask
|
2017-03-14 15:51:44 +05:00
|
|
|
|
import static akka.pattern.PatternsCS.ask;
|
|
|
|
|
|
import static akka.pattern.PatternsCS.pipe;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
import akka.util.Timeout;
|
2017-03-14 15:51:44 +05:00
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
//#import-ask
|
|
|
|
|
|
//#import-gracefulStop
|
2017-03-14 15:51:44 +05:00
|
|
|
|
import static akka.pattern.PatternsCS.gracefulStop;
|
2014-02-21 12:43:30 +01:00
|
|
|
|
import akka.pattern.AskTimeoutException;
|
|
|
|
|
|
import scala.concurrent.duration.Duration;
|
2017-03-14 15:51:44 +05:00
|
|
|
|
import java.util.concurrent.CompletionStage;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
//#import-gracefulStop
|
|
|
|
|
|
//#import-terminated
|
|
|
|
|
|
import akka.actor.Terminated;
|
|
|
|
|
|
//#import-terminated
|
2014-02-21 12:43:30 +01:00
|
|
|
|
|
2016-02-11 16:39:25 +01:00
|
|
|
|
public class ActorDocTest extends AbstractJavaTest {
|
2014-02-21 12:43:30 +01:00
|
|
|
|
|
2014-03-20 12:05:32 +01:00
|
|
|
|
public static Config config = ConfigFactory.parseString(
|
|
|
|
|
|
"akka {\n" +
|
|
|
|
|
|
" loggers = [\"akka.testkit.TestEventListener\"]\n" +
|
|
|
|
|
|
" loglevel = \"WARNING\"\n" +
|
|
|
|
|
|
" stdout-loglevel = \"WARNING\"\n" +
|
|
|
|
|
|
"}\n"
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2014-02-21 12:43:30 +01:00
|
|
|
|
static ActorSystem system = null;
|
|
|
|
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
|
|
public static void beforeClass() {
|
2014-03-20 12:05:32 +01:00
|
|
|
|
system = ActorSystem.create("ActorDocTest", config);
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@AfterClass
|
2014-08-25 15:49:28 +02:00
|
|
|
|
public static void afterClass() throws Exception {
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
Await.ready(system.terminate(), Duration.create(5, TimeUnit.SECONDS));
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
|
//#context-actorOf
|
|
|
|
|
|
public class FirstActor extends AbstractActor {
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
final ActorRef child = getContext().actorOf(Props.create(MyActor.class), "myChild");
|
|
|
|
|
|
|
2014-02-21 12:43:30 +01:00
|
|
|
|
//#plus-some-behavior
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
|
.matchAny(x -> sender().tell(x, self()))
|
|
|
|
|
|
.build();
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
//#plus-some-behavior
|
|
|
|
|
|
}
|
|
|
|
|
|
//#context-actorOf
|
|
|
|
|
|
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
static public class SomeActor extends AbstractActor {
|
|
|
|
|
|
//#createReceive
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
|
.match(String.class, s -> System.out.println(s.toLowerCase()))
|
|
|
|
|
|
.build();
|
2014-03-20 12:05:32 +01:00
|
|
|
|
}
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
//#createReceive
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
|
//#well-structured
|
|
|
|
|
|
public class WellStructuredActor extends AbstractActor {
|
|
|
|
|
|
|
|
|
|
|
|
public static class Msg1 {}
|
|
|
|
|
|
public static class Msg2 {}
|
|
|
|
|
|
public static class Msg3 {}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
|
.match(Msg1.class, this::receiveMsg1)
|
|
|
|
|
|
.match(Msg2.class, this::receiveMsg2)
|
|
|
|
|
|
.match(Msg3.class, this::receiveMsg3)
|
|
|
|
|
|
.build();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void receiveMsg1(Msg1 msg) {
|
|
|
|
|
|
// actual work
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void receiveMsg2(Msg2 msg) {
|
|
|
|
|
|
// actual work
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void receiveMsg3(Msg3 msg) {
|
|
|
|
|
|
// actual work
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//#well-structured
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
|
//#optimized
|
|
|
|
|
|
public class OptimizedActor extends UntypedAbstractActor {
|
|
|
|
|
|
|
|
|
|
|
|
public static class Msg1 {}
|
|
|
|
|
|
public static class Msg2 {}
|
|
|
|
|
|
public static class Msg3 {}
|
|
|
|
|
|
|
2014-02-21 12:43:30 +01:00
|
|
|
|
@Override
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
public void onReceive(Object msg) throws Exception {
|
|
|
|
|
|
if (msg instanceof Msg1)
|
|
|
|
|
|
receiveMsg1((Msg1) msg);
|
2017-03-14 15:51:44 +05:00
|
|
|
|
else if (msg instanceof Msg2)
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
receiveMsg2((Msg2) msg);
|
|
|
|
|
|
else if (msg instanceof Msg3)
|
|
|
|
|
|
receiveMsg3((Msg3) msg);
|
|
|
|
|
|
else
|
|
|
|
|
|
unhandled(msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void receiveMsg1(Msg1 msg) {
|
|
|
|
|
|
// actual work
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void receiveMsg2(Msg2 msg) {
|
|
|
|
|
|
// actual work
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void receiveMsg3(Msg3 msg) {
|
|
|
|
|
|
// actual work
|
|
|
|
|
|
}
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
//#optimized
|
2014-02-21 12:43:30 +01:00
|
|
|
|
|
|
|
|
|
|
static public class ActorWithArgs extends AbstractActor {
|
|
|
|
|
|
private final String args;
|
|
|
|
|
|
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
public ActorWithArgs(String args) {
|
2014-02-21 12:43:30 +01:00
|
|
|
|
this.args = args;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return receiveBuilder().matchAny(x -> { }).build();
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
|
//#props-factory
|
|
|
|
|
|
public class DemoActor extends AbstractActor {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Create Props for an actor of this type.
|
|
|
|
|
|
* @param magicNumber The magic number to be passed to this actor’s constructor.
|
|
|
|
|
|
* @return a Props for creating this actor, which can then be further configured
|
|
|
|
|
|
* (e.g. calling `.withDispatcher()` on it)
|
|
|
|
|
|
*/
|
|
|
|
|
|
static Props props(Integer magicNumber) {
|
|
|
|
|
|
// You need to specify the actual type of the returned actor
|
|
|
|
|
|
// since Java 8 lambdas have some runtime type information erased
|
|
|
|
|
|
return Props.create(DemoActor.class, () -> new DemoActor(magicNumber));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private final Integer magicNumber;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
|
|
|
|
|
|
public DemoActor(Integer magicNumber) {
|
2014-02-21 12:43:30 +01:00
|
|
|
|
this.magicNumber = magicNumber;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
|
.match(Integer.class, i -> {
|
2014-02-21 12:43:30 +01:00
|
|
|
|
sender().tell(i + magicNumber, self());
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
})
|
|
|
|
|
|
.build();
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//#props-factory
|
|
|
|
|
|
static
|
|
|
|
|
|
//#props-factory
|
|
|
|
|
|
public class SomeOtherActor extends AbstractActor {
|
|
|
|
|
|
// Props(new DemoActor(42)) would not be safe
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
ActorRef demoActor = getContext().actorOf(DemoActor.props(42), "demo");
|
2014-02-21 12:43:30 +01:00
|
|
|
|
// ...
|
|
|
|
|
|
//#props-factory
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return AbstractActor.emptyBehavior();
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
//#props-factory
|
|
|
|
|
|
}
|
|
|
|
|
|
//#props-factory
|
|
|
|
|
|
|
2015-01-16 23:43:27 +05:00
|
|
|
|
static
|
|
|
|
|
|
//#messages-in-companion
|
2015-01-28 07:46:33 +01:00
|
|
|
|
public class DemoMessagesActor extends AbstractLoggingActor {
|
2015-01-16 23:43:27 +05:00
|
|
|
|
|
|
|
|
|
|
static public class Greeting {
|
|
|
|
|
|
private final String from;
|
|
|
|
|
|
|
|
|
|
|
|
public Greeting(String from) {
|
|
|
|
|
|
this.from = from;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String getGreeter() {
|
|
|
|
|
|
return from;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
|
.match(Greeting.class, g -> {
|
2015-01-28 07:46:33 +01:00
|
|
|
|
log().info("I was greeted by {}", g.getGreeter());
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
})
|
|
|
|
|
|
.build();
|
|
|
|
|
|
}
|
2015-01-16 23:43:27 +05:00
|
|
|
|
}
|
|
|
|
|
|
//#messages-in-companion
|
|
|
|
|
|
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
|
|
|
|
|
|
public static class LifecycleMethods extends AbstractActor {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return AbstractActor.emptyBehavior();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* This section must be kept in sync with the actual Actor trait.
|
|
|
|
|
|
*
|
|
|
|
|
|
* BOYSCOUT RULE: whenever you read this, verify that!
|
|
|
|
|
|
*/
|
|
|
|
|
|
//#lifecycle-callbacks
|
|
|
|
|
|
public void preStart() {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void preRestart(Throwable reason, Optional<Object> message) {
|
|
|
|
|
|
for (ActorRef each : getContext().getChildren()) {
|
|
|
|
|
|
getContext().unwatch(each);
|
|
|
|
|
|
getContext().stop(each);
|
|
|
|
|
|
}
|
|
|
|
|
|
postStop();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void postRestart(Throwable reason) {
|
|
|
|
|
|
preStart();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void postStop() {
|
|
|
|
|
|
}
|
|
|
|
|
|
//#lifecycle-callbacks
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-02-21 12:43:30 +01:00
|
|
|
|
public static class Hook extends AbstractActor {
|
|
|
|
|
|
ActorRef target = null;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return AbstractActor.emptyBehavior();
|
2014-03-20 12:05:32 +01:00
|
|
|
|
}
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
|
2014-02-21 12:43:30 +01:00
|
|
|
|
//#preStart
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void preStart() {
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
target = getContext().actorOf(Props.create(MyActor.class, "target"));
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
//#preStart
|
|
|
|
|
|
//#postStop
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void postStop() {
|
|
|
|
|
|
//#clean-up-some-resources
|
|
|
|
|
|
final String message = "stopped";
|
|
|
|
|
|
//#tell
|
|
|
|
|
|
// don’t forget to think about who is the sender (2nd argument)
|
|
|
|
|
|
target.tell(message, self());
|
|
|
|
|
|
//#tell
|
|
|
|
|
|
final Object result = "";
|
|
|
|
|
|
//#forward
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
target.forward(result, getContext());
|
2014-02-21 12:43:30 +01:00
|
|
|
|
//#forward
|
|
|
|
|
|
target = null;
|
|
|
|
|
|
//#clean-up-some-resources
|
|
|
|
|
|
}
|
|
|
|
|
|
//#postStop
|
|
|
|
|
|
|
|
|
|
|
|
// compilation test only
|
|
|
|
|
|
public void compileSelections() {
|
|
|
|
|
|
//#selection-local
|
|
|
|
|
|
// will look up this absolute path
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
getContext().actorSelection("/user/serviceA/actor");
|
2014-02-21 12:43:30 +01:00
|
|
|
|
// will look up sibling beneath same supervisor
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
getContext().actorSelection("../joe");
|
2014-02-21 12:43:30 +01:00
|
|
|
|
//#selection-local
|
|
|
|
|
|
|
|
|
|
|
|
//#selection-wildcard
|
|
|
|
|
|
// will look all children to serviceB with names starting with worker
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
getContext().actorSelection("/user/serviceB/worker*");
|
2014-02-21 12:43:30 +01:00
|
|
|
|
// will look up all siblings beneath same supervisor
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
getContext().actorSelection("../*");
|
2014-02-21 12:43:30 +01:00
|
|
|
|
//#selection-wildcard
|
|
|
|
|
|
|
|
|
|
|
|
//#selection-remote
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
getContext().actorSelection("akka.tcp://app@otherhost:1234/user/serviceB");
|
2014-02-21 12:43:30 +01:00
|
|
|
|
//#selection-remote
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static class ReplyException extends AbstractActor {
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
|
.matchAny(x -> {
|
2014-02-21 12:43:30 +01:00
|
|
|
|
//#reply-exception
|
|
|
|
|
|
try {
|
|
|
|
|
|
String result = operation();
|
|
|
|
|
|
sender().tell(result, self());
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
sender().tell(new akka.actor.Status.Failure(e), self());
|
|
|
|
|
|
throw e;
|
|
|
|
|
|
}
|
|
|
|
|
|
//#reply-exception
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
})
|
|
|
|
|
|
.build();
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String operation() {
|
|
|
|
|
|
return "Hi";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
|
//#gracefulStop-actor
|
|
|
|
|
|
public class Manager extends AbstractActor {
|
|
|
|
|
|
private static enum Shutdown {
|
|
|
|
|
|
Shutdown
|
|
|
|
|
|
}
|
|
|
|
|
|
public static final Shutdown SHUTDOWN = Shutdown.Shutdown;
|
|
|
|
|
|
|
|
|
|
|
|
private ActorRef worker =
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
getContext().watch(getContext().actorOf(Props.create(Cruncher.class), "worker"));
|
2014-02-21 12:43:30 +01:00
|
|
|
|
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
|
.matchEquals("job", s -> {
|
2014-02-21 12:43:30 +01:00
|
|
|
|
worker.tell("crunch", self());
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
})
|
|
|
|
|
|
.matchEquals(SHUTDOWN, x -> {
|
2014-02-21 12:43:30 +01:00
|
|
|
|
worker.tell(PoisonPill.getInstance(), self());
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
getContext().become(shuttingDown());
|
|
|
|
|
|
})
|
|
|
|
|
|
.build();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private AbstractActor.Receive shuttingDown() {
|
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
|
.matchEquals("job", s ->
|
|
|
|
|
|
sender().tell("service unavailable, shutting down", self())
|
|
|
|
|
|
)
|
|
|
|
|
|
.match(Terminated.class, t -> t.actor().equals(worker), t ->
|
|
|
|
|
|
getContext().stop(self())
|
|
|
|
|
|
)
|
|
|
|
|
|
.build();
|
|
|
|
|
|
}
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
//#gracefulStop-actor
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void usePatternsGracefulStop() throws Exception {
|
|
|
|
|
|
ActorRef actorRef = system.actorOf(Props.create(Manager.class));
|
|
|
|
|
|
//#gracefulStop
|
|
|
|
|
|
try {
|
2017-03-14 15:51:44 +05:00
|
|
|
|
CompletionStage<Boolean> stopped =
|
2014-02-21 12:43:30 +01:00
|
|
|
|
gracefulStop(actorRef, Duration.create(5, TimeUnit.SECONDS), Manager.SHUTDOWN);
|
2017-03-14 15:51:44 +05:00
|
|
|
|
stopped.toCompletableFuture().get(6, TimeUnit.SECONDS);
|
2014-02-21 12:43:30 +01:00
|
|
|
|
// the actor has been stopped
|
|
|
|
|
|
} catch (AskTimeoutException e) {
|
|
|
|
|
|
// the actor wasn't stopped within 5 seconds
|
|
|
|
|
|
}
|
|
|
|
|
|
//#gracefulStop
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class Cruncher extends AbstractActor {
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return receiveBuilder().matchEquals("crunch", s -> { }).build();
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
|
//#swapper
|
2014-03-20 12:05:32 +01:00
|
|
|
|
public class Swapper extends AbstractLoggingActor {
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
|
.matchEquals(Swap, s -> {
|
|
|
|
|
|
log().info("Hi");
|
|
|
|
|
|
getContext().become(receiveBuilder().
|
|
|
|
|
|
matchEquals(Swap, x -> {
|
|
|
|
|
|
log().info("Ho");
|
|
|
|
|
|
getContext().unbecome(); // resets the latest 'become' (just for fun)
|
|
|
|
|
|
}).build(), false); // push on top instead of replace
|
|
|
|
|
|
}).build();
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//#swapper
|
|
|
|
|
|
static
|
|
|
|
|
|
//#swapper
|
|
|
|
|
|
public class SwapperApp {
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
ActorSystem system = ActorSystem.create("SwapperSystem");
|
|
|
|
|
|
ActorRef swapper = system.actorOf(Props.create(Swapper.class), "swapper");
|
|
|
|
|
|
swapper.tell(Swap, ActorRef.noSender()); // logs Hi
|
|
|
|
|
|
swapper.tell(Swap, ActorRef.noSender()); // logs Ho
|
|
|
|
|
|
swapper.tell(Swap, ActorRef.noSender()); // logs Hi
|
|
|
|
|
|
swapper.tell(Swap, ActorRef.noSender()); // logs Ho
|
|
|
|
|
|
swapper.tell(Swap, ActorRef.noSender()); // logs Hi
|
|
|
|
|
|
swapper.tell(Swap, ActorRef.noSender()); // logs Ho
|
2014-08-25 15:49:28 +02:00
|
|
|
|
system.terminate();
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//#swapper
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void creatingActorWithSystemActorOf() {
|
|
|
|
|
|
//#system-actorOf
|
|
|
|
|
|
// ActorSystem is a heavy object: create only one per application
|
2014-03-20 12:05:32 +01:00
|
|
|
|
final ActorSystem system = ActorSystem.create("MySystem", config);
|
2014-02-21 12:43:30 +01:00
|
|
|
|
final ActorRef myActor = system.actorOf(Props.create(MyActor.class), "myactor");
|
|
|
|
|
|
//#system-actorOf
|
|
|
|
|
|
try {
|
|
|
|
|
|
new JavaTestKit(system) {
|
|
|
|
|
|
{
|
|
|
|
|
|
myActor.tell("hello", getRef());
|
|
|
|
|
|
expectMsgEquals("hello");
|
2016-10-23 22:35:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
JavaTestKit.shutdownActorSystem(system);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void creatingGraduallyBuiltActorWithSystemActorOf() {
|
|
|
|
|
|
final ActorSystem system = ActorSystem.create("MySystem", config);
|
|
|
|
|
|
final ActorRef actor = system.actorOf(Props.create(GraduallyBuiltActor.class), "graduallyBuiltActor");
|
|
|
|
|
|
try {
|
|
|
|
|
|
new JavaTestKit(system) {
|
|
|
|
|
|
{
|
|
|
|
|
|
actor.tell("hello", getRef());
|
|
|
|
|
|
expectMsgEquals("hello");
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
JavaTestKit.shutdownActorSystem(system);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void creatingPropsConfig() {
|
|
|
|
|
|
//#creating-props
|
|
|
|
|
|
Props props1 = Props.create(MyActor.class);
|
|
|
|
|
|
Props props2 = Props.create(ActorWithArgs.class,
|
|
|
|
|
|
() -> new ActorWithArgs("arg")); // careful, see below
|
|
|
|
|
|
Props props3 = Props.create(ActorWithArgs.class, "arg");
|
|
|
|
|
|
//#creating-props
|
|
|
|
|
|
|
|
|
|
|
|
//#creating-props-deprecated
|
|
|
|
|
|
// NOT RECOMMENDED within another actor:
|
|
|
|
|
|
// encourages to close over enclosing class
|
|
|
|
|
|
Props props7 = Props.create(ActorWithArgs.class,
|
|
|
|
|
|
() -> new ActorWithArgs("arg"));
|
|
|
|
|
|
//#creating-props-deprecated
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test(expected=IllegalArgumentException.class)
|
|
|
|
|
|
public void creatingPropsIllegal() {
|
|
|
|
|
|
//#creating-props-illegal
|
|
|
|
|
|
// This will throw an IllegalArgumentException since some runtime
|
|
|
|
|
|
// type information of the lambda is erased.
|
|
|
|
|
|
// Use Props.create(actorClass, Creator) instead.
|
|
|
|
|
|
Props props = Props.create(() -> new ActorWithArgs("arg"));
|
|
|
|
|
|
//#creating-props-illegal
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
|
//#receive-timeout
|
|
|
|
|
|
public class ReceiveTimeoutActor extends AbstractActor {
|
|
|
|
|
|
//#receive-timeout
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
ActorRef target = getContext().system().deadLetters();
|
2014-02-21 12:43:30 +01:00
|
|
|
|
//#receive-timeout
|
2014-03-20 12:05:32 +01:00
|
|
|
|
public ReceiveTimeoutActor() {
|
|
|
|
|
|
// To set an initial delay
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
getContext().setReceiveTimeout(Duration.create(10, TimeUnit.SECONDS));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
|
.matchEquals("Hello", s -> {
|
2014-02-21 12:43:30 +01:00
|
|
|
|
// To set in a response to a message
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
getContext().setReceiveTimeout(Duration.create(1, TimeUnit.SECONDS));
|
2014-02-21 12:43:30 +01:00
|
|
|
|
//#receive-timeout
|
|
|
|
|
|
target = sender();
|
|
|
|
|
|
target.tell("Hello world", self());
|
|
|
|
|
|
//#receive-timeout
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
})
|
|
|
|
|
|
.match(ReceiveTimeout.class, r -> {
|
2014-02-21 12:43:30 +01:00
|
|
|
|
// To turn it off
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
getContext().setReceiveTimeout(Duration.Undefined());
|
2014-02-21 12:43:30 +01:00
|
|
|
|
//#receive-timeout
|
|
|
|
|
|
target.tell("timeout", self());
|
|
|
|
|
|
//#receive-timeout
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
})
|
|
|
|
|
|
.build();
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//#receive-timeout
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void using_receiveTimeout() {
|
|
|
|
|
|
final ActorRef myActor = system.actorOf(Props.create(ReceiveTimeoutActor.class));
|
|
|
|
|
|
new JavaTestKit(system) {
|
|
|
|
|
|
{
|
|
|
|
|
|
myActor.tell("Hello", getRef());
|
|
|
|
|
|
expectMsgEquals("Hello world");
|
|
|
|
|
|
expectMsgEquals("timeout");
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
|
//#hot-swap-actor
|
|
|
|
|
|
public class HotSwapActor extends AbstractActor {
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
private AbstractActor.Receive angry;
|
|
|
|
|
|
private AbstractActor.Receive happy;
|
2014-02-21 12:43:30 +01:00
|
|
|
|
|
2014-03-20 12:05:32 +01:00
|
|
|
|
public HotSwapActor() {
|
2014-02-21 12:43:30 +01:00
|
|
|
|
angry =
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
receiveBuilder()
|
|
|
|
|
|
.matchEquals("foo", s -> {
|
2014-02-21 12:43:30 +01:00
|
|
|
|
sender().tell("I am already angry?", self());
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
})
|
|
|
|
|
|
.matchEquals("bar", s -> {
|
|
|
|
|
|
getContext().become(happy);
|
|
|
|
|
|
})
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
happy = receiveBuilder()
|
|
|
|
|
|
.matchEquals("bar", s -> {
|
2014-02-21 12:43:30 +01:00
|
|
|
|
sender().tell("I am already happy :-)", self());
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
})
|
|
|
|
|
|
.matchEquals("foo", s -> {
|
|
|
|
|
|
getContext().become(angry);
|
|
|
|
|
|
})
|
|
|
|
|
|
.build();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
|
.matchEquals("foo", s ->
|
|
|
|
|
|
getContext().become(angry)
|
|
|
|
|
|
)
|
|
|
|
|
|
.matchEquals("bar", s ->
|
|
|
|
|
|
getContext().become(happy)
|
|
|
|
|
|
)
|
|
|
|
|
|
.build();
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//#hot-swap-actor
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void using_hot_swap() {
|
|
|
|
|
|
final ActorRef actor = system.actorOf(Props.create(HotSwapActor.class), "hot");
|
|
|
|
|
|
new JavaTestKit(system) {
|
|
|
|
|
|
{
|
|
|
|
|
|
actor.tell("foo", getRef());
|
|
|
|
|
|
actor.tell("foo", getRef());
|
|
|
|
|
|
expectMsgEquals("I am already angry?");
|
|
|
|
|
|
actor.tell("bar", getRef());
|
|
|
|
|
|
actor.tell("bar", getRef());
|
|
|
|
|
|
expectMsgEquals("I am already happy :-)");
|
|
|
|
|
|
actor.tell("foo", getRef());
|
|
|
|
|
|
actor.tell("foo", getRef());
|
|
|
|
|
|
expectMsgEquals("I am already angry?");
|
|
|
|
|
|
expectNoMsg(Duration.create(1, TimeUnit.SECONDS));
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
|
//#stash
|
|
|
|
|
|
public class ActorWithProtocol extends AbstractActorWithStash {
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
|
.matchEquals("open", s -> {
|
|
|
|
|
|
getContext().become(receiveBuilder()
|
|
|
|
|
|
.matchEquals("write", ws -> { /* do writing */ })
|
|
|
|
|
|
.matchEquals("close", cs -> {
|
2014-02-21 12:43:30 +01:00
|
|
|
|
unstashAll();
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
getContext().unbecome();
|
|
|
|
|
|
})
|
|
|
|
|
|
.matchAny(msg -> stash())
|
|
|
|
|
|
.build(), false);
|
|
|
|
|
|
})
|
|
|
|
|
|
.matchAny(msg -> stash())
|
|
|
|
|
|
.build();
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//#stash
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void using_Stash() {
|
|
|
|
|
|
final ActorRef actor = system.actorOf(Props.create(ActorWithProtocol.class), "stash");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
|
//#watch
|
|
|
|
|
|
public class WatchActor extends AbstractActor {
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
private final ActorRef child = getContext().actorOf(Props.empty(), "target");
|
2014-02-21 12:43:30 +01:00
|
|
|
|
private ActorRef lastSender = system.deadLetters();
|
|
|
|
|
|
|
2014-03-20 12:05:32 +01:00
|
|
|
|
public WatchActor() {
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
getContext().watch(child); // <-- this is the only call needed for registration
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
|
.matchEquals("kill", s -> {
|
|
|
|
|
|
getContext().stop(child);
|
2014-02-21 12:43:30 +01:00
|
|
|
|
lastSender = sender();
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
})
|
|
|
|
|
|
.match(Terminated.class, t -> t.actor().equals(child), t -> {
|
2014-02-21 12:43:30 +01:00
|
|
|
|
lastSender.tell("finished", self());
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
})
|
|
|
|
|
|
.build();
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//#watch
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void using_watch() {
|
|
|
|
|
|
ActorRef actor = system.actorOf(Props.create(WatchActor.class));
|
|
|
|
|
|
|
|
|
|
|
|
new JavaTestKit(system) {
|
|
|
|
|
|
{
|
|
|
|
|
|
actor.tell("kill", getRef());
|
|
|
|
|
|
expectMsgEquals("finished");
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
|
//#identify
|
|
|
|
|
|
public class Follower extends AbstractActor {
|
|
|
|
|
|
final Integer identifyId = 1;
|
|
|
|
|
|
|
2014-03-20 12:05:32 +01:00
|
|
|
|
public Follower(){
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
ActorSelection selection = getContext().actorSelection("/user/another");
|
2014-02-21 12:43:30 +01:00
|
|
|
|
selection.tell(new Identify(identifyId), self());
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
|
.match(ActorIdentity.class, id -> id.getActorRef().isPresent(), id -> {
|
|
|
|
|
|
ActorRef ref = id.getActorRef().get();
|
|
|
|
|
|
getContext().watch(ref);
|
|
|
|
|
|
getContext().become(active(ref));
|
|
|
|
|
|
})
|
|
|
|
|
|
.match(ActorIdentity.class, id -> !id.getActorRef().isPresent(), id -> {
|
|
|
|
|
|
getContext().stop(self());
|
|
|
|
|
|
})
|
|
|
|
|
|
.build();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
final AbstractActor.Receive active(final ActorRef another) {
|
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
|
.match(Terminated.class, t -> t.actor().equals(another), t ->
|
|
|
|
|
|
getContext().stop(self())
|
|
|
|
|
|
)
|
|
|
|
|
|
.build();
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//#identify
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void using_Identify() {
|
|
|
|
|
|
ActorRef a = system.actorOf(Props.empty());
|
|
|
|
|
|
ActorRef b = system.actorOf(Props.create(Follower.class));
|
|
|
|
|
|
|
|
|
|
|
|
new JavaTestKit(system) {
|
|
|
|
|
|
{
|
|
|
|
|
|
watch(b);
|
|
|
|
|
|
system.stop(a);
|
|
|
|
|
|
assertEquals(expectMsgClass(Duration.create(2, TimeUnit.SECONDS), Terminated.class).actor(), b);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
|
2014-03-20 12:05:32 +01:00
|
|
|
|
@Test
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
public void usePatternsAskPipe() {
|
|
|
|
|
|
new JavaTestKit(system) {
|
|
|
|
|
|
{
|
|
|
|
|
|
ActorRef actorA = system.actorOf(TestActors.echoActorProps());
|
|
|
|
|
|
ActorRef actorB = system.actorOf(TestActors.echoActorProps());
|
|
|
|
|
|
ActorRef actorC = getRef();
|
|
|
|
|
|
|
|
|
|
|
|
//#ask-pipe
|
2017-03-14 15:51:44 +05:00
|
|
|
|
Timeout t = new Timeout(Duration.create(5, TimeUnit.SECONDS));
|
|
|
|
|
|
|
|
|
|
|
|
// using 1000ms timeout
|
|
|
|
|
|
CompletableFuture<Object> future1 =
|
|
|
|
|
|
ask(actorA, "request", 1000).toCompletableFuture();
|
|
|
|
|
|
|
|
|
|
|
|
// using timeout from above
|
|
|
|
|
|
CompletableFuture<Object> future2 =
|
|
|
|
|
|
ask(actorB, "another request", t).toCompletableFuture();
|
|
|
|
|
|
|
|
|
|
|
|
CompletableFuture<Result> transformed =
|
|
|
|
|
|
CompletableFuture.allOf(future1, future2)
|
|
|
|
|
|
.thenApply(v -> {
|
|
|
|
|
|
String x = (String) future1.join();
|
|
|
|
|
|
String s = (String) future2.join();
|
|
|
|
|
|
return new Result(x, s);
|
|
|
|
|
|
});
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
|
|
|
|
|
|
pipe(transformed, system.dispatcher()).to(actorC);
|
|
|
|
|
|
//#ask-pipe
|
|
|
|
|
|
|
|
|
|
|
|
expectMsgEquals(new Result("request", "another request"));
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2014-03-20 12:05:32 +01:00
|
|
|
|
}
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void useKill() {
|
|
|
|
|
|
new JavaTestKit(system) {
|
|
|
|
|
|
{
|
|
|
|
|
|
ActorRef victim = system.actorOf(TestActors.echoActorProps());
|
|
|
|
|
|
watch(victim);
|
|
|
|
|
|
//#kill
|
|
|
|
|
|
victim.tell(akka.actor.Kill.getInstance(), ActorRef.noSender());
|
|
|
|
|
|
//#kill
|
|
|
|
|
|
expectTerminated(Duration.create(3, TimeUnit.SECONDS), victim);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2014-03-20 12:05:32 +01:00
|
|
|
|
}
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
|
2014-03-20 12:05:32 +01:00
|
|
|
|
@Test
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
public void usePoisonPill() {
|
|
|
|
|
|
new JavaTestKit(system) {
|
|
|
|
|
|
{
|
|
|
|
|
|
ActorRef victim = system.actorOf(TestActors.echoActorProps());
|
|
|
|
|
|
watch(victim);
|
|
|
|
|
|
//#poison-pill
|
|
|
|
|
|
victim.tell(akka.actor.PoisonPill.getInstance(), ActorRef.noSender());
|
|
|
|
|
|
//#poison-pill
|
|
|
|
|
|
expectTerminated(Duration.create(3, TimeUnit.SECONDS), victim);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2014-03-20 12:05:32 +01:00
|
|
|
|
}
|
2016-12-01 18:49:38 +01:00
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void coordinatedShutdown() {
|
|
|
|
|
|
final ActorRef someActor = system.actorOf(Props.create(FirstActor.class));
|
|
|
|
|
|
//#coordinated-shutdown-addTask
|
|
|
|
|
|
CoordinatedShutdown.get(system).addTask(
|
|
|
|
|
|
CoordinatedShutdown.PhaseBeforeServiceUnbind(), "someTaskName",
|
|
|
|
|
|
() -> {
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
return akka.pattern.PatternsCS.ask(someActor, "stop", new Timeout(5, TimeUnit.SECONDS))
|
2016-12-01 18:49:38 +01:00
|
|
|
|
.thenApply(reply -> Done.getInstance());
|
|
|
|
|
|
});
|
|
|
|
|
|
//#coordinated-shutdown-addTask
|
|
|
|
|
|
|
|
|
|
|
|
//#coordinated-shutdown-jvm-hook
|
|
|
|
|
|
CoordinatedShutdown.get(system).addJvmShutdownHook(() ->
|
|
|
|
|
|
System.out.println("custom JVM shutdown hook...")
|
|
|
|
|
|
);
|
|
|
|
|
|
//#coordinated-shutdown-jvm-hook
|
|
|
|
|
|
|
|
|
|
|
|
// don't run this
|
|
|
|
|
|
if (false) {
|
|
|
|
|
|
//#coordinated-shutdown-run
|
|
|
|
|
|
CompletionStage<Done> done = CoordinatedShutdown.get(system).runAll();
|
|
|
|
|
|
//#coordinated-shutdown-run
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-03-20 12:05:32 +01:00
|
|
|
|
|
2014-02-21 12:43:30 +01:00
|
|
|
|
}
|