Hello.I use code(work with 2.5.12) from official documentation
public class HotSwapActor extends AbstractActor {
private AbstractActor.Receive angry;
private AbstractActor.Receive happy;
public HotSwapActor() {
angry = receiveBuilder().matchEquals("foo", s -> {
getSender().tell("I am already angry?", getSelf());
}).matchEquals("bar", s -> {
getContext().become(happy);
}).matchAny(System.out::println)
.build();
happy = receiveBuilder().matchEquals("bar", s -> {
getSender().tell("I am already happy :-)", getSelf());
}).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();
}
}
But, if I try
ActorRef secondRef = system.actorOf(Props.create(HotSwapActor.class), "TestHotSwap");
secondRef.tell("foo",ActorRef.noSender());
secondRef.tell("foo",ActorRef.noSender());`
then I give:
[INFO] [04/17/2018 17:33:15.441] [testSystem-akka.actor.default-dispatcher-3] [akka://testSystem/deadLetters] Message [java.lang.String] from Actor[akka://testSystem/user/TestHotSwap#553242136] to Actor[akka://testSystem/deadLetters] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
If I try :
ActorRef secondRef = system.actorOf(Props.create(HotSwapActor.class), "TestHotSwap");
secondRef.tell("foo",ActorRef.noSender());
secondRef.tell("foo",secondRef);
then all OK…Why?