本文整理汇总了Java中com.netflix.loadbalancer.ServerList类的典型用法代码示例。如果您正苦于以下问题:Java ServerList类的具体用法?Java ServerList怎么用?Java ServerList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServerList类属于com.netflix.loadbalancer包,在下文中一共展示了ServerList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFixedServerList
import com.netflix.loadbalancer.ServerList; //导入依赖的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());
}
示例2: getDomainExtractingServerList
import com.netflix.loadbalancer.ServerList; //导入依赖的package包/类
protected DomainExtractingServerList getDomainExtractingServerList(
DefaultClientConfigImpl config, boolean approximateZoneFromHostname) {
DiscoveryEnabledServer server = mock(DiscoveryEnabledServer.class);
@SuppressWarnings("unchecked")
ServerList<DiscoveryEnabledServer> originalServerList = mock(ServerList.class);
InstanceInfo instanceInfo = mock(InstanceInfo.class);
given(server.getInstanceInfo()).willReturn(instanceInfo);
given(server.getHost()).willReturn(HOST_NAME);
given(instanceInfo.getMetadata()).willReturn(this.metadata);
given(instanceInfo.getHostName()).willReturn(HOST_NAME);
given(instanceInfo.getIPAddr()).willReturn(IP_ADDR);
given(instanceInfo.getPort()).willReturn(PORT);
given(originalServerList.getInitialListOfServers()).willReturn(
Arrays.asList(server));
return new DomainExtractingServerList(originalServerList, config,
approximateZoneFromHostname);
}
示例3: testBuildWithDiscoveryEnabledNIWSServerList
import com.netflix.loadbalancer.ServerList; //导入依赖的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);
}
示例4: testBuildWithDiscoveryEnabledNIWSServerListAndUpdater
import com.netflix.loadbalancer.ServerList; //导入依赖的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);
}
示例5: ribbonServerList
import com.netflix.loadbalancer.ServerList; //导入依赖的package包/类
@Bean
public ServerList<Server> ribbonServerList(
IClientConfig config) {
ServiceCombServerList serverList = new ServiceCombServerList();
serverList.initWithNiwsConfig(config);
return serverList;
}
示例6: loadBalancer
import com.netflix.loadbalancer.ServerList; //导入依赖的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);
}
示例7: serverList
import com.netflix.loadbalancer.ServerList; //导入依赖的package包/类
@Bean
public ServerList<Server> serverList() {
return new ServerList<Server>() {
@Override
public List<Server> getInitialListOfServers() {
return servers();
}
@Override
public List<Server> getUpdatedListOfServers() {
return servers();
}
};
}
示例8: ribbonServerList
import com.netflix.loadbalancer.ServerList; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public ServerList<?> ribbonServerList() {
MarathonServerList serverList = new MarathonServerList(client, properties);
serverList.initWithNiwsConfig(clientConfig);
return serverList;
}
示例9: ribbonServerList
import com.netflix.loadbalancer.ServerList; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public ServerList<?> ribbonServerList(KubernetesClient client, IClientConfig config) {
KubernetesServerList serverList = new KubernetesServerList(client);
serverList.initWithNiwsConfig(config);
return serverList;
}
示例10: ribbonServerList
import com.netflix.loadbalancer.ServerList; //导入依赖的package包/类
@Bean
ServerList<Server> ribbonServerList() {
String hostname;
int port;
try {
hostname = new URI(quoteServerURL).getHost();
port = new URI(quoteServerURL).getPort();
} catch (URISyntaxException e) {
hostname = DEFAULT_QUOTE_SERVER_HOST;
port = DEFAULT_QUOTE_SERVER_PORT;
e.printStackTrace();
}
return new StaticServerList<>(new Server(hostname, port));
}
示例11: ribbonServerList
import com.netflix.loadbalancer.ServerList; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public ServerList<?> ribbonServerList(IClientConfig config) {
// TODO: this is a common thing between impl, maybe ServerListFactory?
LatticeServerList serverList = new LatticeServerList(props, receptorService,
serviceId);
return serverList;
}
示例12: ribbonServerList
import com.netflix.loadbalancer.ServerList; //导入依赖的package包/类
@Bean
public ServerList<?> ribbonServerList() {
Map<String, String> metadata = new HashMap<>();
metadata.put("version", "1.0");
metadata.put("variant", "A");
InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder()
.setAppName("local")
.setHostName("localhost")
.setPort(8761)
.setMetadata(metadata)
.build();
return new StaticServerList<>(Arrays.asList(new DiscoveryEnabledServer(instanceInfo, false)));
}
开发者ID:jmnarloch,项目名称:ribbon-discovery-filter-spring-cloud-starter,代码行数:14,代码来源:RibbonDiscoveryFilterTest.java
示例13: ribbonLoadBalancer
import com.netflix.loadbalancer.ServerList; //导入依赖的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);
}
示例14: ribbonServerListFromDependencies
import com.netflix.loadbalancer.ServerList; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
@ConditionalOnDependenciesPassed
public ServerList<?> ribbonServerListFromDependencies(IClientConfig config,
ZookeeperDependencies zookeeperDependencies,
ServiceDiscovery<ZookeeperInstance> serviceDiscovery) {
ZookeeperServerList serverList = new ZookeeperServerList(serviceDiscovery);
serverList.initFromDependencies(config, zookeeperDependencies);
log.debug(String.format("Server list for Ribbon's dependencies based load balancing is [%s]", serverList));
return serverList;
}
示例15: dependenciesBasedLoadBalancer
import com.netflix.loadbalancer.ServerList; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
@ConditionalOnDependenciesPassed
@ConditionalOnProperty(value = "spring.cloud.zookeeper.dependency.ribbon.loadbalancer", matchIfMissing = true)
public ILoadBalancer dependenciesBasedLoadBalancer(ZookeeperDependencies zookeeperDependencies,
ServerList<?> serverList, IClientConfig config, IPing iPing) {
return new DependenciesBasedLoadBalancer(zookeeperDependencies, serverList, config, iPing);
}