• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java WeightedResponseTimeRule类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.netflix.loadbalancer.WeightedResponseTimeRule的典型用法代码示例。如果您正苦于以下问题:Java WeightedResponseTimeRule类的具体用法?Java WeightedResponseTimeRule怎么用?Java WeightedResponseTimeRule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WeightedResponseTimeRule类属于com.netflix.loadbalancer包,在下文中一共展示了WeightedResponseTimeRule类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: build

import com.netflix.loadbalancer.WeightedResponseTimeRule; //导入依赖的package包/类
public ZoneAwareLoadBalancer<Server> build(String schemeName) {
  String servicename = URI.create(schemeName).getHost();
  log.info("creating a loadbalancer {} ", servicename);
  final DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
  clientConfig.setClientName(servicename);
  clientConfig.set(CommonClientConfigKey.ServerListRefreshInterval, 300 * 1000);

  return LoadBalancerBuilder.newBuilder().withClientConfig(clientConfig)
      .withRule(new WeightedResponseTimeRule()).withDynamicServerList(factory.build(servicename))
      .buildDynamicServerListLoadBalancer();
}
 
开发者ID:januslabs,项目名称:consul-ribbon-starter,代码行数:12,代码来源:ConsulRibbonLoadBalancer.java


示例2: createLoadBalancerRule

import com.netflix.loadbalancer.WeightedResponseTimeRule; //导入依赖的package包/类
@Override
public IRule createLoadBalancerRule(String ruleName) {
  if (RULE_RoundRobin.equals(ruleName)) {
    return new RoundRobinRule();
  } else if (RULE_Random.equals(ruleName)) {
    return new RandomRule();
  } else if (RULE_WeightedResponse.equals(ruleName)) {
    return new WeightedResponseTimeRule();
  } else if (RULE_SessionStickiness.equals(ruleName)) {
    return new SessionStickinessRule();
  } else {
    throw new IllegalStateException("unexpected code to reach here, value is " + ruleName);
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:15,代码来源:RuleNameExtentionsFactory.java


示例3: testRuleName

import com.netflix.loadbalancer.WeightedResponseTimeRule; //导入依赖的package包/类
@Test
public void testRuleName() {
  System.setProperty("cse.loadbalance.mytest1.strategy.name", "RoundRobin");
  System.setProperty("cse.loadbalance.mytest2.strategy.name", "Random");
  System.setProperty("cse.loadbalance.mytest3.strategy.name", "WeightedResponse");
  System.setProperty("cse.loadbalance.mytest4.strategy.name", "SessionStickiness");

  BeansHolder holder = new BeansHolder();
  List<ExtensionsFactory> extensionsFactories = new ArrayList<>();
  extensionsFactories.add(new RuleClassNameExtentionsFactory());
  extensionsFactories.add(new RuleNameExtentionsFactory());
  extensionsFactories.add(new DefaultRetryExtensionsFactory());
  Deencapsulation.setField(holder, "extentionsFactories", extensionsFactories);
  holder.init();

  Assert.assertEquals(RoundRobinRule.class.getName(),
      ExtensionsManager.createLoadBalancerRule("mytest1").getClass().getName());
  Assert.assertEquals(RandomRule.class.getName(),
      ExtensionsManager.createLoadBalancerRule("mytest2").getClass().getName());
  Assert.assertEquals(WeightedResponseTimeRule.class.getName(),
      ExtensionsManager.createLoadBalancerRule("mytest3").getClass().getName());
  Assert.assertEquals(SessionStickinessRule.class.getName(),
      ExtensionsManager.createLoadBalancerRule("mytest4").getClass().getName());

  System.getProperties().remove("cse.loadbalance.mytest1.strategy.name");
  System.getProperties().remove("cse.loadbalance.mytest2.strategy.name");
  System.getProperties().remove("cse.loadbalance.mytest3.strategy.name");
  System.getProperties().remove("cse.loadbalance.mytest4.strategy.name");
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:30,代码来源:TestExtensionsManager.java


示例4: testRuleClassName

import com.netflix.loadbalancer.WeightedResponseTimeRule; //导入依赖的package包/类
@Test
public void testRuleClassName() {
  System.setProperty("cse.loadbalance.mytest1.NFLoadBalancerRuleClassName",
      "com.netflix.loadbalancer.RoundRobinRule");
  System.setProperty("cse.loadbalance.mytest2.NFLoadBalancerRuleClassName",
      "com.netflix.loadbalancer.WeightedResponseTimeRule");
  System.setProperty("cse.loadbalance.mytest3.NFLoadBalancerRuleClassName", "com.netflix.loadbalancer.RandomRule");
  System.setProperty("cse.loadbalance.mytest4.NFLoadBalancerRuleClassName",
      "org.apache.servicecomb.loadbalance.SessionStickinessRule");

  BeansHolder holder = new BeansHolder();
  List<ExtensionsFactory> extensionsFactories = new ArrayList<>();
  extensionsFactories.add(new RuleClassNameExtentionsFactory());
  extensionsFactories.add(new RuleNameExtentionsFactory());
  extensionsFactories.add(new DefaultRetryExtensionsFactory());
  Deencapsulation.setField(holder, "extentionsFactories", extensionsFactories);
  holder.init();

  Assert.assertEquals(RoundRobinRule.class.getName(),
      ExtensionsManager.createLoadBalancerRule("mytest1").getClass().getName());
  Assert.assertEquals(WeightedResponseTimeRule.class.getName(),
      ExtensionsManager.createLoadBalancerRule("mytest2").getClass().getName());
  Assert.assertEquals(RandomRule.class.getName(),
      ExtensionsManager.createLoadBalancerRule("mytest3").getClass().getName());
  Assert.assertEquals(SessionStickinessRule.class.getName(),
      ExtensionsManager.createLoadBalancerRule("mytest4").getClass().getName());

  System.getProperties().remove("cse.loadbalance.mytest1.NFLoadBalancerRuleClassName");
  System.getProperties().remove("cse.loadbalance.mytest2.NFLoadBalancerRuleClassName");
  System.getProperties().remove("cse.loadbalance.mytest3.NFLoadBalancerRuleClassName");
  System.getProperties().remove("cse.loadbalance.mytest4.NFLoadBalancerRuleClassName");

  Assert.assertEquals(DefaultLoadBalancerRetryHandler.class.getName(),
      ExtensionsManager.createRetryHandler("mytest1").getClass().getName());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:36,代码来源:TestExtensionsManager.java


示例5: build

import com.netflix.loadbalancer.WeightedResponseTimeRule; //导入依赖的package包/类
/**
 * Builds a new {@link RibbonJerseyClient} with an existing Jersey Client
 * and service discoverer
 *
 * @param name
 *            Client name
 * @param jerseyClient
 *            Jersey Client
 * @param serviceDiscoverer
 *            Service discoverer
 * @return new RibbonJerseyClient
 */
public RibbonJerseyClient build(@Nonnull final String name,
        @Nonnull final Client jerseyClient,
        @Nonnull final ConsulServiceDiscoverer serviceDiscoverer) {

    // dynamic server list that is refreshed from Consul
    final ConsulServerList serverList = new ConsulServerList(consul,
            serviceDiscoverer);

    // build a new load balancer based on the configuration
    final DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
    clientConfig.setClientName(name);
    clientConfig.set(CommonClientConfigKey.ServerListRefreshInterval,
            Ints.checkedCast(
                    configuration.getRefreshInterval().toMilliseconds()));

    final ZoneAwareLoadBalancer<Server> loadBalancer = LoadBalancerBuilder
            .newBuilder().withClientConfig(clientConfig)
            .withRule(new WeightedResponseTimeRule())
            .withDynamicServerList(serverList)
            .buildDynamicServerListLoadBalancer();

    final RibbonJerseyClient client = new RibbonJerseyClient(
            configuration.getScheme(), loadBalancer, jerseyClient);

    environment.lifecycle().manage(new Managed() {
        @Override
        public void start() throws Exception {
            // nothing to start
        }

        @Override
        public void stop() throws Exception {
            client.close();
        }
    });
    return client;
}
 
开发者ID:smoketurner,项目名称:dropwizard-consul,代码行数:50,代码来源:RibbonJerseyClientBuilder.java


示例6: testServerWeights

import com.netflix.loadbalancer.WeightedResponseTimeRule; //导入依赖的package包/类
@Test
public void testServerWeights(){
    try{
        ConfigurationManager.loadPropertiesFromResources("sample-client.properties"); 

        ConfigurationManager.getConfigInstance().setProperty(
                "sample-client.ribbon.NFLoadBalancerClassName", "com.netflix.loadbalancer.DynamicServerListLoadBalancer");
        ConfigurationManager.getConfigInstance().setProperty(
                "sample-client.ribbon.NFLoadBalancerRuleClassName", "com.netflix.loadbalancer.WeightedResponseTimeRule");
        // shorter weight adjusting interval
        ConfigurationManager.getConfigInstance().setProperty(
                "sample-client.ribbon." + WeightedResponseTimeRule.WEIGHT_TASK_TIMER_INTERVAL_CONFIG_KEY, "5000");
        ConfigurationManager.getConfigInstance().setProperty(
                "sample-client.ribbon.InitializeNFLoadBalancer", "true");       

        RestClient client = (RestClient) ClientFactory.getNamedClient("sample-client"); 

        HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build(); 

        for (int i = 0; i < 20; i++) {
            client.executeWithLoadBalancer(request);
        }
        System.out.println(((AbstractLoadBalancer) client.getLoadBalancer()).getLoadBalancerStats());
        // wait for the weights to be adjusted
        Thread.sleep(5000);
        for (int i = 0; i < 50; i++) {
            client.executeWithLoadBalancer(request);
        }
        System.out.println(((AbstractLoadBalancer) client.getLoadBalancer()).getLoadBalancerStats());
    }
    catch (Exception e){
        e.printStackTrace();
    }
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:35,代码来源:ResponseTimeWeightedRuleTest.java


示例7: ribbonRule

import com.netflix.loadbalancer.WeightedResponseTimeRule; //导入依赖的package包/类
@Bean
public IRule ribbonRule(IClientConfig config) {
	WeightedResponseTimeRule rule = new WeightedResponseTimeRule();
	rule.initWithNiwsConfig(config);
	return rule;
}
 
开发者ID:spencergibb,项目名称:ribbondemo,代码行数:7,代码来源:RibbonDemoRibbonConfig.java



注:本文中的com.netflix.loadbalancer.WeightedResponseTimeRule类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CodeableConceptDt类代码示例发布时间:2022-05-22
下一篇:
Java CtFieldReference类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap