mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noël Rouvignac
20.42.2016 61b9eb1be03fc03a9f4bb0013a08ff44a1059503
opendj-server-legacy/src/main/java/org/opends/server/extensions/FIFOEntryCache.java
@@ -80,10 +80,7 @@
{
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
  /**
   * The reference to the Java runtime used to determine the amount of memory
   * currently in use.
   */
  /** The reference to the Java runtime used to determine the amount of memory currently in use. */
  private static final Runtime runtime = Runtime.getRuntime();
  /** The mapping between entry backends/IDs and entries. */
@@ -92,10 +89,7 @@
  /** The mapping between DNs and entries. */
  private LinkedHashMap<DN,CacheEntry> dnMap;
  /**
   * The lock used to provide threadsafe access when changing the contents of
   * the cache.
   */
  /** The lock used to provide threadsafe access when changing the contents of the cache. */
  private ReadWriteLock cacheLock;
  private Lock cacheWriteLock;
  private Lock cacheReadLock;
@@ -122,7 +116,6 @@
    // All initialization should be performed in the initializeEntryCache.
  }
  /** {@inheritDoc} */
  @Override
  public void initializeEntryCache(FIFOEntryCacheCfg configuration)
      throws ConfigException, InitializationException
@@ -152,7 +145,6 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public void finalizeEntryCache()
  {
@@ -174,7 +166,6 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public boolean containsEntry(DN entryDN)
  {
@@ -191,7 +182,6 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public Entry getEntry(DN entryDN)
  {
@@ -212,7 +202,6 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public long getEntryID(DN entryDN)
  {
@@ -226,7 +215,6 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public DN getEntryDN(String backendID, long entryID)
  {
@@ -246,14 +234,12 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public void putEntry(Entry entry, String backendID, long entryID)
  {
    // Create the cache entry based on the provided information.
    CacheEntry cacheEntry = new CacheEntry(entry, backendID, entryID);
    // Obtain a lock on the cache.  If this fails, then don't do anything.
    try
    {
@@ -269,7 +255,6 @@
      return;
    }
    // At this point, we hold the lock.  No matter what, we must release the
    // lock before leaving this method, so do that in a finally block.
    try
@@ -312,7 +297,6 @@
            }
          }
        }
      }
      else
      {
@@ -332,7 +316,6 @@
          map.put(entryID, cacheEntry);
        }
        // See if a cap has been placed on the maximum number of entries in the
        // cache.  If so, then see if we have exceeded it and we need to purge
        // entries until we're within the limit.
@@ -366,14 +349,12 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public boolean putEntryIfAbsent(Entry entry, String backendID, long entryID)
  {
    // Create the cache entry based on the provided information.
    CacheEntry cacheEntry = new CacheEntry(entry, backendID, entryID);
    // Obtain a lock on the cache.  If this fails, then don't do anything.
    try
    {
@@ -391,7 +372,6 @@
      return false;
    }
    // At this point, we hold the lock.  No matter what, we must release the
    // lock before leaving this method, so do that in a finally block.
    try
@@ -441,7 +421,6 @@
          map.put(entryID, cacheEntry);
        }
        // See if a cap has been placed on the maximum number of entries in the
        // cache.  If so, then see if we have exceeded it and we need to purge
        // entries until we're within the limit.
@@ -465,7 +444,6 @@
        }
      }
      // We'll always return true in this case, even if we didn't actually add
      // the entry due to memory constraints.
      return true;
@@ -483,7 +461,6 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public void removeEntry(DN entryDN)
  {
@@ -494,7 +471,6 @@
    // other thread before it releases the lock.
    cacheWriteLock.lock();
    // At this point, it is absolutely critical that we always release the lock
    // before leaving this method, so do so in a finally block.
    try
@@ -538,7 +514,6 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public void clear()
  {
@@ -546,7 +521,6 @@
    // been cleared, so we will block until we can obtain the lock.
    cacheWriteLock.lock();
    // At this point, it is absolutely critical that we always release the lock
    // before leaving this method, so do so in a finally block.
    try
@@ -569,7 +543,6 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public void clearBackend(String backendID)
  {
@@ -577,7 +550,6 @@
    // been cleared, so we will block until we can obtain the lock.
    cacheWriteLock.lock();
    // At this point, it is absolutely critical that we always release the lock
    // before leaving this method, so do so in a finally block.
    try
@@ -591,7 +563,6 @@
        return;
      }
      // Unfortunately, there is no good way to dump the entries from the DN
      // cache based on their backend, so we will need to iterate through the
      // entries in the ID map and do it manually.  Since this could take a
@@ -624,7 +595,6 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public void clearSubtree(DN baseDN)
  {
@@ -636,12 +606,10 @@
      return;
    }
    // Acquire a lock on the cache.  We should not return until the cache has
    // been cleared, so we will block until we can obtain the lock.
    cacheWriteLock.lock();
    // At this point, it is absolutely critical that we always release the lock
    // before leaving this method, so do so in a finally block.
    try
@@ -660,8 +628,6 @@
    }
  }
  /**
   * Clears all entries at or below the specified base DN that are associated
   * with the given backend.  The caller must already hold the cache lock.
@@ -681,7 +647,6 @@
      return;
    }
    // Since the provided base DN could hold a subset of the information in the
    // specified backend, we will have to do this by iterating through all the
    // entries for that backend.  Since this could take a while, we'll
@@ -709,7 +674,6 @@
      }
    }
    // See if the backend has any subordinate backends.  If so, then process
    // them recursively.
    for (Backend<?> subBackend : backend.getSubordinateBackends())
@@ -731,14 +695,12 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public void handleLowMemory()
  {
    // Grab the lock on the cache and wait until we have it.
    cacheWriteLock.lock();
    // At this point, it is absolutely critical that we always release the lock
    // before leaving this method, so do so in a finally block.
    try
@@ -782,7 +744,6 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public boolean isConfigurationAcceptable(EntryCacheCfg configuration,
                                           List<LocalizableMessage> unacceptableReasons)
@@ -791,7 +752,6 @@
    return isConfigurationChangeAcceptable(config, unacceptableReasons);
  }
  /** {@inheritDoc} */
  @Override
  public boolean isConfigurationChangeAcceptable(
      FIFOEntryCacheCfg configuration,
@@ -810,7 +770,6 @@
    return errorHandler.getIsAcceptable();
  }
  /** {@inheritDoc} */
  @Override
  public ConfigChangeResult applyConfigurationChange(      FIFOEntryCacheCfg configuration      )
  {
@@ -833,8 +792,6 @@
    return changeResult;
  }
  /**
   * Parses the provided configuration and configure the entry cache.
   *
@@ -920,14 +877,12 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public Long getCacheCount()
  {
    return Long.valueOf(dnMap.size());
  }
  /** {@inheritDoc} */
  @Override
  public String toVerboseString()
  {