Search in sources :

Example 1 with LoadBalanceFactory

use of rpc.turbo.loadbalance.LoadBalanceFactory in project turbo-rpc by hank-whu.

the class AppConfig method parse.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static AppConfig parse(Config config) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException {
    String group = getStringOrElse(config, "group", TurboService.DEFAULT_GROUP);
    String app = getStringOrElse(config, "app", TurboService.DEFAULT_GROUP);
    int globalTimeout = getIntOrElse(config, "globalTimeout", 0);
    int maxRequestWait = getIntOrElse(config, "maxRequestWait", 10000);
    int connectPerServer = getIntOrElse(config, "connectPerServer", 1);
    int serverErrorThreshold = getIntOrElse(config, "serverErrorThreshold", 16);
    int connectErrorThreshold = getIntOrElse(config, "connectErrorThreshold", 2 * serverErrorThreshold / connectPerServer);
    String serializerClass = getStringOrElse(config, "serializer.class", ProtostuffSerializer.class.getName());
    Serializer serializer = (Serializer) // 
    Class.forName(// 
    serializerClass).getDeclaredConstructor().newInstance();
    String loadBalanceFactoryClass = getStringOrElse(config, "loadBalanceFactory.class", RoundRobinLoadBalanceFactory.class.getName());
    LoadBalanceFactory loadBalanceFactory = (LoadBalanceFactory) // 
    Class.forName(// 
    loadBalanceFactoryClass).getDeclaredConstructor().newInstance();
    String discoverClass = getStringOrElse(config, "discover.class", DirectConnectDiscover.class.getName());
    List<String> discoverAddressList = config.getStringList("discover.address");
    Discover discover = (Discover) // 
    Class.forName(// 
    discoverClass).getDeclaredConstructor().newInstance();
    List<HostPort> hostPorts = // 
    discoverAddressList.stream().map(// 
    str -> new HostPort(str)).collect(Collectors.toList());
    discover.init(hostPorts);
    AppConfig appConfig = new AppConfig();
    appConfig.setGroup(group);
    appConfig.setApp(app);
    appConfig.setSerializer(serializer);
    appConfig.setGlobalTimeout(globalTimeout);
    appConfig.setMaxRequestWait(maxRequestWait);
    appConfig.setConnectPerServer(connectPerServer);
    appConfig.setServerErrorThreshold(serverErrorThreshold);
    appConfig.setConnectErrorThreshold(connectErrorThreshold);
    appConfig.setLoadBalanceFactory(loadBalanceFactory);
    appConfig.setDiscover(discover);
    return appConfig;
}
Also used : Discover(rpc.turbo.discover.Discover) Serializer(rpc.turbo.serialization.Serializer) Config(com.typesafe.config.Config) TurboService(rpc.turbo.annotation.TurboService) ConfigUtils.getStringOrElse(rpc.turbo.config.ConfigUtils.getStringOrElse) DirectConnectDiscover(rpc.turbo.discover.DirectConnectDiscover) ProtostuffSerializer(rpc.turbo.serialization.protostuff.ProtostuffSerializer) ConfigException(rpc.turbo.config.ConfigException) Collectors(java.util.stream.Collectors) LoadBalanceFactory(rpc.turbo.loadbalance.LoadBalanceFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) HostPort(rpc.turbo.config.HostPort) Weightable(rpc.turbo.loadbalance.Weightable) ConfigUtils.getIntOrElse(rpc.turbo.config.ConfigUtils.getIntOrElse) RoundRobinLoadBalanceFactory(rpc.turbo.loadbalance.RoundRobinLoadBalanceFactory) HostPort(rpc.turbo.config.HostPort) LoadBalanceFactory(rpc.turbo.loadbalance.LoadBalanceFactory) RoundRobinLoadBalanceFactory(rpc.turbo.loadbalance.RoundRobinLoadBalanceFactory) Discover(rpc.turbo.discover.Discover) DirectConnectDiscover(rpc.turbo.discover.DirectConnectDiscover) ProtostuffSerializer(rpc.turbo.serialization.protostuff.ProtostuffSerializer) DirectConnectDiscover(rpc.turbo.discover.DirectConnectDiscover) RoundRobinLoadBalanceFactory(rpc.turbo.loadbalance.RoundRobinLoadBalanceFactory) Serializer(rpc.turbo.serialization.Serializer) ProtostuffSerializer(rpc.turbo.serialization.protostuff.ProtostuffSerializer)

Aggregations

Config (com.typesafe.config.Config)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 TurboService (rpc.turbo.annotation.TurboService)1 ConfigException (rpc.turbo.config.ConfigException)1 ConfigUtils.getIntOrElse (rpc.turbo.config.ConfigUtils.getIntOrElse)1 ConfigUtils.getStringOrElse (rpc.turbo.config.ConfigUtils.getStringOrElse)1 HostPort (rpc.turbo.config.HostPort)1 DirectConnectDiscover (rpc.turbo.discover.DirectConnectDiscover)1 Discover (rpc.turbo.discover.Discover)1 LoadBalanceFactory (rpc.turbo.loadbalance.LoadBalanceFactory)1 RoundRobinLoadBalanceFactory (rpc.turbo.loadbalance.RoundRobinLoadBalanceFactory)1 Weightable (rpc.turbo.loadbalance.Weightable)1 Serializer (rpc.turbo.serialization.Serializer)1 ProtostuffSerializer (rpc.turbo.serialization.protostuff.ProtostuffSerializer)1