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
This commit is contained in:
parent
3617fe8b41
commit
4bd6b7aab1
157 changed files with 3290 additions and 8882 deletions
|
|
@ -5,13 +5,14 @@ package docs.circuitbreaker;
|
|||
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.ReceiveTimeout;
|
||||
import akka.actor.UntypedActor;
|
||||
import akka.actor.AbstractActor.Receive;
|
||||
import akka.actor.AbstractActor;
|
||||
import akka.event.Logging;
|
||||
import akka.event.LoggingAdapter;
|
||||
import akka.pattern.CircuitBreaker;
|
||||
import scala.concurrent.duration.Duration;
|
||||
|
||||
public class TellPatternJavaActor extends UntypedActor {
|
||||
public class TellPatternJavaActor extends AbstractActor {
|
||||
|
||||
private final ActorRef target;
|
||||
private final CircuitBreaker breaker;
|
||||
|
|
@ -35,16 +36,21 @@ public class TellPatternJavaActor extends UntypedActor {
|
|||
|
||||
//#circuit-breaker-tell-pattern
|
||||
@Override
|
||||
public void onReceive(Object payload) {
|
||||
if ( "call".equals(payload) && breaker.isClosed() ) {
|
||||
target.tell("message", getSelf());
|
||||
} else if ( "response".equals(payload) ) {
|
||||
breaker.succeed();
|
||||
} else if ( payload instanceof Throwable ) {
|
||||
breaker.fail();
|
||||
} else if ( payload instanceof ReceiveTimeout ) {
|
||||
breaker.fail();
|
||||
}
|
||||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(String.class, payload -> "call".equals(payload) && breaker.isClosed(), payload ->
|
||||
target.tell("message", self())
|
||||
)
|
||||
.matchEquals("response", payload ->
|
||||
breaker.succeed()
|
||||
)
|
||||
.match(Throwable.class, t ->
|
||||
breaker.fail()
|
||||
)
|
||||
.match(ReceiveTimeout.class, t ->
|
||||
breaker.fail()
|
||||
)
|
||||
.build();
|
||||
}
|
||||
//#circuit-breaker-tell-pattern
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue