Java Code Examples for akka.japi.pf.ReceiveBuilder#create()

The following examples show how to use akka.japi.pf.ReceiveBuilder#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractBackgroundStreamingActorWithConfigWithStatusReport.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private Receive sleeping() {
    final ReceiveBuilder sleepingReceiveBuilder = ReceiveBuilder.create();
    preEnhanceSleepingBehavior(sleepingReceiveBuilder);
    return sleepingReceiveBuilder.match(WokeUp.class, this::wokeUp)
            .match(Event.class, this::addCustomEventToLog)
            .match(RetrieveHealth.class, this::retrieveHealth)
            .match(Shutdown.class, this::shutdownStream)
            .build()
            .orElse(retrieveConfigBehavior())
            .orElse(modifyConfigBehavior());
}
 
Example 2
Source File: AbstractBackgroundStreamingActorWithConfigWithStatusReport.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private Receive streaming() {
    final ReceiveBuilder streamingReceiveBuilder = ReceiveBuilder.create();
    preEnhanceStreamingBehavior(streamingReceiveBuilder);
    return streamingReceiveBuilder
            .match(StreamTerminated.class, this::streamTerminated)
            .match(Event.class, this::addCustomEventToLog)
            .match(RetrieveHealth.class, this::retrieveHealth)
            .match(Shutdown.class, this::shutdownStream)
            .build()
            .orElse(retrieveConfigBehavior())
            .orElse(modifyConfigBehavior());
}
 
Example 3
Source File: AbstractGraphActor.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Receive createReceive() {
    final SourceQueueWithComplete<T> sourceQueue = getSourceQueue(materializer);

    final ReceiveBuilder receiveBuilder = ReceiveBuilder.create();
    preEnhancement(receiveBuilder);
    return receiveBuilder
            .match(DittoRuntimeException.class, this::handleDittoRuntimeException)
            .match(matchClass, match -> handleMatched(sourceQueue, match))
            .match(Throwable.class, this::handleUnknownThrowable)
            .matchAny(message -> logger.warning("Received unknown message <{}>.", message))
            .build();
}
 
Example 4
Source File: AbstractProxyActor.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Receive createReceive() {
    final ReceiveBuilder receiveBuilder = ReceiveBuilder.create();

    // common commands
    receiveBuilder
            .match(RetrieveStatistics.class, retrieveStatistics -> {
                log.debug("Got 'RetrieveStatistics' message");
                statisticsActor.forward(retrieveStatistics, getContext());
            })
            .match(RetrieveStatisticsDetails.class, retrieveStatisticsDetails -> {
                log.debug("Got 'RetrieveStatisticsDetails' message");
                statisticsActor.forward(retrieveStatisticsDetails, getContext());
            });

    // specific commands
    addCommandBehaviour(receiveBuilder);

    // specific responses
    addResponseBehaviour(receiveBuilder);

    // specific errors
    addErrorBehaviour(receiveBuilder);

    // common errors
    receiveBuilder
            .match(Status.Failure.class, failure -> {
                Throwable cause = failure.cause();
                if (cause instanceof JsonRuntimeException) {
                    cause = new DittoJsonException((RuntimeException) cause);
                }
                getSender().tell(cause, getSelf());
            })
            .match(DittoRuntimeException.class, cre -> getSender().tell(cre, getSelf()))
            .match(DistributedPubSubMediator.SubscribeAck.class, subscribeAck ->
                    getLogger().debug("Successfully subscribed to distributed pub/sub on topic '{}'",
                            subscribeAck.subscribe().topic())
            )
            .matchAny(m -> getLogger().warning("Got unknown message, expected a 'Command': {}", m));

    return receiveBuilder.build();
}