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

Java LoadBalancerBuilder类代码示例

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

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



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

示例1: updateLoadBalancer

import com.netflix.loadbalancer.LoadBalancerBuilder; //导入依赖的package包/类
private void updateLoadBalancer(List<Server> newServers) {
	if (serviceServers == null) {
		serviceServers = new HashSet<Server>();
	}
	if (newServers == null) {
		newServers = new ArrayList<Server>();
	}
	//return if nothing changed
	if ((serviceServers.isEmpty() && newServers.isEmpty())
		|| (newServers.size() == serviceServers.size() && serviceServers.containsAll(newServers))) {
		return;
	}
	serviceServers = new HashSet<Server>(newServers);
	loadBalancerModificationLock.writeLock().lock();
	if (loadBalancer != null) {
		loadBalancer.shutdown();
	}
	loadBalancer = LoadBalancerBuilder.newBuilder().buildFixedServerListLoadBalancer(newServers);
	for (EndpointClientCollection<?> lb : endpointMap.values()) {
		lb.updateServers(newServers);
	}
	loadBalancerModificationLock.writeLock().unlock();
}
 
开发者ID:DescartesResearch,项目名称:Pet-Supply-Store,代码行数:24,代码来源:ServiceLoadBalancer.java


示例2: setup

import com.netflix.loadbalancer.LoadBalancerBuilder; //导入依赖的package包/类
@Before
public void setup() throws Exception {
	zookeeperServer = new TestingServer(2181, true);

	ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration("localhost", 2181, "/services");

	zookeeperServiceDiscovery = new ZookeeperServiceDiscovery(zookeeperConfiguration);
	zookeeperServiceDiscovery.register(new ZookeeperInstance("myApi", "localhost", 7080, Collections.emptyMap()));
	zookeeperServiceDiscovery.register(new ZookeeperInstance("myApi", "localhost", 7081, Collections.emptyMap()));
	zookeeperServiceDiscovery.register(new ZookeeperInstance("myApi", "localhost", 7082, Collections.emptyMap()));

	ZookeeperServers zookeeperServers = new ZookeeperServers("myApi", zookeeperServiceDiscovery);

	ILoadBalancer loadBalancer = LoadBalancerBuilder.newBuilder()
			.withDynamicServerList(zookeeperServers)
				.buildDynamicServerListLoadBalancer();

	RibbonHttpClientRequestFactory ribbonHttpClientRequestFactory = new RibbonHttpClientRequestFactory(loadBalancer, new RibbonZookeeperExceptionHandler(zookeeperServiceDiscovery));

	myApi = new RestifyProxyBuilder()
			.client(ribbonHttpClientRequestFactory)
			.target(MyApi.class, "http://myApi")
			.build();
}
 
开发者ID:ljtfreitas,项目名称:java-restify,代码行数:25,代码来源:ZookeeperServiceDiscoveryTest.java


示例3: build

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


示例4: testFixedServerList

