Beispiel #1
0
 /**
  * Removes all of {@link Cookie cookies} in this HTTP state that have expired by the specified
  * {@link java.util.Date date}.
  *
  * @param date The {@link java.util.Date date} to compare against.
  * @return true if any cookies were purged.
  * @see Cookie#isExpired(java.util.Date)
  * @see #purgeExpiredCookies()
  */
 public synchronized boolean purgeExpiredCookies(Date date) {
   LOG.trace("enter HttpState.purgeExpiredCookies(Date)");
   // BEGIN IA/HERITRIX CHANGES
   //      PRIOR IMPL & COMPARISON HARNESS LEFT COMMENTED OUT FOR TEMPORARY REFERENCE
   //        boolean arrayRemoved = false;
   //        Iterator ita = cookiesArrayList.iterator();
   //        while (ita.hasNext()) {
   //            if (((Cookie) (ita.next())).isExpired(date)) {
   //                ita.remove();
   //                arrayRemoved = true;
   //            }
   //        }
   boolean removed = false;
   Iterator<Cookie> it = cookiesMap.values().iterator();
   while (it.hasNext()) {
     if (it.next().isExpired(date)) {
       it.remove();
       removed = true;
     }
   }
   StoredIterator.close(it);
   //        assert removed == arrayRemoved : "discrepancy"
   // END IA/HERITRIX CHANGES
   return removed;
 }
Beispiel #2
0
  /**
   * Copies entries from an existing environment db to a new one. If historyMap is not provided,
   * only logs the entries that would have been copied.
   *
   * @param sourceDir existing environment database directory
   * @param historyMap new environment db (or null for a dry run)
   * @return number of records
   * @throws DatabaseException
   */
  private static int copyPersistEnv(File sourceDir, StoredSortedMap<String, Map> historyMap)
      throws DatabaseException {
    int count = 0;

    // open the source env history DB, copying entries to target env
    EnhancedEnvironment sourceEnv = setupCopyEnvironment(sourceDir, true);
    StoredClassCatalog sourceClassCatalog = sourceEnv.getClassCatalog();
    DatabaseConfig historyDbConfig = HISTORY_DB_CONFIG.toDatabaseConfig();
    historyDbConfig.setReadOnly(true);
    Database sourceHistoryDB = sourceEnv.openDatabase(null, URI_HISTORY_DBNAME, historyDbConfig);
    StoredSortedMap<String, Map> sourceHistoryMap =
        new StoredSortedMap<String, Map>(
            sourceHistoryDB,
            new StringBinding(),
            new SerialBinding<Map>(sourceClassCatalog, Map.class),
            true);

    Iterator<Entry<String, Map>> iter = sourceHistoryMap.entrySet().iterator();
    while (iter.hasNext()) {
      Entry<String, Map> item = iter.next();
      if (logger.isLoggable(Level.FINE)) {
        logger.fine(item.getKey() + " " + new JSONObject(item.getValue()));
      }

      if (historyMap != null) {
        historyMap.put(item.getKey(), item.getValue());
      }
      count++;
    }
    StoredIterator.close(iter);
    sourceHistoryDB.close();
    sourceEnv.close();

    return count;
  }
Beispiel #3
0
  /**
   * Print the objects returned by an iterator of entity value objects.
   *
   * <p><b> IMPORTANT: All database iterators must be closed to avoid serious database problems. If
   * the iterator is not closed, the underlying Berkeley DB cursor is not closed either. </b>
   */
  private void printValues(String label, Iterator iterator) {

    System.out.println("\n--- " + label + " ---");
    try {
      while (iterator.hasNext()) {
        System.out.println(iterator.next().toString());
      }
    } finally {
      // IMPORTANT: Use StoredIterator to close all database
      // iterators.  If java.util.Iterator is in hand, you can safely
      // close it by calling StoredIterator.close(Iterator).
      StoredIterator.close(iterator);
    }
  }
Beispiel #4
0
  /**
   * Returns an array of {@link Cookie cookies} that this HTTP state currently contains.
   *
   * @return an array of {@link Cookie cookies}.
   * @see #getCookies(String, int, String, boolean)
   * @deprecated use getCookiesMap() // <- IA/HERITRIX CHANGE
   */
  public synchronized Cookie[] getCookies() {
    LOG.trace("enter HttpState.getCookies()");
    // BEGIN IA/HERITRIX CHANGES
    //      PRIOR IMPL & COMPARISON HARNESS LEFT COMMENTED OUT FOR TEMPORARY REFERENCE
    //        Cookie[] arrayListAnswer = (Cookie[]) (cookiesArrayList.toArray(new
    // Cookie[cookiesArrayList.size()]));
    ArrayList<Cookie> arrayableCookies = new ArrayList<Cookie>();
    Iterator<Cookie> iter = cookiesMap.values().iterator();
    while (iter.hasNext()) {
      arrayableCookies.add(iter.next());
    }
    StoredIterator.close(iter);
    Cookie[] mapAnswer = (Cookie[]) arrayableCookies.toArray(new Cookie[arrayableCookies.size()]);

    //        if(cookiesArrayList.size()!=arrayableCookies.size()) {
    //            System.out.println("discrepancy");
    //        }
    return mapAnswer;
    // END IA/HERITRIX CHANGES
  }