当前位置: 首页>>代码示例>>Java>>正文


Java IRule类代码示例

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


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

示例1: testBuildWithDiscoveryEnabledNIWSServerList

import com.netflix.loadbalancer.IRule; //导入依赖的package包/类
@Test
public void testBuildWithDiscoveryEnabledNIWSServerList() {
    IRule rule = new AvailabilityFilteringRule();
    ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList("dummy:7001");
    ServerListFilter<DiscoveryEnabledServer> filter = new ZoneAffinityServerListFilter<DiscoveryEnabledServer>();
    ZoneAwareLoadBalancer<DiscoveryEnabledServer> lb = LoadBalancerBuilder.<DiscoveryEnabledServer>newBuilder()
            .withDynamicServerList(list)
            .withRule(rule)
            .withServerListFilter(filter)
            .buildDynamicServerListLoadBalancer();
    assertNotNull(lb);
    assertEquals(Lists.newArrayList(expected), lb.getAllServers());
    assertSame(filter, lb.getFilter());
    assertSame(list, lb.getServerListImpl());
    Server server = lb.chooseServer();
    // make sure load balancer does not recreate the server instance
    assertTrue(server instanceof DiscoveryEnabledServer);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:19,代码来源:LBBuilderTest.java

示例2: testBuildWithDiscoveryEnabledNIWSServerListAndUpdater

import com.netflix.loadbalancer.IRule; //导入依赖的package包/类
@Test
public void testBuildWithDiscoveryEnabledNIWSServerListAndUpdater() {
    IRule rule = new AvailabilityFilteringRule();
    ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList("dummy:7001");
    ServerListFilter<DiscoveryEnabledServer> filter = new ZoneAffinityServerListFilter<DiscoveryEnabledServer>();
    ServerListUpdater updater = new PollingServerListUpdater();
    ZoneAwareLoadBalancer<DiscoveryEnabledServer> lb = LoadBalancerBuilder.<DiscoveryEnabledServer>newBuilder()
            .withDynamicServerList(list)
            .withRule(rule)
            .withServerListFilter(filter)
            .withServerListUpdater(updater)
            .buildDynamicServerListLoadBalancerWithUpdater();
    assertNotNull(lb);
    assertEquals(Lists.newArrayList(expected), lb.getAllServers());
    assertSame(filter, lb.getFilter());
    assertSame(list, lb.getServerListImpl());
    assertSame(updater, lb.getServerListUpdater());
    Server server = lb.chooseServer();
    // make sure load balancer does not recreate the server instance
    assertTrue(server instanceof DiscoveryEnabledServer);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:22,代码来源:LBBuilderTest.java

示例3: createLoadBalancer

import com.netflix.loadbalancer.IRule; //导入依赖的package包/类
private LoadBalancer createLoadBalancer(String microserviceName, String loadBalancerName) {
  IRule rule = ExtensionsManager.createLoadBalancerRule(microserviceName);
  LoadBalancer lb = new LoadBalancer(loadBalancerName, rule);

  // we can change this implementation to ExtensionsManager in the future.
  loadServerListFilters(lb);
  // tow lines below is for compatibility, will remove in future
  setIsolationFilter(lb, microserviceName);
  setTransactionControlFilter(lb, microserviceName);

  LOGGER.info("create loadBalancer, microserviceName={}, loadBalancerName={}.", microserviceName, loadBalancerName);
  return lb;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:14,代码来源:LoadbalanceHandler.java

示例4: LoadBalancer

import com.netflix.loadbalancer.IRule; //导入依赖的package包/类
public LoadBalancer(String name, IRule rule) {
  this.name = name;
  this.rule = rule;
  this.rule.setLoadBalancer(this);
  this.lbStats = new LoadBalancerStats(null);
  this.filters = new ConcurrentHashMap<>();
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:8,代码来源:LoadBalancer.java

示例5: createLoadBalancerRule

import com.netflix.loadbalancer.IRule; //导入依赖的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

示例6: loadBalancer

import com.netflix.loadbalancer.IRule; //导入依赖的package包/类
/**
 * The load balancer definition.
 *
 * @param config            the client config.
 * @param serverList        the server list.
 * @param serverListFilter  the server list filter.
 * @param rule              the load balancing rule.
 * @param ping              the ping strategy.
 * @param serverListUpdater the server list updater.
 * @return The Dynamic Server List Load Balancer.
 */
@Bean
@ConditionalOnMissingBean
public ILoadBalancer loadBalancer(IClientConfig config,
                                  ServerList<Server> serverList,
                                  ServerListFilter<Server> serverListFilter,
                                  IRule rule, IPing ping,
                                  ServerListUpdater serverListUpdater) {
    log.debug("dynamic server list load balancer enabled.");
    return new DynamicServerListLoadBalancer<>(config, rule, ping, serverList,
            serverListFilter, serverListUpdater);
}
 
开发者ID:enadim,项目名称:spring-cloud-ribbon-extensions,代码行数:23,代码来源:RuleBaseConfig.java

示例7: ribbonRule

import com.netflix.loadbalancer.IRule; //导入依赖的package包/类
/**
     * 负载均衡策略
     * @return
     */
    @Bean
    public IRule ribbonRule() {
//        return new BestAvailableRule(); //选择一个最小的并发请求的server
//        return new WeightedResponseTimeRule(); //根据相应时间分配一个weight,相应时间越长,weight越小,被选中的可能性越低。
//        return new RetryRule(); //对选定的负载均衡策略机上重试机制。
//        return new RoundRobinRule(); //roundRobin方式轮询选择server
        return new RandomRule(); //随机选择一个server
//        return new ZoneAvoidanceRule(); //复合判断server所在区域的性能和server的可用性选择server
//        return new AvailabilityFilteringRule();
    }
 
开发者ID:hutou-workhouse,项目名称:miscroServiceHello,代码行数:15,代码来源:HelloConfiguration.java

示例8: ribbonLoadBalancer

import com.netflix.loadbalancer.IRule; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public ILoadBalancer ribbonLoadBalancer(IClientConfig config,
										ServerList<Server> serverList, ServerListFilter<Server> serverListFilter,
										IRule rule, IPing ping) {
	ZoneAwareLoadBalancer<Server> balancer = LoadBalancerBuilder.newBuilder()
			.withClientConfig(config).withRule(rule).withPing(ping)
			.withServerListFilter(serverListFilter).withDynamicServerList(serverList)
			.buildDynamicServerListLoadBalancer();
	return new DemoLoadBalancer(balancer);
}
 
开发者ID:spencergibb,项目名称:ribbondemo,代码行数:12,代码来源:RibbonDemoRibbonConfig.java

示例9: chooseRuleForLoadBalancerType

import com.netflix.loadbalancer.IRule; //导入依赖的package包/类
private IRule chooseRuleForLoadBalancerType(LoadBalancerType type) {
	switch (type) {
		case ROUND_ROBIN:
			return getRoundRobinRule();
		case RANDOM:
			return getRandomRule();
		case STICKY:
			return getStickyRule();
		default:
			throw new IllegalArgumentException("Unknown load balancer type " + type);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-zookeeper,代码行数:13,代码来源:DependenciesBasedLoadBalancer.java

示例10: PropertiesFactory

import com.netflix.loadbalancer.IRule; //导入依赖的package包/类
public PropertiesFactory() {
	classToProperty.put(ILoadBalancer.class, "NFLoadBalancerClassName");
	classToProperty.put(IPing.class, "NFLoadBalancerPingClassName");
	classToProperty.put(IRule.class, "NFLoadBalancerRuleClassName");
	classToProperty.put(ServerList.class, "NIWSServerListClassName");
	classToProperty.put(ServerListFilter.class, "NIWSServerListFilterClassName");
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:8,代码来源:PropertiesFactory.java

示例11: ribbonRule

import com.netflix.loadbalancer.IRule; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public IRule ribbonRule(IClientConfig config) {
	if (this.propertiesFactory.isSet(IRule.class, name)) {
		return this.propertiesFactory.get(IRule.class, config, name);
	}
	ZoneAvoidanceRule rule = new ZoneAvoidanceRule();
	rule.initWithNiwsConfig(config);
	return rule;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:11,代码来源:RibbonClientConfiguration.java

示例12: ribbonLoadBalancer

import com.netflix.loadbalancer.IRule; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public ILoadBalancer ribbonLoadBalancer(IClientConfig config,
		ServerList<Server> serverList, ServerListFilter<Server> serverListFilter,
		IRule rule, IPing ping, ServerListUpdater serverListUpdater) {
	if (this.propertiesFactory.isSet(ILoadBalancer.class, name)) {
		return this.propertiesFactory.get(ILoadBalancer.class, config, name);
	}
	return new ZoneAwareLoadBalancer<>(config, rule, ping, serverList,
			serverListFilter, serverListUpdater);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:12,代码来源:RibbonClientConfiguration.java

示例13: loadBalancerRule

import com.netflix.loadbalancer.IRule; //导入依赖的package包/类
@Bean
public IRule loadBalancerRule() {
	// This is a good place to try different load balancing rules and how those rules
	// behave in failure states: BestAvailableRule, WeightedResponseTimeRule, etc

	// This rule just uses a round robin and will skip servers that are in circuit
	// breaker state.
	return new AvailabilityFilteringRule();

}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:11,代码来源:RestTemplateRetryTests.java

示例14: ribbonLoadBalancer

import com.netflix.loadbalancer.IRule; //导入依赖的package包/类
@Bean
public ILoadBalancer ribbonLoadBalancer(IClientConfig config,
		ServerList<Server> serverList, IRule rule, IPing ping) {

	goodServer = new Server("localhost", this.port);
	badServer = new Server("mybadhost", 10001);
	badServer2 = new Server("localhost", SocketUtils.findAvailableTcpPort());

	balancer = LoadBalancerBuilder.newBuilder().withClientConfig(config)
			.withRule(rule).withPing(ping).buildFixedServerListLoadBalancer(
					Arrays.asList(badServer, badServer2, goodServer));
	return balancer;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:14,代码来源:RestTemplateRetryTests.java

示例15: testBuildStaticServerListLoadBalancer

import com.netflix.loadbalancer.IRule; //导入依赖的package包/类
@Test
public void testBuildStaticServerListLoadBalancer() {
    List<Server> list = Lists.newArrayList(expected, expected);
    IRule rule = new AvailabilityFilteringRule();
    IClientConfig clientConfig = IClientConfig.Builder.newBuilder()
            .withDefaultValues()
            .withMaxAutoRetriesNextServer(3).build();

    assertEquals(3, clientConfig.get(Keys.MaxAutoRetriesNextServer).intValue());
    BaseLoadBalancer lb = LoadBalancerBuilder.newBuilder()
            .withRule(rule)
            .buildFixedServerListLoadBalancer(list);
    assertEquals(list, lb.getAllServers());
    assertSame(rule, lb.getRule());
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:16,代码来源:LBBuilderTest.java


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