import com.netflix.loadbalancer.LoadBalancerBuilder; //导入依赖的package包/类
@Test
public void testFixedServerList() throws Exception {
    List<RibbonServer> servers = new ArrayList<>();
    servers.add(new RibbonServer("localhost", 9090));
    servers.add(new RibbonServer("localhost", 9091));

    ServerList<RibbonServer> list = new RibbonServiceCallStaticServerListStrategy(servers);

    ZoneAwareLoadBalancer<RibbonServer> lb = LoadBalancerBuilder.<RibbonServer>newBuilder()
        .withDynamicServerList(list)
        .withRule(new RoundRobinRule()).buildDynamicServerListLoadBalancer();

    Server server = lb.chooseServer();
    assertEquals("localhost", server.getHost());
    assertEquals(9091, server.getPort());

    server = lb.chooseServer();
    assertEquals("localhost", server.getHost());
    assertEquals(9090, server.getPort());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:RibbonServerListTest.java


示例5: testBuildWithDiscoveryEnabledNIWSServerList

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


示例6: testBuildWithDiscoveryEnabledNIWSServerListAndUpdater

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


示例7: testBuildWithArchaiusProperties

import com.netflix.loadbalancer.LoadBalancerBuilder; //导入依赖的package包/类
@Test
public void testBuildWithArchaiusProperties() {
    Configuration config = ConfigurationManager.getConfigInstance();
    config.setProperty("client1.niws.client." + Keys.DeploymentContextBasedVipAddresses, "dummy:7001");
    config.setProperty("client1.niws.client." + Keys.InitializeNFLoadBalancer, "true");
    config.setProperty("client1.niws.client." + Keys.NFLoadBalancerClassName, DynamicServerListLoadBalancer.class.getName());
    config.setProperty("client1.niws.client." + Keys.NFLoadBalancerRuleClassName, RoundRobinRule.class.getName());
    config.setProperty("client1.niws.client." + Keys.NIWSServerListClassName, DiscoveryEnabledNIWSServerList.class.getName());
    config.setProperty("client1.niws.client." + Keys.NIWSServerListFilterClassName, ZoneAffinityServerListFilter.class.getName());
    config.setProperty("client1.niws.client." + Keys.ServerListUpdaterClassName, PollingServerListUpdater.class.getName());
    IClientConfig clientConfig = IClientConfig.Builder.newBuilder(NiwsClientConfig.class, "client1").build();
    ILoadBalancer lb = LoadBalancerBuilder.newBuilder().withClientConfig(clientConfig).buildLoadBalancerFromConfigWithReflection();
    assertNotNull(lb);
    assertEquals(DynamicServerListLoadBalancer.class.getName(), lb.getClass().getName());
    DynamicServerListLoadBalancer<Server> dynamicLB = (DynamicServerListLoadBalancer<Server>) lb;
    assertTrue(dynamicLB.getServerListUpdater() instanceof PollingServerListUpdater);
    assertTrue(dynamicLB.getFilter() instanceof ZoneAffinityServerListFilter);
    assertTrue(dynamicLB.getRule() instanceof RoundRobinRule);
    assertTrue(dynamicLB.getPing() instanceof DummyPing);
    assertEquals(Lists.newArrayList(expected), lb.getAllServers());
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:22,代码来源:LBBuilderTest.java


示例8: FilterBackendLoadBalancer

import com.netflix.loadbalancer.LoadBalancerBuilder; //导入依赖的package包/类
@Autowired
FilterBackendLoadBalancer(
        @Value("${gateway.filter.endPointsAsString}") String endPointsAsString) {
    ImmutableSet<EndPoint> endPoints = ImmutableSet.copyOf(
            new LoadBalancerConfiguration(endPointsAsString, "gateway.filter.endPointsAsString")
                    .getEndPoints());
    List<Server> serverList = endPoints.stream()
            .map(e -> new Server(e.getHost(), e.getPort()))
            .collect(Collectors.toList());
    loadBalancer = LoadBalancerBuilder.newBuilder()
            .buildFixedServerListLoadBalancer(serverList);
}
 
开发者ID:looztra,项目名称:my-awesome-guestbook,代码行数:13,代码来源:FilterBackendLoadBalancer.java


示例9: ApiBackendLoadBalancer

import com.netflix.loadbalancer.LoadBalancerBuilder; //导入依赖的package包/类
@Autowired
ApiBackendLoadBalancer(
        @Value("${gateway.guestbook.endPointsAsString}") String endPointsAsString) {
    ImmutableSet<EndPoint> endPoints = ImmutableSet.copyOf(
            new LoadBalancerConfiguration(endPointsAsString, "gateway.guestbook.endPointsAsString")
                    .getEndPoints());
    List<Server> serverList = endPoints.stream()
            .map(e -> new Server(e.getHost(), e.getPort()))
            .collect(Collectors.toList());
    loadBalancer = LoadBalancerBuilder.newBuilder()
            .buildFixedServerListLoadBalancer(serverList);
}
 
开发者ID:looztra,项目名称:my-awesome-guestbook,代码行数:13,代码来源:ApiBackendLoadBalancer.java


示例10: build

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


示例11: setUp

import com.netflix.loadbalancer.LoadBalancerBuilder; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    Server server1 = new Server("host1", 4711);
    Server server2 = new Server("host2", 4712);

    List<Server> servers = Arrays.asList(server1, server2);
    loadBalancer = LoadBalancerBuilder.newBuilder()
            .withRule(new RoundRobinRule())
            .buildFixedServerListLoadBalancer(servers);
    filter = new RibbonClientRequestFilter(loadBalancer);
}
 
开发者ID:lreimer,项目名称:cloud-native-javaee,代码行数:12,代码来源:RibbonClientRequestFilterTest.java


示例12: apply

import com.netflix.loadbalancer.LoadBalancerBuilder; //导入依赖的package包/类
@Override
public LoadBalancerBuilder<Server> apply(
    final LoadBalancerBuilder<Server> builder, final Optional<String> searchDomain
) {
    final String record = searchDomain.map(s -> this.record + "." + s).orElse(this.record);
    return builder.withDynamicServerList(new SrvServerList(record));
}
 
开发者ID:spotify,项目名称:ffwd,代码行数:8,代码来源:HttpDiscovery.java


示例13: module

import com.netflix.loadbalancer.LoadBalancerBuilder; //导入依赖的package包/类
@Override
public Module module(final Key<PluginSink> key, final String id) {
    return new OutputPluginModule(id) {
        @Provides
        @Singleton
        @Named("http")
        public ExecutorService threadPool() {
            return Executors.newCachedThreadPool(
                new ThreadFactoryBuilder().setNameFormat("ffwd-okhttp-async-%d").build());
        }

        @Provides
        @Singleton
        public ILoadBalancer setupRibbonClient(
            HttpPing httpPing, @Named("searchDomain") final Optional<String> searchDomain
        ) {
            return discovery
                .apply(LoadBalancerBuilder.newBuilder(), searchDomain)
                .withPing(httpPing)
                .buildDynamicServerListLoadBalancer();
        }

        @Override
        protected void configure() {
            bind(BatchedPluginSink.class).to(HttpPluginSink.class);
            Key<PluginSink> sinkKey = Key.get(PluginSink.class, Names.named("httpSink"));
            bind(sinkKey).to(HttpPluginSink.class);
            install(wrapPluginSink(sinkKey, key));
            expose(key);
        }
    };
}
 
开发者ID:spotify,项目名称:ffwd,代码行数:33,代码来源:HttpOutputPlugin.java


示例14: apply

import com.netflix.loadbalancer.LoadBalancerBuilder; //导入依赖的package包/类
@Override
public LoadBalancerBuilder<Server> apply(
    final LoadBalancerBuilder<Server> builder, final String searchDomain
) {
    final List<Server> out = new ArrayList<>();

    for (final HostAndPort hostAndPort : this.servers) {
        final HostAndPort modified = hostAndPort.withOptionalSearchDomain(searchDomain);
        out.add(new Server(modified.getHost(), modified.getPort()));
    }

    return builder.withDynamicServerList(new StaticServerList(out));
}
 
开发者ID:spotify,项目名称:ffwd,代码行数:14,代码来源:HttpDiscovery.java


示例15: build

import com.netflix.loadbalancer.LoadBalancerBuilder; //导入依赖的package包/类
public HttpClient build() {
    final HttpDiscovery discovery =
        this.discovery == null ? HttpDiscovery.Static.supplyDefault() : this.discovery;

    final OkHttpClient.Builder builder = new OkHttpClient.Builder();

    builder.addInterceptor(new GzipRequestInterceptor());

    final ObjectMapper objectMapper = setupApplicationJson();
    final RawHttpClientFactory httpClientFactory =
        new RawHttpClientFactory(objectMapper, builder.build());
    final HttpPing httpPing = new HttpPing(httpClientFactory);

    final ILoadBalancer loadBalancer = discovery
        .apply(LoadBalancerBuilder.newBuilder(), searchDomain)
        .withPing(httpPing)
        .withRule(new RetryRule(new AvailabilityFilteringRule()))
        .buildDynamicServerListLoadBalancer();

    final int retries = this.retries == null ? DEFAULT_RETRIES : this.retries;
    ;
    final long baseDelayMillis =
        this.baseDelayMillis == null ? DEFAULT_BASE_DELAY_MILLIS : this.baseDelayMillis;
    ;
    final long maxDelayMillis =
        this.maxDelayMillis == null ? DEFAULT_MAX_DELAY_MILLIS : this.maxDelayMillis;
    ;

    return new HttpClient(httpClientFactory, loadBalancer, retries, baseDelayMillis,
        maxDelayMillis);
}
 
开发者ID:spotify,项目名称:ffwd,代码行数:32,代码来源:HttpClient.java


示例16: ribbonLoadBalancer

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


示例17: ribbonLoadBalancer

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


示例18: testBuildStaticServerListLoadBalancer

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


示例19: build

import com.netflix.loadbalancer.LoadBalancerBuilder; //导入依赖的package包/类
public LoadBalancingHttpClient<I, O> build() {
    if (retryHandler == null) {
        retryHandler = new NettyHttpLoadBalancerErrorHandler();
    }
    if (config == null) {
        config = DefaultClientConfigImpl.getClientConfigWithDefaultValues();
    }
    if (lb == null) {
        lb = LoadBalancerBuilder.newBuilder().withClientConfig(config).buildLoadBalancerFromConfigWithReflection();
    }
    if (listeners == null) {
        listeners = Collections.<ExecutionListener<HttpClientRequest<I>, HttpClientResponse<O>>>emptyList();
    }
    if (backoffStrategy == null) {
        backoffStrategy = new Func1<Integer, Integer>() {
            @Override
            public Integer call(Integer backoffCount) {
                int interval = config.getPropertyAsInteger(IClientConfigKey.Keys.BackoffInterval, DefaultClientConfigImpl.DEFAULT_BACKOFF_INTERVAL);
                if (backoffCount < 0) {
                    backoffCount = 0;
                }
                else if (backoffCount > 10) {   // Reasonable upper bound
                    backoffCount = 10;
                }
                return (int)Math.pow(2, backoffCount) * interval;
            }
        };
    }
    if (responseToErrorPolicy == null) {
        responseToErrorPolicy = new DefaultResponseToErrorPolicy<O>();
    }
    return build.call(this);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:34,代码来源:LoadBalancingHttpClient.java


示例20: LoadBalancingRxClient

import com.netflix.loadbalancer.LoadBalancerBuilder; //导入依赖的package包/类
public LoadBalancingRxClient(IClientConfig config, RetryHandler defaultRetryHandler, PipelineConfigurator<O, I> pipelineConfigurator) {
    this(LoadBalancerBuilder.newBuilder().withClientConfig(config).buildLoadBalancerFromConfigWithReflection(),
            config,
            defaultRetryHandler,
            pipelineConfigurator
            );
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:8,代码来源:LoadBalancingRxClient.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java VTDNav类代码示例发布时间:2022-05-22
下一篇:
Java Default类代码示例发布时间: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