use of io.helidon.lra.coordinator.client.CoordinatorClient in project helidon by oracle.
the class CoordinatorLocatorService method coordinatorClient.
@Produces
@ApplicationScoped
CoordinatorClient coordinatorClient() {
List<CoordinatorClient> candidates = HelidonServiceLoader.create(ServiceLoader.load(CoordinatorClient.class)).asList();
if (candidates.isEmpty()) {
throw new DeploymentException("No coordinator adapter found");
}
if (candidates.size() > 1) {
throw new DeploymentException("Ambiguous coordinator adapter candidates found: " + candidates.stream().map(CoordinatorClient::getClass).map(Class::getName).collect(Collectors.joining(",")));
}
CoordinatorClient client = candidates.stream().findFirst().get();
if (clientFqdn.isPresent()) {
Optional<CoordinatorClient> selectedClient = candidates.stream().filter(c -> c.getClass().getName().equals(clientFqdn.get())).findFirst();
client = selectedClient.orElseThrow(() -> new DeploymentException("Configured coordinator adapter " + clientFqdn.get() + " not found."));
}
client.init(() -> coordinatorUriSupplier.get(), coordinatorTimeout, coordinatorTimeoutUnit);
return client;
}
Aggregations