io.smallrye.stork.loadbalancer.leastresponsetime.LeastResponseTimeLoadBalancerProviderLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stork-load-balancer-least-response-time Show documentation
Show all versions of stork-load-balancer-least-response-time Show documentation
SmallRye Stork Load Balancer provider based on response time of the reached endpoints
The newest version!
package io.smallrye.stork.loadbalancer.leastresponsetime;
import io.smallrye.stork.loadbalancer.leastresponsetime.LeastResponseTimeConfiguration;
import io.smallrye.stork.loadbalancer.leastresponsetime.LeastResponseTimeLoadBalancerProvider;
import io.smallrye.stork.api.LoadBalancer;
import io.smallrye.stork.api.config.ConfigWithType;
import io.smallrye.stork.api.ServiceDiscovery;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.enterprise.context.ApplicationScoped;
/**
* LoadBalancerLoader for io.smallrye.stork.loadbalancer.leastresponsetime.LeastResponseTimeLoadBalancerProvider
*/
@ApplicationScoped
public class LeastResponseTimeLoadBalancerProviderLoader implements io.smallrye.stork.spi.internal.LoadBalancerLoader {
private final io.smallrye.stork.loadbalancer.leastresponsetime.LeastResponseTimeLoadBalancerProvider provider;
public LeastResponseTimeLoadBalancerProviderLoader() {
io.smallrye.stork.loadbalancer.leastresponsetime.LeastResponseTimeLoadBalancerProvider actual = null;
try {
actual = CDI.current().select(io.smallrye.stork.loadbalancer.leastresponsetime.LeastResponseTimeLoadBalancerProvider.class).get();
} catch(Exception e) {
// Use direct instantiation
actual = new io.smallrye.stork.loadbalancer.leastresponsetime.LeastResponseTimeLoadBalancerProvider();
}
this.provider = actual;
}
@Override
public LoadBalancer createLoadBalancer(ConfigWithType config, ServiceDiscovery serviceDiscovery) {
io.smallrye.stork.loadbalancer.leastresponsetime.LeastResponseTimeConfiguration typedConfig = new io.smallrye.stork.loadbalancer.leastresponsetime.LeastResponseTimeConfiguration(config.parameters());
return provider.createLoadBalancer(typedConfig, serviceDiscovery);
}
/**
* @return the type
*/
@Override
public String type() {
return "least-response-time";
}
}