| | |
| | | { |
| | | 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. */ |
| | |
| | | /** 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; |
| | |
| | | // All initialization should be performed in the initializeEntryCache. |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void initializeEntryCache(FIFOEntryCacheCfg configuration) |
| | | throws ConfigException, InitializationException |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void finalizeEntryCache() |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean containsEntry(DN entryDN) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Entry getEntry(DN entryDN) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public long getEntryID(DN entryDN) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public DN getEntryDN(String backendID, long entryID) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@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 |
| | | { |
| | |
| | | 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 |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | else |
| | | { |
| | |
| | | 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. |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@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 |
| | | { |
| | |
| | | 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 |
| | |
| | | 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. |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // We'll always return true in this case, even if we didn't actually add |
| | | // the entry due to memory constraints. |
| | | return true; |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void removeEntry(DN entryDN) |
| | | { |
| | |
| | | // 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 |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void clear() |
| | | { |
| | |
| | | // 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 |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void clearBackend(String backendID) |
| | | { |
| | |
| | | // 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 |
| | |
| | | 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 |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void clearSubtree(DN baseDN) |
| | | { |
| | |
| | | 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 |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 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. |
| | |
| | | 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 |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // See if the backend has any subordinate backends. If so, then process |
| | | // them recursively. |
| | | for (Backend<?> subBackend : backend.getSubordinateBackends()) |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@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 |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isConfigurationAcceptable(EntryCacheCfg configuration, |
| | | List<LocalizableMessage> unacceptableReasons) |
| | |
| | | return isConfigurationChangeAcceptable(config, unacceptableReasons); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isConfigurationChangeAcceptable( |
| | | FIFOEntryCacheCfg configuration, |
| | |
| | | return errorHandler.getIsAcceptable(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public ConfigChangeResult applyConfigurationChange( FIFOEntryCacheCfg configuration ) |
| | | { |
| | |
| | | return changeResult; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Parses the provided configuration and configure the entry cache. |
| | | * |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Long getCacheCount() |
| | | { |
| | | return Long.valueOf(dnMap.size()); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String toVerboseString() |
| | | { |