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(); }); }
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) ); }); }
final ActorRef self = getSelf(); persistEvent(connectionClosed, persistedEvent -> { if (connection != null) { restoreConnection(connection.toBuilder().connectionStatus(ConnectionStatus.CLOSED).build());
final ActorRef self = getSelf(); persistEvent(connectionClosed, persistedEvent -> { if (connection != null) { restoreConnection(connection.toBuilder().connectionStatus(ConnectionStatus.CLOSED).build());
private void modifyConnection(final ModifyConnection command) { final ActorRef origin = getSender(); final ActorRef self = getSelf(); if (connection != null && !connection.getConnectionType().equals(command.getConnection().getConnectionType())) { handleException("modify", origin, ConnectionConfigurationInvalidException .newBuilder("ConnectionType <" + connection.getConnectionType().getName() + "> of existing connection <" + connectionId + "> cannot be changed!") .dittoHeaders(command.getDittoHeaders()) .build() ); return; } persistEvent(ConnectionModified.of(command.getConnection(), command.getDittoHeaders()), persistedEvent -> { restoreConnection(persistedEvent.getConnection()); getContext().become(connectionCreatedBehaviour); // if client actor is started: send an artificial CloseConnection command to gracefully disconnect and stop the child actors askClientActorIfStarted(CloseConnection.of(connectionId, DittoHeaders.empty()), onSuccess -> { final PerformTask modifyTask = createModifyConnectionTask(true, command, origin); self.tell(modifyTask, ActorRef.noSender()); }, error -> handleException("connect-after-modify", origin, error), () -> { final PerformTask modifyTask = createModifyConnectionTask(false, command, origin); self.tell(modifyTask, ActorRef.noSender()); }); }); }
private void modifyConnection(final ModifyConnection command) { final ActorRef origin = getSender(); final ActorRef self = getSelf(); if (connection != null && !connection.getConnectionType().equals(command.getConnection().getConnectionType())) { handleException("modify", origin, ConnectionConfigurationInvalidException .newBuilder("ConnectionType <" + connection.getConnectionType().getName() + "> of existing connection <" + connectionId + "> cannot be changed!") .dittoHeaders(command.getDittoHeaders()) .build() ); return; } persistEvent(ConnectionModified.of(command.getConnection(), command.getDittoHeaders()), persistedEvent -> { restoreConnection(persistedEvent.getConnection()); getContext().become(connectionCreatedBehaviour); // if client actor is started: send an artificial CloseConnection command to gracefully disconnect and stop the child actors askClientActorIfStarted(CloseConnection.of(connectionId, DittoHeaders.empty()), onSuccess -> { final PerformTask modifyTask = createModifyConnectionTask(true, command, origin); self.tell(modifyTask, ActorRef.noSender()); }, error -> handleException("connect-after-modify", origin, error), () -> { final PerformTask modifyTask = createModifyConnectionTask(false, command, origin); self.tell(modifyTask, ActorRef.noSender()); }); }); }
final ActorRef parent = getContext().getParent(); persistEvent(ConnectionCreated.of(command.getConnection(), command.getDittoHeaders()), persistedEvent -> { restoreConnection(persistedEvent.getConnection()); getContext().become(connectionCreatedBehaviour);
final ActorRef parent = getContext().getParent(); persistEvent(ConnectionCreated.of(command.getConnection(), command.getDittoHeaders()), persistedEvent -> { restoreConnection(persistedEvent.getConnection()); getContext().become(connectionCreatedBehaviour);