All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.smallrye.stork.loadbalancer.leastresponsetime.LeastResponseTimeLoadBalancerProviderLoader Maven / Gradle / Ivy

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";
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy