private void askClientActorIfStarted(final Command<?> cmd, final Consumer<Object> onSuccess, final Consumer<Throwable> onError, final Runnable onClientActorNotStarted) { if (clientActorRouter != null && connection != null) { askClientActor(cmd, onSuccess, onError); } else { onClientActorNotStarted.run(); } }
private void askClientActorIfStarted(final Command<?> cmd, final Consumer<Object> onSuccess, final Consumer<Throwable> onError, final Runnable onClientActorNotStarted) { if (clientActorRouter != null && connection != null) { askClientActor(cmd, onSuccess, onError); } else { onClientActorNotStarted.run(); } }
private void testConnection(final TestConnection command) { final ActorRef origin = getSender(); final ActorRef self = getSelf(); restoreConnection(command.getConnection()); final PerformTask stopSelfTask = new PerformTask("stop self after test", ConnectionActor::stopSelf); askClientActor(command, response -> { origin.tell(TestConnectionResponse.success(command.getConnectionId(), response.toString(), command.getDittoHeaders()), self); // terminate this actor's supervisor after a connection test again: self.tell(stopSelfTask, ActorRef.noSender()); }, error -> { handleException("test", origin, error); // terminate this actor's supervisor after a connection test again: self.tell(stopSelfTask, ActorRef.noSender()); }); }
private void testConnection(final TestConnection command) { final ActorRef origin = getSender(); final ActorRef self = getSelf(); restoreConnection(command.getConnection()); final PerformTask stopSelfTask = new PerformTask("stop self after test", ConnectionActor::stopSelf); askClientActor(command, response -> { origin.tell(TestConnectionResponse.success(command.getConnectionId(), response.toString(), command.getDittoHeaders()), self); // terminate this actor's supervisor after a connection test again: self.tell(stopSelfTask, ActorRef.noSender()); }, error -> { handleException("test", origin, error); // terminate this actor's supervisor after a connection test again: self.tell(stopSelfTask, ActorRef.noSender()); }); }
private void openConnection(final OpenConnection command) { checkConnectionNotNull(); final ConnectionOpened connectionOpened = ConnectionOpened.of(command.getConnectionId(), command.getDittoHeaders()); final ActorRef origin = getSender(); final ActorRef self = getSelf(); persistEvent(connectionOpened, persistedEvent -> { restoreConnection(connection.toBuilder().connectionStatus(ConnectionStatus.OPEN).build()); askClientActor(command, response -> { final ConnectivityCommandResponse commandResponse = OpenConnectionResponse.of(connectionId, command.getDittoHeaders()); final PerformTask performTask = new PerformTask("open connection", subscribeForEventsAndScheduleResponse(commandResponse, origin)); self.tell(performTask, ActorRef.noSender()); }, error -> handleException("open-connection", origin, error) ); }); }
private void openConnection(final OpenConnection command) { checkConnectionNotNull(); final ConnectionOpened connectionOpened = ConnectionOpened.of(command.getConnectionId(), command.getDittoHeaders()); final ActorRef origin = getSender(); final ActorRef self = getSelf(); persistEvent(connectionOpened, persistedEvent -> { restoreConnection(connection.toBuilder().connectionStatus(ConnectionStatus.OPEN).build()); askClientActor(command, response -> { final ConnectivityCommandResponse commandResponse = OpenConnectionResponse.of(connectionId, command.getDittoHeaders()); final PerformTask performTask = new PerformTask("open connection", subscribeForEventsAndScheduleResponse(commandResponse, origin)); self.tell(performTask, ActorRef.noSender()); }, error -> handleException("open-connection", origin, error) ); }); }
private void handleModifyConnection(final ModifyConnection command, final ActorRef origin) { checkNotNull(connection, "Connection"); final ActorRef self = getSelf(); final ActorRef parent = getContext().getParent(); final DittoHeaders dittoHeaders = command.getDittoHeaders(); final ConnectivityCommandResponse commandResponse = ModifyConnectionResponse.modified(connectionId, dittoHeaders); if (ConnectionStatus.OPEN.equals(connection.getConnectionStatus())) { final OpenConnection openConnectionAfterModification = OpenConnection.of(connectionId, dittoHeaders); log.debug("Desired connection state is {}, forwarding {} to client actor.", connection.getConnectionStatus(), openConnectionAfterModification); askClientActor(openConnectionAfterModification, response -> { final PerformTask performTask = new PerformTask("subscribe for events and schedule ModifyConnectionResponse", subscribeForEventsAndScheduleResponse(commandResponse, origin)); parent.tell(ConnectionSupervisorActor.ManualReset.getInstance(), self); self.tell(performTask, ActorRef.noSender()); }, error -> handleException("connect-after-modify", origin, error) ); } else { log.debug("Desired connection state is {}, do not open connection.", connection.getConnectionStatus()); origin.tell(commandResponse, getSelf()); } }
private void handleModifyConnection(final ModifyConnection command, final ActorRef origin) { checkNotNull(connection, "Connection"); final ActorRef self = getSelf(); final ActorRef parent = getContext().getParent(); final DittoHeaders dittoHeaders = command.getDittoHeaders(); final ConnectivityCommandResponse commandResponse = ModifyConnectionResponse.modified(connectionId, dittoHeaders); if (ConnectionStatus.OPEN.equals(connection.getConnectionStatus())) { final OpenConnection openConnectionAfterModification = OpenConnection.of(connectionId, dittoHeaders); log.debug("Desired connection state is {}, forwarding {} to client actor.", connection.getConnectionStatus(), openConnectionAfterModification); askClientActor(openConnectionAfterModification, response -> { final PerformTask performTask = new PerformTask("subscribe for events and schedule ModifyConnectionResponse", subscribeForEventsAndScheduleResponse(commandResponse, origin)); parent.tell(ConnectionSupervisorActor.ManualReset.getInstance(), self); self.tell(performTask, ActorRef.noSender()); }, error -> handleException("connect-after-modify", origin, error) ); } else { log.debug("Desired connection state is {}, do not open connection.", connection.getConnectionStatus()); origin.tell(commandResponse, getSelf()); } }
connection.getConnectionStatus().getName()); final OpenConnection openConnection = OpenConnection.of(connectionId, command.getDittoHeaders()); askClientActor(openConnection, response -> { final ConnectivityCommandResponse commandResponse =
connection.getConnectionStatus().getName()); final OpenConnection openConnection = OpenConnection.of(connectionId, command.getDittoHeaders()); askClientActor(openConnection, response -> { final ConnectivityCommandResponse commandResponse =
askClientActor(connect, response -> log.info("OpenConnection result: {}", response), error -> handleException("recovery-connect", origin, error)
askClientActor(connect, response -> log.info("OpenConnection result: {}", response), error -> handleException("recovery-connect", origin, error)