|
1 | 1 | package com.codingapi.ribbon.loadbalancer; |
2 | 2 |
|
| 3 | +import com.netflix.client.config.IClientConfig; |
| 4 | +import com.netflix.loadbalancer.*; |
3 | 5 | import org.slf4j.Logger; |
4 | 6 | import org.slf4j.LoggerFactory; |
5 | 7 |
|
6 | | -import com.netflix.client.config.IClientConfig; |
7 | | -import com.netflix.loadbalancer.IPing; |
8 | | -import com.netflix.loadbalancer.IRule; |
9 | | -import com.netflix.loadbalancer.Server; |
10 | | -import com.netflix.loadbalancer.ServerList; |
11 | | -import com.netflix.loadbalancer.ServerListFilter; |
12 | | -import com.netflix.loadbalancer.ServerListUpdater; |
13 | | -import com.netflix.loadbalancer.ZoneAwareLoadBalancer; |
| 8 | +import java.util.ArrayList; |
| 9 | +import java.util.List; |
14 | 10 |
|
15 | 11 | /** |
16 | 12 | * created by foxdd 2017-12-05 |
17 | 13 | */ |
18 | | -public class LcnZoneAwareLoadBalancerProxy<T extends Server> extends ZoneAwareLoadBalancer<T> { |
| 14 | +public class LcnZoneAwareLoadBalancerProxy extends ZoneAwareLoadBalancer<Server> { |
19 | 15 |
|
20 | 16 | private Logger logger = LoggerFactory.getLogger(LcnZoneAwareLoadBalancerProxy.class); |
21 | 17 |
|
22 | 18 | LcnLoadBalancerRule lcnLoadBalancerRule = new LcnLoadBalancerRule(); |
23 | 19 |
|
24 | 20 | public LcnZoneAwareLoadBalancerProxy(IClientConfig clientConfig, IRule rule, |
25 | | - IPing ping, ServerList<T> serverList, ServerListFilter<T> filter, |
| 21 | + IPing ping, ServerList<Server> serverList, ServerListFilter<Server> filter, |
26 | 22 | ServerListUpdater serverListUpdater) { |
27 | 23 | super(clientConfig, rule, ping, serverList, filter, serverListUpdater); |
28 | 24 | } |
29 | 25 |
|
30 | 26 | @Override |
31 | 27 | public Server chooseServer(Object key){ |
32 | 28 | logger.info("enter chooseServer method, key:" + key); |
33 | | - return lcnLoadBalancerRule.proxy(getAllServers(),super.chooseServer(key)); |
| 29 | + |
| 30 | + List<Server> serverList = new ArrayList<Server>(); |
| 31 | + //获取处理之后的serverlist |
| 32 | + serverList = super.getServerListImpl().getUpdatedListOfServers(); |
| 33 | + //获取过滤之后的serverlist |
| 34 | + serverList = super.getFilter().getFilteredListOfServers(serverList); |
| 35 | + return lcnLoadBalancerRule.proxy(serverList, super.chooseServer(key)); |
| 36 | + |
34 | 37 | } |
35 | 38 |
|
36 | 39 | } |
0 commit comments