protected void locationChanged(String agent, String priorLoc, String newLoc) { if (priorLoc != null) { if (logger.isDebugEnabled()) { logger.debug( "locationChanged:" + " agent=" + agent + " prior=" + priorLoc + " new=" + newLoc); } synchronized (suspectedDuplicates) { if (suspectedDuplicates.containsKey(agent)) { Map priorLocations = (Map) suspectedDuplicates.get(agent); if (!priorLocations.containsKey(priorLoc)) { priorLocations.put(priorLoc, new Long(model.getVersion(agent))); } if (priorLocations.containsKey(newLoc)) { String agentToRemove = selectAgentToRemove(priorLocations); if (logger.isWarnEnabled()) { logger.warn( "Duplicate agent detected, removing duplicate:" + " agent=" + agent + " locations=" + priorLocations.keySet() + " removingFrom=" + agentToRemove); } suspectedDuplicates.remove(agent); restartHelper.killAgent(agent, agentToRemove, model.getCommunityName()); } } else { Map priorLocations = new HashMap(); priorLocations.put(priorLoc, new Long(model.getVersion(agent))); suspectedDuplicates.put(agent, priorLocations); } } } }
public DuplicateAgentDetector(CommunityStatusModel csm, RestartHelper rh) { model = csm; model.addChangeListener(this); restartHelper = rh; if (logger.isDebugEnabled()) { logger.debug("DuplicateAgentDetector started"); } }