private void sendBackAggregatedResults() { if (origin != null && originHeaders != null && !aggregatedResults.isEmpty()) { final String responseType = aggregatedResults.get(0).getType(); final AggregatedConnectivityCommandResponse response = AggregatedConnectivityCommandResponse.of(connectionId, aggregatedResults, responseType, HttpStatusCode.OK, originHeaders); log.debug("Aggregated response: {}", response); origin.tell(response, getSelf()); } else if (origin != null && originHeaders != null && !aggregatedStatus.isEmpty()) { log.debug("Aggregated statuses: {}", aggregatedStatus); final Optional<Status.Status> failure = aggregatedStatus.entrySet().stream() .filter(s -> s.getValue() instanceof Status.Failure) .map(Map.Entry::getValue) .findFirst(); if (failure.isPresent()) { origin.tell(failure.get(), getSelf()); } else { final String aggregatedStatusStr = aggregatedStatus.entrySet().stream() .map(Object::toString) .collect(Collectors.joining(",")); origin.tell(new Status.Success(aggregatedStatusStr), getSelf()); } } else { log.warning("No origin was present or results were empty in order to send back aggregated results to"); } getContext().stop(getSelf()); } }
AggregateActor.props(connectionId, clientActorRouter, connection.getClientCount(), responseTimeout)); PatternsCS.ask(aggregationActor, cmd, clientActorAskTimeout.toMillis()) .whenComplete((response, exception) -> {
AggregateActor.props(connectionId, clientActorRouter, connection.getClientCount(), timeout)); PatternsCS.ask(aggregationActor, cmd, timeout) .whenComplete((response, exception) -> {
return ReceiveBuilder.create() .match(Command.class, command -> { clientActor.tell(new Broadcast(command), getSelf()); originHeaders = command.getDittoHeaders(); origin = getSender(); getContext().setReceiveTimeout( Duration.create(timeout / 2.0, TimeUnit.MILLISECONDS)); }) .match(ReceiveTimeout.class, timeout -> { sendBackAggregatedResults(); }) .matchAny(any -> { aggregatedResults.add((CommandResponse<?>) any); } else if (any instanceof Status.Status) { aggregatedStatus.put(getSender().path().address().hostPort(), (Status.Status) any); } else if (any instanceof DittoRuntimeException) { if (expectedResponses == responseCount) { sendBackAggregatedResults();
private void sendBackAggregatedResults() { if (origin != null && originHeaders != null && !aggregatedResults.isEmpty()) { final String responseType = aggregatedResults.get(0).getType(); final AggregatedConnectivityCommandResponse response = AggregatedConnectivityCommandResponse.of(connectionId, aggregatedResults, responseType, HttpStatusCode.OK, originHeaders); log.debug("Aggregated response: {}", response); origin.tell(response, getSelf()); } else if (origin != null && originHeaders != null && !aggregatedStatus.isEmpty()) { log.debug("Aggregated statuses: {}", aggregatedStatus); final Optional<Status.Status> failure = aggregatedStatus.entrySet().stream() .filter(s -> s.getValue() instanceof Status.Failure) .map(Map.Entry::getValue) .findFirst(); if (failure.isPresent()) { origin.tell(failure.get(), getSelf()); } else { final String aggregatedStatusStr = aggregatedStatus.entrySet().stream() .map(Object::toString) .collect(Collectors.joining(",")); origin.tell(new Status.Success(aggregatedStatusStr), getSelf()); } } else { log.warning("No origin was present or results were empty in order to send back aggregated results to"); } getContext().stop(getSelf()); } }
return ReceiveBuilder.create() .match(Command.class, command -> { clientActor.tell(new Broadcast(command), getSelf()); originHeaders = command.getDittoHeaders(); origin = getSender(); getContext().setReceiveTimeout( Duration.create(timeout / 2.0, TimeUnit.MILLISECONDS)); }) .match(ReceiveTimeout.class, timeout -> { sendBackAggregatedResults(); }) .matchAny(any -> { aggregatedResults.add((CommandResponse<?>) any); } else if (any instanceof Status.Status) { aggregatedStatus.put(getSender().path().address().hostPort(), (Status.Status) any); } else if (any instanceof DittoRuntimeException) { if (expectedResponses == responseCount) { sendBackAggregatedResults();