private void respondWithEmptyMetrics(final RetrieveConnectionMetrics command, final ActorRef origin) { log.debug("ClientActor not started, responding with empty connection metrics with status closed."); final ConnectionMetrics metrics = ConnectivityModelFactory.newConnectionMetrics(ConnectionStatus.CLOSED, "connection is closed", connectionClosedAt != null ? connectionClosedAt : Instant.ofEpochSecond(0), BaseClientState.DISCONNECTED.name(), Collections.emptyList(), Collections.emptyList()); final RetrieveConnectionMetricsResponse metricsResponse = RetrieveConnectionMetricsResponse.of(connectionId, metrics, command.getDittoHeaders()); final String responseType = metricsResponse.getType(); final AggregatedConnectivityCommandResponse response = AggregatedConnectivityCommandResponse.of(connectionId, Collections.singletonList(metricsResponse), responseType, HttpStatusCode.OK, command.getDittoHeaders()); origin.tell(response, getSelf()); }
private void respondWithEmptyMetrics(final RetrieveConnectionMetrics command, final ActorRef origin) { log.debug("ClientActor not started, responding with empty connection metrics with status closed."); final ConnectionMetrics metrics = ConnectivityModelFactory.newConnectionMetrics(ConnectionStatus.CLOSED, "connection is closed", connectionClosedAt != null ? connectionClosedAt : Instant.ofEpochSecond(0), BaseClientState.DISCONNECTED.name(), Collections.emptyList(), Collections.emptyList()); final RetrieveConnectionMetricsResponse metricsResponse = RetrieveConnectionMetricsResponse.of(connectionId, metrics, command.getDittoHeaders()); final String responseType = metricsResponse.getType(); final AggregatedConnectivityCommandResponse response = AggregatedConnectivityCommandResponse.of(connectionId, Collections.singletonList(metricsResponse), responseType, HttpStatusCode.OK, command.getDittoHeaders()); origin.tell(response, getSelf()); }
private DittoRuntimeException unhandledExceptionForSignalInState(final Object signal, final BaseClientState state) { final DittoHeaders headers = signal instanceof WithDittoHeaders ? ((WithDittoHeaders) signal).getDittoHeaders() : DittoHeaders.empty(); switch (state) { case CONNECTING: case DISCONNECTING: return ConnectionSignalIllegalException.newBuilder(connectionId()) .operationName(state.name().toLowerCase()) .timeout(CONNECTING_TIMEOUT) .dittoHeaders(headers) .build(); default: final String signalType = signal instanceof Signal ? ((Signal) signal).getType() : "unknown"; // no need to disclose Java class of signal to clients return ConnectionSignalIllegalException.newBuilder(connectionId()) .illegalSignalForState(signalType, state.name().toLowerCase()) .dittoHeaders(headers) .build(); } }
private DittoRuntimeException unhandledExceptionForSignalInState(final Object signal, final BaseClientState state) { final DittoHeaders headers = signal instanceof WithDittoHeaders ? ((WithDittoHeaders) signal).getDittoHeaders() : DittoHeaders.empty(); switch (state) { case CONNECTING: case DISCONNECTING: return ConnectionSignalIllegalException.newBuilder(connectionId()) .operationName(state.name().toLowerCase()) .timeout(CONNECTING_TIMEOUT) .dittoHeaders(headers) .build(); default: final String signalType = signal instanceof Signal ? ((Signal) signal).getType() : "unknown"; // no need to disclose Java class of signal to clients return ConnectionSignalIllegalException.newBuilder(connectionId()) .illegalSignalForState(signalType, state.name().toLowerCase()) .dittoHeaders(headers) .build(); } }
private FSM.State<BaseClientState, BaseClientData> retrieveConnectionMetrics( final RetrieveConnectionMetrics command, final BaseClientData data) { final ActorRef sender = getSender(); final ActorRef self = getSelf(); final DittoHeaders dittoHeaders = command.getDittoHeaders().toBuilder() .source(org.eclipse.ditto.services.utils.config.ConfigUtil.instanceIdentifier()) .build(); final CompletionStage<List<SourceMetrics>> sourceMetricsFuture = getCurrentSourcesMetrics(); final CompletionStage<List<TargetMetrics>> targetMetricsFuture = getCurrentTargetsMetrics(); final CompletionStage<ConnectionMetrics> metricsFuture = sourceMetricsFuture.thenCompose(sourceMetrics -> targetMetricsFuture.thenApply(targetMetrics -> ConnectivityModelFactory.newConnectionMetrics( getCurrentConnectionStatus(), getCurrentConnectionStatusDetails().orElse(null), getInConnectionStatusSince(), stateName().name(), sourceMetrics, targetMetrics) ) ); metricsFuture.thenAccept(connectionMetrics -> { final Object response = RetrieveConnectionMetricsResponse.of(connectionId(), connectionMetrics, dittoHeaders); sender.tell(response, self); }); return stay(); }
private FSM.State<BaseClientState, BaseClientData> retrieveConnectionMetrics( final RetrieveConnectionMetrics command, final BaseClientData data) { final ActorRef sender = getSender(); final ActorRef self = getSelf(); final DittoHeaders dittoHeaders = command.getDittoHeaders().toBuilder() .source(org.eclipse.ditto.services.utils.config.ConfigUtil.instanceIdentifier()) .build(); final CompletionStage<List<SourceMetrics>> sourceMetricsFuture = getCurrentSourcesMetrics(); final CompletionStage<List<TargetMetrics>> targetMetricsFuture = getCurrentTargetsMetrics(); final CompletionStage<ConnectionMetrics> metricsFuture = sourceMetricsFuture.thenCompose(sourceMetrics -> targetMetricsFuture.thenApply(targetMetrics -> ConnectivityModelFactory.newConnectionMetrics( getCurrentConnectionStatus(), getCurrentConnectionStatusDetails().orElse(null), getInConnectionStatusSince(), stateName().name(), sourceMetrics, targetMetrics) ) ); metricsFuture.thenAccept(connectionMetrics -> { final Object response = RetrieveConnectionMetricsResponse.of(connectionId(), connectionMetrics, dittoHeaders); sender.tell(response, self); }); return stay(); }