private static ConnectionType getConnectionTypeOrThrow(final JsonObject jsonObject) { final String readConnectionType = jsonObject.getValueOrThrow(JsonFields.CONNECTION_TYPE); return ConnectionType.forName(readConnectionType) .orElseThrow(() -> JsonParseException.newBuilder() .message(MessageFormat.format("Connection type <{0}> is invalid!", readConnectionType)) .build()); }
/** * Returns the {@code ConnectionType} for the given {@code name} if it exists. * * @param name the name. * @return the ConnectionType or an empty optional. */ public static Optional<ConnectionType> forName(final CharSequence name) { checkNotNull(name, "Name"); return Arrays.stream(values()) .filter(c -> c.name.contentEquals(name)) .findFirst(); }
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()); }); }); }
jsonObjectBuilder.set(JsonFields.ID, id, predicate); jsonObjectBuilder.set(JsonFields.NAME, name, predicate); jsonObjectBuilder.set(JsonFields.CONNECTION_TYPE, connectionType.getName(), predicate); jsonObjectBuilder.set(JsonFields.CONNECTION_STATUS, connectionStatus.getName(), predicate); jsonObjectBuilder.set(JsonFields.URI, uri.toString(), predicate);
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()); }); }); }
jsonObjectBuilder.set(JsonFields.ID, id, predicate); jsonObjectBuilder.set(JsonFields.NAME, name, predicate); jsonObjectBuilder.set(JsonFields.CONNECTION_TYPE, connectionType.getName(), predicate); jsonObjectBuilder.set(JsonFields.CONNECTION_STATUS, connectionStatus.getName(), predicate); jsonObjectBuilder.set(JsonFields.URI, uri.toString(), predicate);
private static ConnectionType getConnectionTypeOrThrow(final JsonObject jsonObject) { final String readConnectionType = jsonObject.getValueOrThrow(JsonFields.CONNECTION_TYPE); return ConnectionType.forName(readConnectionType) .orElseThrow(() -> JsonParseException.newBuilder() .message(MessageFormat.format("Connection type <{0}> is invalid!", readConnectionType)) .build()); }
/** * Returns the {@code ConnectionType} for the given {@code name} if it exists. * * @param name the name. * @return the ConnectionType or an empty optional. */ public static Optional<ConnectionType> forName(final CharSequence name) { checkNotNull(name, "Name"); return Arrays.stream(values()) .filter(c -> c.name.contentEquals(name)) .findFirst(); }