标签:mutable err equal log balance col strong for sel
ServerListChangeListener
用来监听负载均衡器的服务器列表变化。
public interface ServerListChangeListener {
/**
* 当 BaseLoadBalancer的server列表变化时被调用。
*/
public void serverListChanged(List<Server> oldList, List<Server> newList);
}
通过BaseLoadBalancer的addServerListChangeListener和removeServerListChangeListener方法来增加和删除ServerListChangeListener监听器。
private List<ServerListChangeListener> changeListeners = new CopyOnWriteArrayList<ServerListChangeListener>(); ... public void addServerListChangeListener(ServerListChangeListener listener) { changeListeners.add(listener); } public void removeServerListChangeListener(ServerListChangeListener listener) { changeListeners.remove(listener); } ....
当BaseLoadBalancer的Server列表发生变化时,调用注册的ServerListChangeListener监听器。
public void setServersList(List lsrv) { ... boolean listChanged = false; if (!allServerList.equals(allServers)) { listChanged = true; if (changeListeners != null && changeListeners.size() > 0) { List<Server> oldList = ImmutableList.copyOf(allServerList); List<Server> newList = ImmutableList.copyOf(allServers); for (ServerListChangeListener l: changeListeners) { try { l.serverListChanged(oldList, newList); } catch (Exception e) { logger.error("LoadBalancer [{}]: Error invoking server list change listener", name, e); } } } } ... }
ribbon源码之ServerListChangeListener
标签:mutable err equal log balance col strong for sel
原文地址:http://www.cnblogs.com/zhangwanhua/p/7994498.html