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()); }); }
CreateConnectionResponse.of(connection, command.getDittoHeaders()); final PerformTask performTask = new PerformTask("subscribe for events and schedule CreateConnectionResponse", subscribeForEventsAndScheduleResponse(commandResponse, origin)); parent.tell(ConnectionSupervisorActor.ManualReset.getInstance(), self);
response -> { final PerformTask performTask = new PerformTask( "unsubscribe from events on connection closed, stop client actor and schdeule response", connectionActor -> {
CreateConnectionResponse.of(connection, command.getDittoHeaders()); final PerformTask performTask = new PerformTask("subscribe for events and schedule CreateConnectionResponse", subscribeForEventsAndScheduleResponse(commandResponse, origin)); parent.tell(ConnectionSupervisorActor.ManualReset.getInstance(), self);
response -> { final PerformTask performTask = new PerformTask( "unsubscribe from events on connection closed, stop client actor and schdeule response", connectionActor -> {
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()); } }
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 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 PerformTask createModifyConnectionTask(final boolean stopClientActor, final ModifyConnection command, final ActorRef origin) { final String description = (stopClientActor ? "stop client actor and " : "") + "handle modify connection"; return new PerformTask(description, connectionActor -> { if (stopClientActor) { log.debug("Connection {} was modified, stopping client actor.", connectionId); connectionActor.stopClientActor(); } connectionActor.handleModifyConnection(command, origin); }); }
private PerformTask createModifyConnectionTask(final boolean stopClientActor, final ModifyConnection command, final ActorRef origin) { final String description = (stopClientActor ? "stop client actor and " : "") + "handle modify connection"; return new PerformTask(description, connectionActor -> { if (stopClientActor) { log.debug("Connection {} was modified, stopping client actor.", connectionId); connectionActor.stopClientActor(); } connectionActor.handleModifyConnection(command, origin); }); }