@@ -0,0 +1,1733 @@
+package cloudeventbus.client;%0A%0Aimport java.net.SocketAddress;%0Aimport java.util.ArrayList;%0Aimport java.util.Iterator;%0Aimport java.util.List;%0A%0A/**%0A * Keeps a list of available servers in the cluster.%0A *%0A * @author Mike Heath %3Celcapo@gmail.com%3E%0A */%0Aclass ServerList %7B%0A%0A%09public static int RECONNECT_LIMIT = 10;%0A%0A%09private final List%3CServer%3E servers = new ArrayList%3C%3E();%0A%0A%09private final Object lock = new Object();%0A%0A%09private Iterator%3CServer%3E iterator;%0A%0A%09public void addServers(Iterable%3CSocketAddress%3E addresses) %7B%0A%09%09synchronized (lock) %7B%0A%09%09%09for (SocketAddress address : addresses) %7B%0A%09%09%09%09servers.add(new Server(address));%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09public Server nextServer() %7B%0A%09%09synchronized (lock) %7B%0A%09%09%09if (servers.size() == 0)  %7B%0A%09%09%09%09throw new IllegalStateException(%22No servers in list.%22);%0A%09%09%09%7D%0A%0A%09%09%09if (iterator == null %7C%7C !iterator.hasNext()) %7B%0A%09%09%09%09final List%3CServer%3E activeServers = new ArrayList%3C%3E();%0A%09%09%09%09for (Server server : servers) %7B%0A%09%09%09%09%09if (server.connectionAttempts %3E 0) %7B%0A%09%09%09%09%09%09activeServers.add(server);%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%09if (activeServers.size() == 0) %7B%0A%09%09%09%09%09for (Server server : servers) %7B%0A%09%09%09%09%09%09server.connectionAttempts = RECONNECT_LIMIT;%0A%09%09%09%09%09%7D%0A%09%09%09%09%09activeServers.addAll(servers);%0A%09%09%09%09%7D%0A%09%09%09%09iterator = activeServers.iterator();%0A%09%09%09%7D%0A%09%09%09return iterator.next();%0A%09%09%7D%0A%09%7D%0A%0A%09public class Server %7B%0A%09%09private final SocketAddress address;%0A%0A%09%09private int connectionAttempts = RECONNECT_LIMIT;%0A%0A%09%09private Server(SocketAddress address) %7B%0A%09%09%09this.address = address;%0A%09%09%7D%0A%0A%09%09public SocketAddress getAddress() %7B%0A%09%09%09return address;%0A%09%09%7D%0A%0A%09%09public void connectionFailure() %7B%0A%09%09%09synchronized (lock) %7B%0A%09%09%09%09connectionAttempts--;%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09public void connectionSuccess() %7B%0A%09%09%09synchronized (lock) %7B%0A%09%09%09%09connectionAttempts = RECONNECT_LIMIT;%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%7D%0A

Create class for managing list of servers client can connect to.