-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added AddressMetric used in SourceMetrics and TargetMetrics
* those contain metrics about a single sourceAddress or targetAddress * gathered the information when ConnectionMetrics are requested Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch-si.com>
- Loading branch information
Showing
17 changed files
with
663 additions
and
266 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
model/connectivity/src/main/java/org/eclipse/ditto/model/connectivity/AddressMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright (c) 2017 Bosch Software Innovations GmbH. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/org/documents/epl-2.0/index.php | ||
* | ||
* Contributors: | ||
* Bosch Software Innovations GmbH - initial contribution | ||
*/ | ||
package org.eclipse.ditto.model.connectivity; | ||
|
||
import java.util.Optional; | ||
|
||
import javax.annotation.concurrent.Immutable; | ||
|
||
import org.eclipse.ditto.json.JsonFactory; | ||
import org.eclipse.ditto.json.JsonField; | ||
import org.eclipse.ditto.json.JsonFieldDefinition; | ||
import org.eclipse.ditto.json.JsonFieldSelector; | ||
import org.eclipse.ditto.json.JsonObject; | ||
import org.eclipse.ditto.model.base.json.FieldType; | ||
import org.eclipse.ditto.model.base.json.JsonSchemaVersion; | ||
import org.eclipse.ditto.model.base.json.Jsonifiable; | ||
|
||
/** | ||
* TODO doc | ||
*/ | ||
public interface AddressMetric extends Jsonifiable.WithFieldSelectorAndPredicate<JsonField> { | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
ConnectionStatus getStatus(); | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
Optional<String> getStatusDetails(); | ||
|
||
/** | ||
* | ||
* @return | ||
*/ | ||
long getMessageCount(); | ||
|
||
/** | ||
* Returns all non hidden marked fields of this {@code AddressMetric}. | ||
* | ||
* @return a JSON object representation of this Source including only non hidden marked fields. | ||
*/ | ||
@Override | ||
default JsonObject toJson() { | ||
return toJson(FieldType.notHidden()); | ||
} | ||
|
||
@Override | ||
default JsonObject toJson(final JsonSchemaVersion schemaVersion, final JsonFieldSelector fieldSelector) { | ||
return toJson(schemaVersion, FieldType.notHidden()).get(fieldSelector); | ||
} | ||
|
||
/** | ||
* An enumeration of the known {@code JsonField}s of an {@code AddressMetric}. | ||
*/ | ||
@Immutable | ||
final class JsonFields { | ||
|
||
/** | ||
* JSON field containing the {@code JsonSchemaVersion}. | ||
*/ | ||
public static final JsonFieldDefinition<Integer> SCHEMA_VERSION = | ||
JsonFactory.newIntFieldDefinition(JsonSchemaVersion.getJsonKey(), FieldType.SPECIAL, FieldType.HIDDEN, | ||
JsonSchemaVersion.V_1, JsonSchemaVersion.V_2); | ||
|
||
/** | ||
* JSON field containing the {@code ConnectionStatus} value. | ||
*/ | ||
public static final JsonFieldDefinition<String> STATUS = | ||
JsonFactory.newStringFieldDefinition("status", FieldType.REGULAR, JsonSchemaVersion.V_1, | ||
JsonSchemaVersion.V_2); | ||
|
||
/** | ||
* JSON field containing the {@code ConnectionStatus} details. | ||
*/ | ||
public static final JsonFieldDefinition<String> STATUS_DETAILS = | ||
JsonFactory.newStringFieldDefinition("statusDetails", FieldType.REGULAR, JsonSchemaVersion.V_1, | ||
JsonSchemaVersion.V_2); | ||
|
||
/** | ||
* JSON field containing the amount of consumed/published messages. | ||
*/ | ||
public static final JsonFieldDefinition<Long> MESSAGE_COUNT = | ||
JsonFactory.newLongFieldDefinition("messageCount", FieldType.REGULAR, JsonSchemaVersion.V_1, | ||
JsonSchemaVersion.V_2); | ||
|
||
private JsonFields() { | ||
throw new AssertionError(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...nnectivity/src/main/java/org/eclipse/ditto/model/connectivity/ImmutableAddressMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright (c) 2017 Bosch Software Innovations GmbH. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/org/documents/epl-2.0/index.php | ||
* | ||
* Contributors: | ||
* Bosch Software Innovations GmbH - initial contribution | ||
*/ | ||
package org.eclipse.ditto.model.connectivity; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.function.Predicate; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.annotation.concurrent.Immutable; | ||
|
||
import org.eclipse.ditto.json.JsonFactory; | ||
import org.eclipse.ditto.json.JsonField; | ||
import org.eclipse.ditto.json.JsonObject; | ||
import org.eclipse.ditto.json.JsonObjectBuilder; | ||
import org.eclipse.ditto.model.base.json.JsonSchemaVersion; | ||
|
||
/** | ||
* Immutable implementation of {@link AddressMetric}. | ||
*/ | ||
@Immutable | ||
final class ImmutableAddressMetric implements AddressMetric { | ||
|
||
private final ConnectionStatus status; | ||
@Nullable private final String statusDetails; | ||
private final long messageCount; | ||
|
||
private ImmutableAddressMetric(final ConnectionStatus status, @Nullable final String statusDetails, | ||
final long messageCount) { | ||
this.status = status; | ||
this.statusDetails = statusDetails; | ||
this.messageCount = messageCount; | ||
} | ||
|
||
/** | ||
* TODO Doc | ||
*/ | ||
public static ImmutableAddressMetric of(final ConnectionStatus status, @Nullable final String statusDetails, | ||
final long consumedMessages) { | ||
return new ImmutableAddressMetric(status, statusDetails, consumedMessages); | ||
} | ||
|
||
@Override | ||
public ConnectionStatus getStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public Optional<String> getStatusDetails() { | ||
return Optional.ofNullable(statusDetails); | ||
} | ||
|
||
@Override | ||
public long getMessageCount() { | ||
return messageCount; | ||
} | ||
|
||
@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); | ||
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); | ||
return ImmutableAddressMetric.of(readConnectionStatus, readConnectionStatusDetails, readConsumedMessages); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) {return true;} | ||
if (!(o instanceof ImmutableAddressMetric)) {return false;} | ||
final ImmutableAddressMetric that = (ImmutableAddressMetric) o; | ||
return status == that.status && | ||
Objects.equals(statusDetails, that.statusDetails) && | ||
messageCount == that.messageCount; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(status, statusDetails, messageCount); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + " [" + | ||
"status=" + status + | ||
", statusDetails=" + statusDetails + | ||
", messageCount=" + messageCount + | ||
"]"; | ||
} | ||
} |
Oops, something went wrong.