@Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); jsonObjectBuilder.set(ConnectivityCommandResponse.JsonFields.JSON_CONNECTION_ID, connectionId, predicate); jsonObjectBuilder.set(JSON_CONNECTION_STATUS, connectionStatus.getName(), predicate); }
@Override public WithEntity setEntity(final JsonValue entity) { final ConnectionStatus connectionStatusToSet = ConnectionStatus.forName(entity.asString()).orElse(ConnectionStatus.UNKNOWN); return of(connectionId, connectionStatusToSet, getDittoHeaders()); }
/** * Returns the {@code ConnectionStatus} for the given {@code name} if it exists. * * @param name the name. * @return the ConnectionStatus or an empty optional. */ public static Optional<ConnectionStatus> forName(final CharSequence name) { checkNotNull(name, "Name"); return Arrays.stream(values()) .filter(c -> c.name.contentEquals(name)) .findFirst(); }
getContext().become(connectionCreatedBehaviour); if (ConnectionStatus.OPEN.equals(connection.getConnectionStatus())) { log.debug("Connection <{}> has status <{}> and will therefore be opened.", connection.getId(), connection.getConnectionStatus().getName()); final OpenConnection openConnection = OpenConnection.of(connectionId, command.getDittoHeaders()); askClientActor(openConnection, log.debug("Connection <{}> has status <{}> and will therefore stay closed.", connection.getId(), connection.getConnectionStatus().getName()); respondWithCreateConnectionResponse(connection, command, origin);
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()); } }
getContext().become(connectionCreatedBehaviour); if (ConnectionStatus.OPEN.equals(connection.getConnectionStatus())) { log.debug("Connection <{}> has status <{}> and will therefore be opened.", connection.getId(), connection.getConnectionStatus().getName()); final OpenConnection openConnection = OpenConnection.of(connectionId, command.getDittoHeaders()); askClientActor(openConnection, log.debug("Connection <{}> has status <{}> and will therefore stay closed.", connection.getId(), connection.getConnectionStatus().getName()); respondWithCreateConnectionResponse(connection, command, origin);
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()); } }
@Override protected void appendPayload(final JsonObjectBuilder jsonObjectBuilder, final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); jsonObjectBuilder.set(ConnectivityCommandResponse.JsonFields.JSON_CONNECTION_ID, connectionId, predicate); jsonObjectBuilder.set(JSON_CONNECTION_STATUS, connectionStatus.getName(), predicate); }
@Override public WithEntity setEntity(final JsonValue entity) { final ConnectionStatus connectionStatusToSet = ConnectionStatus.forName(entity.asString()).orElse(ConnectionStatus.UNKNOWN); return of(connectionId, connectionStatusToSet, getDittoHeaders()); }
log.info("Connection <{}> was recovered: {}", connectionId, connection); if (connection != null) { if (ConnectionStatus.OPEN.equals(connection.getConnectionStatus())) { log.debug("Opening connection <{}> after recovery.", connectionId);
/** * Returns the {@code ConnectionStatus} for the given {@code name} if it exists. * * @param name the name. * @return the ConnectionStatus or an empty optional. */ public static Optional<ConnectionStatus> forName(final CharSequence name) { checkNotNull(name, "Name"); return Arrays.stream(values()) .filter(c -> c.name.contentEquals(name)) .findFirst(); }
@Override public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); final JsonObjectBuilder jsonObjectBuilder = JsonFactory.newObjectBuilder(); jsonObjectBuilder.set(JsonFields.CONNECTION_STATUS, connectionStatus.getName(), predicate); if (connectionStatusDetails != null) { jsonObjectBuilder.set(JsonFields.CONNECTION_STATUS_DETAILS, connectionStatusDetails, predicate); } jsonObjectBuilder.set(JsonFields.IN_CONNECTION_STATUS_SINCE, inConnectionStatusSince.toString(), predicate); jsonObjectBuilder.set(JsonFields.CLIENT_STATE, clientState, predicate); jsonObjectBuilder.set(JsonFields.SOURCES_METRICS, sourcesMetrics.stream() .map(SourceMetrics::toJson) .collect(JsonCollectors.valuesToArray()), predicate); jsonObjectBuilder.set(JsonFields.TARGETS_METRICS, targetsMetrics.stream() .map(TargetMetrics::toJson) .collect(JsonCollectors.valuesToArray()), predicate); return jsonObjectBuilder.build(); }
private static ConnectionStatus getConnectionStatusOrThrow(final JsonObject jsonObject) { final String readConnectionStatus = jsonObject.getValueOrThrow(JsonFields.CONNECTION_STATUS); return ConnectionStatus.forName(readConnectionStatus) .orElseThrow(() -> JsonParseException.newBuilder() .message(MessageFormat.format("Connection status <{0}> is invalid!", readConnectionStatus)) .build()); }
log.info("Connection <{}> was recovered: {}", connectionId, connection); if (connection != null) { if (ConnectionStatus.OPEN.equals(connection.getConnectionStatus())) { log.debug("Opening connection <{}> after recovery.", connectionId);
@Override public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); final JsonObjectBuilder jsonObjectBuilder = JsonFactory.newObjectBuilder(); jsonObjectBuilder.set(JsonFields.CONNECTION_STATUS, connectionStatus.getName(), predicate); if (connectionStatusDetails != null) { jsonObjectBuilder.set(JsonFields.CONNECTION_STATUS_DETAILS, connectionStatusDetails, predicate); } jsonObjectBuilder.set(JsonFields.IN_CONNECTION_STATUS_SINCE, inConnectionStatusSince.toString(), predicate); jsonObjectBuilder.set(JsonFields.CLIENT_STATE, clientState, predicate); jsonObjectBuilder.set(JsonFields.SOURCES_METRICS, sourcesMetrics.stream() .map(SourceMetrics::toJson) .collect(JsonCollectors.valuesToArray()), predicate); jsonObjectBuilder.set(JsonFields.TARGETS_METRICS, targetsMetrics.stream() .map(TargetMetrics::toJson) .collect(JsonCollectors.valuesToArray()), predicate); return jsonObjectBuilder.build(); }
private static ConnectionStatus getConnectionStatusOrThrow(final JsonObject jsonObject) { final String readConnectionStatus = jsonObject.getValueOrThrow(JsonFields.CONNECTION_STATUS); return ConnectionStatus.forName(readConnectionStatus) .orElseThrow(() -> JsonParseException.newBuilder() .message(MessageFormat.format("Connection status <{0}> is invalid!", readConnectionStatus)) .build()); }
@Override public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); final JsonObjectBuilder jsonObjectBuilder = JsonFactory.newObjectBuilder(); jsonObjectBuilder.set(JsonFields.SCHEMA_VERSION, schemaVersion.toInt(), predicate); jsonObjectBuilder.set(JsonFields.STATUS, status.getName(), predicate); if (statusDetails != null) { jsonObjectBuilder.set(JsonFields.STATUS_DETAILS, statusDetails, predicate); } jsonObjectBuilder.set(JsonFields.MESSAGE_COUNT, messageCount, predicate); if (lastMessageAt != null) { jsonObjectBuilder.set(JsonFields.LAST_MESSAGE_AT, lastMessageAt.toString(), predicate); } return jsonObjectBuilder.build(); }
/** * Creates a new {@code AddressMetric} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the AddressMetric to be created. * @return a new AddressMetric which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static AddressMetric fromJson(final JsonObject jsonObject) { final ConnectionStatus readConnectionStatus = ConnectionStatus.forName( jsonObject.getValueOrThrow(JsonFields.STATUS)).orElse(ConnectionStatus.UNKNOWN); final String readConnectionStatusDetails = jsonObject.getValue(JsonFields.STATUS_DETAILS) .orElse(null); final long readConsumedMessages = jsonObject.getValueOrThrow(JsonFields.MESSAGE_COUNT); final Instant readLastMessageAt = jsonObject.getValue(JsonFields.LAST_MESSAGE_AT).map(Instant::parse) .orElse(null); return ImmutableAddressMetric.of(readConnectionStatus, readConnectionStatusDetails, readConsumedMessages, readLastMessageAt); }
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); jsonObjectBuilder.set(JsonFields.SOURCES, sources.stream()
final ConnectionStatus readConnectionStatus = ConnectionStatus.forName( jsonObject.getValueOrThrow(JsonFields.CONNECTION_STATUS)).orElse(ConnectionStatus.UNKNOWN); final String readConnectionStatusDetails = jsonObject.getValue(JsonFields.CONNECTION_STATUS_DETAILS)