/** * Creates a new {@code ImmutableAddressMetric} instance. * * @param status the current status of the connection * @param statusDetails the optional status details * @param consumedMessages the current message count * @param lastMessageAt the timestamp when the last message was consumed/published * @return a new instance of ImmutableAddressMetric */ public static ImmutableAddressMetric of(final ConnectionStatus status, @Nullable final String statusDetails, final long consumedMessages, @Nullable final Instant lastMessageAt) { return new ImmutableAddressMetric(status, statusDetails, consumedMessages, lastMessageAt); }
/** * Creates a new {@code AddressMetric} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the Connection 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 addressMetricFromJson(final JsonObject jsonObject) { return ImmutableAddressMetric.fromJson(jsonObject); }
/** * Returns a new {@code AddressMetric}. * * @param status the ConnectionStatus of the source metrics to create * @param statusDetails the optional details about the connection status * @param messageCount the amount of totally consumed/published messages * @param lastMessageAt the timestamp when the last message was consumed/published * @return a new AddressMetric which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if any parameter is {@code null}. */ public static AddressMetric newAddressMetric(final ConnectionStatus status, @Nullable final String statusDetails, final long messageCount, @Nullable final Instant lastMessageAt) { return ImmutableAddressMetric.of(status, statusDetails, messageCount, lastMessageAt); }
@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.ADDRESS_METRICS, addressMetrics.entrySet().stream() .map(e -> ImmutableAddressMetric.toJsonField(e.getKey(), e.getValue())) .collect(JsonCollectors.fieldsToObject()), predicate); jsonObjectBuilder.set(JsonFields.CONSUMED_MESSAGES, consumedMessages, predicate); return jsonObjectBuilder.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.ADDRESS_METRICS, addressMetrics.entrySet().stream() .map(e -> ImmutableAddressMetric.toJsonField(e.getKey(), e.getValue())) .collect(JsonCollectors.fieldsToObject()), predicate); jsonObjectBuilder.set(JsonFields.PUBLISHED_MESSAGES, publishedMessages, predicate); return jsonObjectBuilder.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.ADDRESS_METRICS, addressMetrics.entrySet().stream() .map(e -> ImmutableAddressMetric.toJsonField(e.getKey(), e.getValue())) .collect(JsonCollectors.fieldsToObject()), predicate); jsonObjectBuilder.set(JsonFields.PUBLISHED_MESSAGES, publishedMessages, predicate); return jsonObjectBuilder.build(); }
/** * Returns a new {@code AddressMetric}. * * @param status the ConnectionStatus of the source metrics to create * @param statusDetails the optional details about the connection status * @param messageCount the amount of totally consumed/published messages * @param lastMessageAt the timestamp when the last message was consumed/published * @return a new AddressMetric which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if any parameter is {@code null}. */ public static AddressMetric newAddressMetric(final ConnectionStatus status, @Nullable final String statusDetails, final long messageCount, @Nullable final Instant lastMessageAt) { return ImmutableAddressMetric.of(status, statusDetails, messageCount, lastMessageAt); }
/** * Creates a new {@code AddressMetric} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the Connection 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 addressMetricFromJson(final JsonObject jsonObject) { return ImmutableAddressMetric.fromJson(jsonObject); }
/** * Creates a new {@code ImmutableAddressMetric} instance. * * @param status the current status of the connection * @param statusDetails the optional status details * @param consumedMessages the current message count * @param lastMessageAt the timestamp when the last message was consumed/published * @return a new instance of ImmutableAddressMetric */ public static ImmutableAddressMetric of(final ConnectionStatus status, @Nullable final String statusDetails, final long consumedMessages, @Nullable final Instant lastMessageAt) { return new ImmutableAddressMetric(status, statusDetails, consumedMessages, lastMessageAt); }
@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.ADDRESS_METRICS, addressMetrics.entrySet().stream() .map(e -> ImmutableAddressMetric.toJsonField(e.getKey(), e.getValue())) .collect(JsonCollectors.fieldsToObject()), predicate); jsonObjectBuilder.set(JsonFields.CONSUMED_MESSAGES, consumedMessages, 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); }
/** * 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); }