public JaasClient() {
   if (_log == null) {
     _log = LoggerFactory.getInstance().createLogger(this);
   }
   if (_log == null) {
     throw new RuntimeException("Unable to get LoggingService");
   }
 }
public class SecureJarFilterStream extends FilterInputStream {
  URL _url = null;
  private static final Logger _logger =
      LoggerFactory.getInstance().createLogger(SecureJarFilterStream.class);

  private static long m_totalTime;

  SecureJarFilterStream(URL u) throws GeneralSecurityException, IOException {
    super(new BufferedInputStream(u.openStream()));
    _url = u;
    init();
  }

  SecureJarFilterStream(InputStream in) throws GeneralSecurityException, IOException {
    super(new BufferedInputStream(in));
    init();
  }

  private void init() throws GeneralSecurityException, IOException {
    // Unfortunately, we don't know that the signature is
    // correct until we have read the whole stream.
    // So, we read the stream until the end, and we see if we
    // get any exception.
    long a = 0;
    if (_logger.isInfoEnabled()) {
      a = System.currentTimeMillis();
    }
    byte buffer[] = new byte[1000];
    try {
      while (in.read(buffer, 0, buffer.length) != -1) ;
    } catch (Exception e) {
      String message = "Invalid JAR file";
      if (_url != null) {
        message += ": " + _url;
      }
      GeneralSecurityException gse = new GeneralSecurityException(message);
      gse.initCause(e);
      throw gse;
    }
    if (_logger.isInfoEnabled()) {
      long b = System.currentTimeMillis();
      m_totalTime += (b - a);
      _logger.info("Time spent: " + (b - a) + " Total: " + m_totalTime);
    }
  }
}
 static {
   _log = LoggerFactory.getInstance().createLogger(UserFileParser.class);
 }
/** Monitors CommunityStatusModel activity to detect duplicate agents. */
public class DuplicateAgentDetector implements StatusChangeListener {

  protected CommunityStatusModel model;
  protected RestartHelper restartHelper;

  protected static Logger logger =
      LoggerFactory.getInstance().createLogger(DuplicateAgentDetector.class);

  protected Map suspectedDuplicates = new HashMap();

  public DuplicateAgentDetector(CommunityStatusModel csm, RestartHelper rh) {
    model = csm;
    model.addChangeListener(this);
    restartHelper = rh;
    if (logger.isDebugEnabled()) {
      logger.debug("DuplicateAgentDetector started");
    }
  }

  public void statusChanged(CommunityStatusChangeEvent[] csce) {
    for (int i = 0; i < csce.length; i++) {
      if (csce[i].locationChanged()) {
        locationChanged(
            csce[i].getName(), csce[i].getPriorLocation(), csce[i].getCurrentLocation());
      } else if (csce[i].statusReceived()) {
        if (suspectedDuplicates.containsKey(csce[i].getName())) {
          suspectedDuplicates.remove(csce[i].getName());
        }
      }
    }
  }

  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);
        }
      }
    }
  }

  protected String selectAgentToRemove(Map locationMap) {
    String location = null;
    long timestamp = 0;
    for (Iterator it = locationMap.entrySet().iterator(); it.hasNext(); ) {
      Map.Entry me = (Map.Entry) it.next();
      if (location == null || ((Long) me.getValue()).longValue() > timestamp) {
        location = (String) me.getKey();
        timestamp = ((Long) me.getValue()).longValue();
      }
    }
    return location;
  }
}