예제 #1
0
  /**
   * Factory method for ResultsPruners (used to load ConfigurationManager properties.
   *
   * @param props
   * @throws FileNotFoundException
   */
  public static ResultsPruner getPruner(Context context, Properties props)
      throws FileNotFoundException {

    ResultsPruner rp = new ResultsPruner(context);
    Pattern retentionPattern = Pattern.compile("checker\\.retention\\.(.*)");
    for (Enumeration<String> en = (Enumeration<String>) props.propertyNames();
        en.hasMoreElements(); ) {
      String name = en.nextElement();
      Matcher matcher = retentionPattern.matcher(name);
      if (!matcher.matches()) {
        continue;
      }
      String resultCode = matcher.group(1);
      long duration;
      try {
        duration = Utils.parseDuration(props.getProperty(name));
      } catch (ParseException e) {
        throw new IllegalStateException("Problem parsing duration: " + e.getMessage(), e);
      }
      ChecksumResultCode code = ChecksumResultCode.valueOf(resultCode);
      if (code == null) {
        throw new IllegalStateException("Checksum result code not found: " + resultCode);
      }
      if ("default".equals(resultCode)) {
        rp.setDefaultDuration(duration);
      } else {
        rp.addInterested(code, duration);
      }
    }
    return rp;
  }
예제 #2
0
 /**
  * Prunes the results retaining results as configured by the interests registered with this
  * object.
  *
  * @return number of results removed.
  */
 public int prune() throws SQLException {
   ChecksumResultCode[] codes = ChecksumResultCode.values();
   for (ChecksumResultCode code : codes) {
     if (!interests.containsKey(code)) {
       interests.put(code, defaultDuration);
     }
   }
   int result = checksumHistoryService.prune(context, interests);
   return result;
 }