io.smallrye.stork.servicediscovery.composite.CompositeServiceDiscoveryProviderLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stork-service-discovery-composite Show documentation
Show all versions of stork-service-discovery-composite Show documentation
A service discovery provider that combines multiple service discoveries.
The mechanism returns services from _all_ the discovery providers that it combines,
That is, it obtains service lists from all services and just then returns a combined list.
The newest version!
package io.smallrye.stork.servicediscovery.composite;
import io.smallrye.stork.servicediscovery.composite.CompositeConfiguration;
import io.smallrye.stork.servicediscovery.composite.CompositeServiceDiscoveryProvider;
import io.smallrye.stork.api.ServiceDiscovery;
import io.smallrye.stork.api.config.ConfigWithType;
import io.smallrye.stork.api.config.ServiceConfig;
import io.smallrye.stork.spi.StorkInfrastructure;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.enterprise.context.ApplicationScoped;
/**
* ServiceDiscoveryLoader for {@link io.smallrye.stork.servicediscovery.composite.CompositeServiceDiscoveryProvider}
*/
@ApplicationScoped
public class CompositeServiceDiscoveryProviderLoader implements io.smallrye.stork.spi.internal.ServiceDiscoveryLoader {
private final io.smallrye.stork.servicediscovery.composite.CompositeServiceDiscoveryProvider provider;
public CompositeServiceDiscoveryProviderLoader() {
io.smallrye.stork.servicediscovery.composite.CompositeServiceDiscoveryProvider actual = null;
try {
actual = CDI.current().select(io.smallrye.stork.servicediscovery.composite.CompositeServiceDiscoveryProvider.class).get();
} catch(Exception e) {
// Use direct instantiation
actual = new io.smallrye.stork.servicediscovery.composite.CompositeServiceDiscoveryProvider();
}
this.provider = actual;
}
@Override
public ServiceDiscovery createServiceDiscovery(ConfigWithType config, String serviceName,
ServiceConfig serviceConfig, StorkInfrastructure storkInfrastructure) {
io.smallrye.stork.servicediscovery.composite.CompositeConfiguration typedConfig = new io.smallrye.stork.servicediscovery.composite.CompositeConfiguration(config.parameters());
return provider.createServiceDiscovery(typedConfig, serviceName, serviceConfig, storkInfrastructure);
}
/**
* @return the type
*/
@Override
public String type() {
return "composite";
}
}