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()); }); }
log.info("Received SnapshotOffer containing connection: <{}>", fromSnapshotStore); if (fromSnapshotStore != null) { restoreConnection(fromSnapshotStore); .match(ConnectionCreated.class, event -> restoreConnection(event.getConnection())) .match(ConnectionModified.class, event -> restoreConnection(event.getConnection())) .match(ConnectionOpened.class, event -> restoreConnection(connection != null ? connection.toBuilder() .connectionStatus(ConnectionStatus.OPEN).build() : null)) .match(ConnectionClosed.class, event -> restoreConnection(connection != null ? connection.toBuilder() .connectionStatus(ConnectionStatus.CLOSED).build() : null)) .match(ConnectionDeleted.class, event -> restoreConnection(null)) .match(RecoveryCompleted.class, rc -> { log.info("Connection <{}> was recovered: {}", connectionId, connection); if (m == null) { restoreConnection(null); log.warning("Invalid persistence of Connection <{}>", connectionId); } else {
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()); }); }
log.info("Received SnapshotOffer containing connection: <{}>", fromSnapshotStore); if (fromSnapshotStore != null) { restoreConnection(fromSnapshotStore); .match(ConnectionCreated.class, event -> restoreConnection(event.getConnection())) .match(ConnectionModified.class, event -> restoreConnection(event.getConnection())) .match(ConnectionOpened.class, event -> restoreConnection(connection != null ? connection.toBuilder() .connectionStatus(ConnectionStatus.OPEN).build() : null)) .match(ConnectionClosed.class, event -> restoreConnection(connection != null ? connection.toBuilder() .connectionStatus(ConnectionStatus.CLOSED).build() : null)) .match(ConnectionDeleted.class, event -> restoreConnection(null)) .match(RecoveryCompleted.class, rc -> { log.info("Connection <{}> was recovered: {}", connectionId, connection); if (m == null) { restoreConnection(null); log.warning("Invalid persistence of Connection <{}>", connectionId); } else {
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) ); }); }
restoreConnection(connection.toBuilder().connectionStatus(ConnectionStatus.CLOSED).build());
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()); }); }); }
restoreConnection(persistedEvent.getConnection()); getContext().become(connectionCreatedBehaviour);
restoreConnection(persistedEvent.getConnection()); getContext().become(connectionCreatedBehaviour);