Skip to content

Commit

Permalink
Simplified CheckConnectionLogsActive class. Removed unnecessary Ditto…
Browse files Browse the repository at this point in the history
…Headers and made them optional.

Signed-off-by: David Joos <david.joos@bosch-si.com>
  • Loading branch information
David Joos committed May 13, 2019
1 parent 2eacc54 commit 721c9fb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,7 @@ private void performTask(final PerformTask performTask) {
}

private void checkLoggingEnabled() {
CheckConnectionLogsActive checkLoggingActive = CheckConnectionLogsActive.of(connectionId,
DittoHeaders.empty(), Instant.now());
CheckConnectionLogsActive checkLoggingActive = CheckConnectionLogsActive.of(connectionId, Instant.now());
if (clientActorRouter != null) {
// forward command to all client actors with no sender
clientActorRouter.tell(new Broadcast(checkLoggingActive), ActorRef.noSender());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ public final class CheckConnectionLogsActive extends AbstractCommand<CheckConnec
private final String connectionId;
private final Instant timestamp;

private CheckConnectionLogsActive(final String connectionId, final DittoHeaders dittoHeaders,
private CheckConnectionLogsActive(final String connectionId,
final Instant timestamp) {
super(TYPE, DittoHeaders.empty());
this.connectionId = connectionId;
this.timestamp = timestamp;
}

private CheckConnectionLogsActive(final String connectionId,
final Instant timestamp, final DittoHeaders dittoHeaders) {
super(TYPE, dittoHeaders);
this.connectionId = connectionId;
this.timestamp = timestamp;
Expand All @@ -53,57 +60,81 @@ private CheckConnectionLogsActive(final String connectionId, final DittoHeaders
* Creates a new instance of {@code CheckConnectionLogsActive}.
*
* @param connectionId the connection for which logging should be enabled.
* @param dittoHeaders the headers of the request.
* @return a new instance of the command.
* @throws java.lang.NullPointerException if any argument is {@code null}.
*/
public static CheckConnectionLogsActive of(final String connectionId, final DittoHeaders dittoHeaders,
public static CheckConnectionLogsActive of(final String connectionId,
final Instant timestamp) {
checkNotNull(connectionId, "Connection ID");
checkNotNull(timestamp, "timestamp");
return new CheckConnectionLogsActive(connectionId, dittoHeaders, timestamp);
return new CheckConnectionLogsActive(connectionId, timestamp);
}

/**
* Creates a new instance of {@code CheckConnectionLogsActive}.
*
* @param connectionId the connection for which logging should be enabled.
* @return a new instance of the command.
* @throws java.lang.NullPointerException if any argument is {@code null}.
*/
public static CheckConnectionLogsActive of(final String connectionId,
final Instant timestamp, final DittoHeaders dittoHeaders) {
checkNotNull(connectionId, "Connection ID");
checkNotNull(timestamp, "timestamp");
return new CheckConnectionLogsActive(connectionId, timestamp, dittoHeaders);
}

/**
* Creates a new {@code CheckConnectionLogsActive} from a JSON string.
*
* @param jsonString the JSON containing the command.
* @param dittoHeaders the headers of the command.
* @return the command.
* @throws NullPointerException if {@code jsonString} is {@code null}.
* @throws IllegalArgumentException if {@code jsonString} is empty.
* @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonString} was not in the expected
* format.
*/
public static CheckConnectionLogsActive fromJson(final String jsonString, final DittoHeaders dittoHeaders,
public static CheckConnectionLogsActive fromJson(final String jsonString,
final Instant timestamp) {
return fromJson(JsonFactory.newObject(jsonString), dittoHeaders, timestamp);
return fromJson(JsonFactory.newObject(jsonString), timestamp);
}

/**
* Creates a new {@code CheckConnectionLogsActive} from a JSON object.
*
* @param jsonObject the JSON containing the command.
* @param dittoHeaders the headers of the command.
* @return the command.
* @throws NullPointerException if {@code jsonObject} is {@code null}.
* @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected
* format.
*/
public static CheckConnectionLogsActive fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders,
public static CheckConnectionLogsActive fromJson(final JsonObject jsonObject,
Instant timestamp) {
return new CommandJsonDeserializer<CheckConnectionLogsActive>(TYPE, jsonObject).deserialize(() -> {
final String readConnectionId =
jsonObject.getValueOrThrow(ConnectivityCommand.JsonFields.JSON_CONNECTION_ID);

return of(readConnectionId, dittoHeaders, timestamp);
return of(readConnectionId, timestamp);
});
}

/* unused */
public static CheckConnectionLogsActive fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) {
public static CheckConnectionLogsActive fromJson(final JsonObject jsonObject) {
final Instant now = Instant.now();
return CheckConnectionLogsActive.fromJson(jsonObject, dittoHeaders, now);
return CheckConnectionLogsActive.fromJson(jsonObject, now);
}

public static CheckConnectionLogsActive fromJson(final JsonObject jsonObject, final Instant timestamp,
final DittoHeaders dittoHeaders) {
return new CommandJsonDeserializer<CheckConnectionLogsActive>(TYPE, jsonObject).deserialize(() -> {
final String readConnectionId =
jsonObject.getValueOrThrow(ConnectivityCommand.JsonFields.JSON_CONNECTION_ID);
return of(readConnectionId, timestamp, dittoHeaders);
});
}

public static CheckConnectionLogsActive fromJson(final String jsonString, final Instant timestamp,
final DittoHeaders dittoHeaders) {
return fromJson(JsonFactory.newObject(jsonString), timestamp, dittoHeaders);
}

@Override
Expand All @@ -129,7 +160,7 @@ public Category getCategory() {

@Override
public CheckConnectionLogsActive setDittoHeaders(final DittoHeaders dittoHeaders) {
return of(connectionId, dittoHeaders, timestamp);
return of(connectionId, timestamp);
}

@Override
Expand Down

0 comments on commit 721c9fb

Please sign in to comment.