2018-10-29 17:19:37 +08:00
|
|
|
/*
|
2020-01-02 07:24:59 -05:00
|
|
|
* Copyright (C) 2009-2020 Lightbend Inc. <https://www.lightbend.com>
|
2014-02-21 12:43:30 +01:00
|
|
|
*/
|
|
|
|
|
|
2017-03-16 09:30:00 +01:00
|
|
|
package jdocs.actor;
|
2013-12-11 14:53:41 +01:00
|
|
|
|
2019-01-12 04:00:53 +08:00
|
|
|
// #imports
|
2013-12-11 14:53:41 +01:00
|
|
|
import akka.actor.AbstractActor;
|
|
|
|
|
import akka.event.Logging;
|
|
|
|
|
import akka.event.LoggingAdapter;
|
|
|
|
|
|
2019-01-12 04:00:53 +08:00
|
|
|
// #imports
|
2013-12-11 14:53:41 +01:00
|
|
|
|
2019-01-12 04:00:53 +08:00
|
|
|
// #my-actor
|
2013-12-11 14:53:41 +01:00
|
|
|
public class MyActor extends AbstractActor {
|
2017-03-16 09:30:00 +01:00
|
|
|
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
|
2013-12-11 14:53:41 +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()
|
2019-01-12 04:00:53 +08:00
|
|
|
.match(
|
|
|
|
|
String.class,
|
|
|
|
|
s -> {
|
|
|
|
|
log.info("Received String message: {}", s);
|
|
|
|
|
// #my-actor
|
|
|
|
|
// #reply
|
|
|
|
|
getSender().tell(s, getSelf());
|
|
|
|
|
// #reply
|
|
|
|
|
// #my-actor
|
|
|
|
|
})
|
|
|
|
|
.matchAny(o -> log.info("received unknown message"))
|
|
|
|
|
.build();
|
2013-12-11 14:53:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
2019-01-12 04:00:53 +08:00
|
|
|
// #my-actor
|