/**
   * Configure the history length for a specific entry. If the length is 0 disable history for this
   * key
   *
   * @param pKey history key
   * @param pMaxEntries number of maximal entries. If larger than globalMaxEntries, then
   *     globalMaxEntries is used instead.
   */
  public synchronized void configure(HistoryKey pKey, int pMaxEntries) {
    int maxEntries = pMaxEntries > globalMaxEntries ? globalMaxEntries : pMaxEntries;

    // Remove entries if set to 0
    if (pMaxEntries == 0) {
      removeEntries(pKey);
      return;
    }
    if (pKey.isMBeanPattern()) {
      patterns.put(pKey, maxEntries);
      // Trim all already stored keys
      for (HistoryKey key : historyStore.keySet()) {
        if (pKey.matches(key)) {
          HistoryEntry entry = historyStore.get(key);
          entry.setMaxEntries(maxEntries);
          entry.trim();
        }
      }
    } else {
      HistoryEntry entry = historyStore.get(pKey);
      if (entry != null) {
        entry.setMaxEntries(maxEntries);
        entry.trim();
      } else {
        entry = new HistoryEntry(maxEntries);
        historyStore.put(pKey, entry);
      }
    }
  }
 /**
  * Set the global maximum limit for history entries
  *
  * @param pGlobalMaxEntries limit
  */
 public synchronized void setGlobalMaxEntries(int pGlobalMaxEntries) {
   globalMaxEntries = pGlobalMaxEntries;
   // Refresh all entries
   for (HistoryEntry entry : historyStore.values()) {
     entry.setMaxEntries(globalMaxEntries);
     entry.trim();
   }
 }