public void markServerDown(String id) { boolean triggered = false; id = Server.normalizeId(id); if (id == null) { return; } Lock writeLock = upServerLock.writeLock(); try { writeLock.lock(); final List<Server> changedServers = new ArrayList<Server>(); for (Server svr : upServerList) { if (svr.isAlive() && (svr.getId().equals(id))) { triggered = true; svr.setAlive(false); changedServers.add(svr); } } if (triggered) { logger.error("LoadBalancer: markServerDown called on [" + id + "]"); notifyServerStatusChangeListener(changedServers); } } finally { try { writeLock.unlock(); } catch (Exception e) { // NOPMD } } }
@Override public void markServerDown(Server server) { if (server == null) { return; } if (!server.isAlive()) { return; } logger.error("LoadBalancer: markServerDown called on [" + server.getId() + "]"); server.setAlive(false); // forceQuickPing(); notifyServerStatusChangeListener(singleton(server)); }
public void runPinger() { if (pingInProgress.get()) { return; } else { pingInProgress.set(true); } Object[] allServers = null; boolean[] results = null; Lock allLock = null; Lock upLock = null; try { allLock = allServerLock.readLock(); allLock.lock(); allServers = allServerList.toArray(); allLock.unlock(); int numCandidates = allServers.length; results = new boolean[numCandidates]; if (logger.isDebugEnabled()) { logger.debug( "LoadBalancer: PingTask executing [" + numCandidates + "] servers configured"); } for (int i = 0; i < numCandidates; i++) { results[i] = false; try { if (ping != null) { results[i] = ping.isAlive((Server) allServers[i]); } } catch (Throwable t) { logger.error("Exception while pinging Server:" + allServers[i], t); } } final List<Server> newUpList = new ArrayList<Server>(); final List<Server> changedServers = new ArrayList<Server>(); for (int i = 0; i < numCandidates; i++) { boolean isAlive = results[i]; Server svr = (Server) allServers[i]; boolean oldIsAlive = svr.isAlive(); svr.setAlive(isAlive); if (oldIsAlive != isAlive) { changedServers.add(svr); if (logger.isDebugEnabled()) { logger.debug( "LoadBalancer: Server [" + svr.getId() + "] status changed to " + (isAlive ? "ALIVE" : "DEAD")); } } if (isAlive) { newUpList.add(svr); } } upLock = upServerLock.writeLock(); upLock.lock(); upServerList = newUpList; upLock.unlock(); notifyServerStatusChangeListener(changedServers); } catch (Throwable t) { logger.error("Throwable caught while running the Pinger-" + name, t); } finally { pingInProgress.set(false); } }
public void setServersList(List lsrv) { Collections.shuffle(lsrv); Lock writeLock = allServerLock.writeLock(); if (logger.isDebugEnabled()) { logger.debug("LoadBalancer: clearing server list (SET op)"); } List<Server> newUpServerList = null; boolean listChanged = false; writeLock.lock(); try { List<Server> allServers = new ArrayList<Server>(); for (Object server : lsrv) { if (server == null) { continue; } if (server instanceof String) { server = new Server((String) server); } if (server instanceof Server) { if (logger.isDebugEnabled()) { logger.debug("LoadBalancer: addServer [" + ((Server) server).getId() + "]"); } allServers.add((Server) server); } else { throw new IllegalArgumentException( "Type String or Server expected, instead found:" + server.getClass()); } } if (!allServerList.equals(allServers)) { listChanged = true; if (changeListeners != null && changeListeners.size() > 0) { List<Server> oldList = new ArrayList<Server>(allServerList); List<Server> newList = new ArrayList<Server>(allServers); for (ServerListChangeListener l : changeListeners) { try { l.serverListChanged(oldList, newList); } catch (Throwable e) { logger.error("Error invoking server list change listener", e); } } } } allServerList = allServers; if (canSkipPing()) { for (Server s : allServerList) { s.setAlive(true); } newUpServerList = allServerList; } } finally { writeLock.unlock(); } if (newUpServerList != null) { Lock unLock = upServerLock.writeLock(); try { unLock.lock(); upServerList = newUpServerList; } finally { unLock.unlock(); } } else if (listChanged) { forceQuickPing(); } }