private void unsubscribeFromEvents() { forEachPubSubTopicDo(pubSubTopic -> { log.debug("Unsubscribing from pub-sub topic <{}> for connection <{}>.", pubSubTopic, connectionId); final DistributedPubSubMediator.Unsubscribe unsubscribe = new DistributedPubSubMediator.Unsubscribe(pubSubTopic, PUB_SUB_GROUP_PREFIX + connectionId, getSelf()); pubSubMediator.tell(unsubscribe, getSelf()); }); }
private void unsubscribeFromEvents() { forEachPubSubTopicDo(pubSubTopic -> { log.debug("Unsubscribing from pub-sub topic <{}> for connection <{}>.", pubSubTopic, connectionId); final DistributedPubSubMediator.Unsubscribe unsubscribe = new DistributedPubSubMediator.Unsubscribe(pubSubTopic, PUB_SUB_GROUP_PREFIX + connectionId, getSelf()); pubSubMediator.tell(unsubscribe, getSelf()); }); }
private void respondWithCreateConnectionResponse(final Connection connection, final CreateConnection command, final ActorRef origin) { origin.tell(CreateConnectionResponse.of(connection, command.getDittoHeaders()), getSelf()); getContext().getParent().tell(ConnectionSupervisorActor.ManualReset.getInstance(), getSelf()); }
private void respondWithCreateConnectionResponse(final Connection connection, final CreateConnection command, final ActorRef origin) { origin.tell(CreateConnectionResponse.of(connection, command.getDittoHeaders()), getSelf()); getContext().getParent().tell(ConnectionSupervisorActor.ManualReset.getInstance(), getSelf()); }
private void stopSelf() { log.debug("Shutting down"); // stop the supervisor (otherwise it'd restart this actor) which causes this actor to stop, too. getContext().getParent().tell(PoisonPill.getInstance(), getSelf()); }
private void stopSelf() { log.debug("Shutting down"); // stop the supervisor (otherwise it'd restart this actor) which causes this actor to stop, too. getContext().getParent().tell(PoisonPill.getInstance(), getSelf()); }
private <E extends Event> void persistEvent(final E event, final Consumer<E> consumer) { persist(event, persistedEvent -> { log.debug("Successfully persisted Event <{}>.", persistedEvent.getType()); consumer.accept(persistedEvent); pubSubMediator.tell(new DistributedPubSubMediator.Publish(event.getType(), event, true), getSelf()); // save a snapshot if there were too many changes since the last snapshot if ((lastSequenceNr() - lastSnapshotSequenceNr) > snapshotThreshold) { doSaveSnapshot(); } }); }
private void retrieveConnectionStatus(final RetrieveConnectionStatus command) { checkConnectionNotNull(); getSender().tell(RetrieveConnectionStatusResponse.of(connectionId, connection.getConnectionStatus(), command.getDittoHeaders()), getSelf()); }
private void schedulePendingResponse(final ConnectivityCommandResponse response, final ActorRef sender) { getContext().system().scheduler() .scheduleOnce(flushPendingResponsesTimeout, sender, response, getContext().dispatcher(), getSelf()); }
private <E extends Event> void persistEvent(final E event, final Consumer<E> consumer) { persist(event, persistedEvent -> { log.debug("Successfully persisted Event <{}>.", persistedEvent.getType()); consumer.accept(persistedEvent); pubSubMediator.tell(new DistributedPubSubMediator.Publish(event.getType(), event, true), getSelf()); // save a snapshot if there were too many changes since the last snapshot if ((lastSequenceNr() - lastSnapshotSequenceNr) > snapshotThreshold) { doSaveSnapshot(); } }); }
private void retrieveConnectionMetrics(final RetrieveConnectionMetrics command) { checkConnectionNotNull(); final ActorRef origin = getSender(); askClientActorIfStarted(command, response -> origin.tell(response, getSelf()), error -> handleException("retrieve-metrics", origin, error), () -> respondWithEmptyMetrics(command, origin)); }
private void retrieveConnectionStatus(final RetrieveConnectionStatus command) { checkConnectionNotNull(); getSender().tell(RetrieveConnectionStatusResponse.of(connectionId, connection.getConnectionStatus(), command.getDittoHeaders()), getSelf()); }
private void retrieveConnectionMetrics(final RetrieveConnectionMetrics command) { checkConnectionNotNull(); final ActorRef origin = getSender(); askClientActorIfStarted(command, response -> origin.tell(response, getSelf()), error -> handleException("retrieve-metrics", origin, error), () -> respondWithEmptyMetrics(command, origin)); }
private void schedulePendingResponse(final ConnectivityCommandResponse response, final ActorRef sender) { getContext().system().scheduler() .scheduleOnce(flushPendingResponsesTimeout, sender, response, getContext().dispatcher(), getSelf()); }
private void stopSelfIfDeletedAfterDelay() { final ExecutionContextExecutor dispatcher = getContext().dispatcher(); cancelStopSelfIfDeletedTrigger(); stopSelfIfDeletedTrigger = getContext().system() .scheduler() .scheduleOnce(DELETED_ACTOR_LIFETIME, getSelf(), STOP_SELF_IF_DELETED, dispatcher, ActorRef.noSender()); }
private void stopSelfIfDeletedAfterDelay() { final ExecutionContextExecutor dispatcher = getContext().dispatcher(); cancelStopSelfIfDeletedTrigger(); stopSelfIfDeletedTrigger = getContext().system() .scheduler() .scheduleOnce(DELETED_ACTOR_LIFETIME, getSelf(), STOP_SELF_IF_DELETED, dispatcher, ActorRef.noSender()); }
private void handleCommandDuringInitialization(final ConnectivityCommand command) { log.debug("Unexpected command during initialization of actor received: {} - " + "Terminating this actor and sending 'ConnectionNotAccessibleException' to requester ...", command.getType()); getSender().tell(ConnectionNotAccessibleException.newBuilder(command.getId()) .dittoHeaders(command.getDittoHeaders()) .build(), getSelf()); }
private void handleCommandDuringInitialization(final ConnectivityCommand command) { log.debug("Unexpected command during initialization of actor received: {} - " + "Terminating this actor and sending 'ConnectionNotAccessibleException' to requester ...", command.getType()); getSender().tell(ConnectionNotAccessibleException.newBuilder(command.getId()) .dittoHeaders(command.getDittoHeaders()) .build(), getSelf()); }
private void deleteConnection(final DeleteConnection command) { final ConnectionDeleted connectionDeleted = ConnectionDeleted.of(command.getConnectionId(), command.getDittoHeaders()); final ActorRef origin = getSender(); final ActorRef self = getSelf(); persistEvent(connectionDeleted, persistedEvent -> { stopClientActor(); origin.tell(DeleteConnectionResponse.of(connectionId, command.getDittoHeaders()), self); stopSelf(); // All subscriptions stop automatically once this actor stops. // connectionActor.unsubscribeFromEvents(); }); }
private void deleteConnection(final DeleteConnection command) { final ConnectionDeleted connectionDeleted = ConnectionDeleted.of(command.getConnectionId(), command.getDittoHeaders()); final ActorRef origin = getSender(); final ActorRef self = getSelf(); persistEvent(connectionDeleted, persistedEvent -> { stopClientActor(); origin.tell(DeleteConnectionResponse.of(connectionId, command.getDittoHeaders()), self); stopSelf(); // All subscriptions stop automatically once this actor stops. // connectionActor.unsubscribeFromEvents(); }); }