private static <T> List<CompletableFuture<T>> sendCommandToRemoteAddresses(final ActorSystem actorSystem,
final SimpleCommand command,
final Set<String> reachable,
final RemoteResponseTransformer<Object, Throwable, T> responseTransformer) {
final Duration healthCheckServiceTimeout =
actorSystem.settings().config().getDuration(ConfigKeys.HEALTH_CHECK_SERVICE_TIMEOUT);
return reachable.stream()
.map(addressString -> addressString + STATUS_SUPPLIER_PATH)
.map(actorSystem::actorSelection)
.map(selection -> {
final String addressString = selection.toSerializationFormat()
.substring(selection.toSerializationFormat().indexOf('@') + 1)
.replace(STATUS_SUPPLIER_PATH, "");
return PatternsCS.ask(selection, command, healthCheckServiceTimeout)
.handle((response, throwable) ->
responseTransformer.apply(response, throwable, addressString))
.toCompletableFuture();
})
.collect(Collectors.toList());
}