Search in sources :

Example 1 with ApplicationScoped

use of jakarta.enterprise.context.ApplicationScoped 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;
}
Also used : CONF_KEY_COORDINATOR_TIMEOUT(io.helidon.lra.coordinator.client.CoordinatorClient.CONF_KEY_COORDINATOR_TIMEOUT) CONF_DEFAULT_COORDINATOR_URL(io.helidon.lra.coordinator.client.CoordinatorClient.CONF_DEFAULT_COORDINATOR_URL) ApplicationScoped(jakarta.enterprise.context.ApplicationScoped) CONF_KEY_COORDINATOR_URL(io.helidon.lra.coordinator.client.CoordinatorClient.CONF_KEY_COORDINATOR_URL) ServiceLoader(java.util.ServiceLoader) HelidonServiceLoader(io.helidon.common.serviceloader.HelidonServiceLoader) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) DeploymentException(jakarta.enterprise.inject.spi.DeploymentException) Optional(java.util.Optional) CoordinatorClient(io.helidon.lra.coordinator.client.CoordinatorClient) URI(java.net.URI) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) Reflected(io.helidon.common.Reflected) Inject(jakarta.inject.Inject) Produces(jakarta.enterprise.inject.Produces) CONF_KEY_COORDINATOR_TIMEOUT_UNIT(io.helidon.lra.coordinator.client.CoordinatorClient.CONF_KEY_COORDINATOR_TIMEOUT_UNIT) CoordinatorClient(io.helidon.lra.coordinator.client.CoordinatorClient) DeploymentException(jakarta.enterprise.inject.spi.DeploymentException) Produces(jakarta.enterprise.inject.Produces) ApplicationScoped(jakarta.enterprise.context.ApplicationScoped)

Aggregations

Reflected (io.helidon.common.Reflected)1 HelidonServiceLoader (io.helidon.common.serviceloader.HelidonServiceLoader)1 CoordinatorClient (io.helidon.lra.coordinator.client.CoordinatorClient)1 CONF_DEFAULT_COORDINATOR_URL (io.helidon.lra.coordinator.client.CoordinatorClient.CONF_DEFAULT_COORDINATOR_URL)1 CONF_KEY_COORDINATOR_TIMEOUT (io.helidon.lra.coordinator.client.CoordinatorClient.CONF_KEY_COORDINATOR_TIMEOUT)1 CONF_KEY_COORDINATOR_TIMEOUT_UNIT (io.helidon.lra.coordinator.client.CoordinatorClient.CONF_KEY_COORDINATOR_TIMEOUT_UNIT)1 CONF_KEY_COORDINATOR_URL (io.helidon.lra.coordinator.client.CoordinatorClient.CONF_KEY_COORDINATOR_URL)1 ApplicationScoped (jakarta.enterprise.context.ApplicationScoped)1 Produces (jakarta.enterprise.inject.Produces)1 DeploymentException (jakarta.enterprise.inject.spi.DeploymentException)1 Inject (jakarta.inject.Inject)1 URI (java.net.URI)1 List (java.util.List)1 Optional (java.util.Optional)1 ServiceLoader (java.util.ServiceLoader)1 TimeUnit (java.util.concurrent.TimeUnit)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 ConfigProperty (org.eclipse.microprofile.config.inject.ConfigProperty)1