Package org.opends.server.extensions
Class DefaultEntryCache
- java.lang.Object
-
- org.opends.server.api.EntryCache<EntryCacheCfg>
-
- org.opends.server.extensions.DefaultEntryCache
-
- All Implemented Interfaces:
ConfigurationChangeListener<EntryCacheCfg>,LocalBackendInitializationListener
public class DefaultEntryCache extends EntryCache<EntryCacheCfg> implements ConfigurationChangeListener<EntryCacheCfg>, LocalBackendInitializationListener
This class defines the default entry cache which acts as an arbiter for every entry cache implementation configured and installed within the Directory Server or acts an an empty cache if no implementation specific entry cache is configured. It does not actually store any entries, so all calls to the entry cache public API are routed to underlying entry cache according to the current configuration order and preferences.
-
-
Field Summary
-
Fields inherited from class org.opends.server.api.EntryCache
cacheHits, cacheMisses
-
-
Constructor Summary
Constructors Constructor Description DefaultEntryCache()Creates a new instance of this default entry cache.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ConfigChangeResultapplyConfigurationChange(EntryCacheCfg configuration)Applies the configuration changes to this change listener.voidclear()Removes all entries from the cache.voidclearBackend(String backendID)Removes all entries from the cache that are associated with the provided backend.booleancontainsEntry(DN entryDN)Indicates whether the entry cache currently contains the entry with the specified DN.voidfinalizeEntryCache()Performs any necessary cleanup work (e.g., flushing all cached entries and releasing any other held resources) that should be performed when the server is to be shut down or the entry cache destroyed or replaced.LonggetCacheCount()Retrieves the current number of entries stored within the cache.static EntryCache<? extends EntryCacheCfg>[]getCacheOrder()Retrieves the current cache order array.EntrygetEntry(String backendID, long entryID)Retrieves the requested entry if it is present in the cache.EntrygetEntry(DN entryDN)Retrieves the entry with the specified DN from the cache.DNgetEntryDN(String backendID, long entryID)Retrieves the entry DN for the entry with the specified ID on the specific backend from the cache.longgetEntryID(DN entryDN)Retrieves the entry ID for the entry with the specified DN from the cache.MonitorDatagetMonitorData()Retrieves a set of attributes containing monitor data that should be returned to the client if the corresponding monitor entry is requested.voidhandleLowMemory()Attempts to react to a scenario in which it is determined that the system is running low on available memory.voidinitializeEntryCache(ServerContext serverContext, EntryCacheCfg configEntry)Initializes this entry cache implementation so that it will be available for storing and retrieving entries.booleanisConfigurationChangeAcceptable(EntryCacheCfg configuration, List<org.forgerock.i18n.LocalizableMessage> unacceptableReasons)Indicates whether the proposed change to the configuration is acceptable to this change listener.voidperformBackendPostFinalizationProcessing(LocalBackend<?> backend)Performs any processing that may be required whenever a backend is finalized.voidperformBackendPostInitializationProcessing(LocalBackend<?> backend)Performs any processing that may be required after the Initialisation cycle has been completed, that is all listeners have received the initialisation event, and the backend has been put into service,.voidperformBackendPreFinalizationProcessing(LocalBackend<?> backend)Performs any processing that may be required before starting the finalisation cycle, that is invoked before any listener receive the Finalization event.voidperformBackendPreInitializationProcessing(LocalBackend<?> backend)Performs any processing that may be required whenever a backend is initialized for use in the Directory Server.voidputEntry(Entry entry, String backendID, long entryID)Stores the provided entry in the cache.booleanputEntryIfAbsent(Entry entry, String backendID, long entryID)Stores the provided entry in the cache only if it does not conflict with an entry that already exists.voidremoveEntry(DN entryDN)Removes the specified entry from the cache.static voidsetCacheOrder(SortedMap<Integer,EntryCache<? extends EntryCacheCfg>> cacheOrderMap)Sets the current cache order array.StringtoVerboseString()Return a verbose string representation of the current cache maps.-
Methods inherited from class org.opends.server.api.EntryCache
filtersAllowCaching, getCacheHits, getCacheMisses, getEntryCacheMonitor, getExcludeFilters, getIncludeFilters, isConfigurationAcceptable, setEntryCacheMonitor, setExcludeFilters, setIncludeFilters
-
-
-
-
Method Detail
-
initializeEntryCache
public void initializeEntryCache(ServerContext serverContext, EntryCacheCfg configEntry) throws ConfigException, InitializationException
Description copied from class:EntryCacheInitializes this entry cache implementation so that it will be available for storing and retrieving entries.- Specified by:
initializeEntryCachein classEntryCache<EntryCacheCfg>- Parameters:
serverContext- The server context.configEntry- The configuration to use to initialize the entry cache.- Throws:
ConfigException- If there is a problem with the provided configuration entry that would prevent this entry cache from being used.InitializationException- If a problem occurs during the initialization process that is not related to the configuration.
-
finalizeEntryCache
public void finalizeEntryCache()
Description copied from class:EntryCachePerforms any necessary cleanup work (e.g., flushing all cached entries and releasing any other held resources) that should be performed when the server is to be shut down or the entry cache destroyed or replaced.- Specified by:
finalizeEntryCachein classEntryCache<EntryCacheCfg>
-
containsEntry
public boolean containsEntry(DN entryDN)
Description copied from class:EntryCacheIndicates whether the entry cache currently contains the entry with the specified DN. This method may be called without holding any locks if a point-in-time check is all that is required. Note that this method is called from @see #getEntry(DN entryDN, LockType lockType, List lockList)- Specified by:
containsEntryin classEntryCache<EntryCacheCfg>- Parameters:
entryDN- The DN for which to make the determination.- Returns:
trueif the entry cache currently contains the entry with the specified DN, orfalseif not.
-
getEntry
public Entry getEntry(String backendID, long entryID)
Description copied from class:EntryCacheRetrieves the requested entry if it is present in the cache.- Overrides:
getEntryin classEntryCache<EntryCacheCfg>- Parameters:
backendID- ID of the backend associated with the entry to retrieve.entryID- The entry ID within the provided backend for the specified entry.- Returns:
- The requested entry if it is present in the cache, or
nullif it is not present.
-
getEntry
public Entry getEntry(DN entryDN)
Description copied from class:EntryCacheRetrieves the entry with the specified DN from the cache.- Specified by:
getEntryin classEntryCache<EntryCacheCfg>- Parameters:
entryDN- The DN of the entry to retrieve.- Returns:
- The requested entry if it is present in the cache, or
nullif it is not present.
-
getEntryID
public long getEntryID(DN entryDN)
Description copied from class:EntryCacheRetrieves the entry ID for the entry with the specified DN from the cache. The caller should have already acquired a read or write lock for the entry if such protection is needed.- Specified by:
getEntryIDin classEntryCache<EntryCacheCfg>- Parameters:
entryDN- The DN of the entry for which to retrieve the entry ID.- Returns:
- The entry ID for the requested entry, or -1 if it is not present in the cache.
-
getEntryDN
public DN getEntryDN(String backendID, long entryID)
Description copied from class:EntryCacheRetrieves the entry DN for the entry with the specified ID on the specific backend from the cache. The caller should have already acquired a read or write lock for the entry if such protection is needed. Note that this method is called from @see #getEntry(Backend backend, long entryID, LockType lockType, List lockList)- Specified by:
getEntryDNin classEntryCache<EntryCacheCfg>- Parameters:
backendID- ID of the backend associated with the entry for which to retrieve the entry DN.entryID- The entry ID within the provided backend for which to retrieve the entry DN.- Returns:
- The entry DN for the requested entry, or
nullif it is not present in the cache.
-
putEntry
public void putEntry(Entry entry, String backendID, long entryID)
Description copied from class:EntryCacheStores the provided entry in the cache. Note that the mechanism that it uses to achieve this is implementation-dependent, and it is acceptable for the entry to not actually be stored in any cache.- Specified by:
putEntryin classEntryCache<EntryCacheCfg>- Parameters:
entry- The entry to store in the cache.backendID- ID of the backend with which the entry is associated.entryID- The entry ID within the provided backend that uniquely identifies the specified entry.
-
putEntryIfAbsent
public boolean putEntryIfAbsent(Entry entry, String backendID, long entryID)
Description copied from class:EntryCacheStores the provided entry in the cache only if it does not conflict with an entry that already exists. Note that the mechanism that it uses to achieve this is implementation-dependent, and it is acceptable for the entry to not actually be stored in any cache. However, this method must not overwrite an existing version of the entry.- Specified by:
putEntryIfAbsentin classEntryCache<EntryCacheCfg>- Parameters:
entry- The entry to store in the cache.backendID- ID of the backend with which the entry is associated.entryID- The entry ID within the provided backend that uniquely identifies the specified entry.- Returns:
falseif an existing entry or some other problem prevented the method from completing successfully, ortrueif there was no conflict and the entry was either stored or the cache determined that this entry should never be cached for some reason.
-
removeEntry
public void removeEntry(DN entryDN)
Description copied from class:EntryCacheRemoves the specified entry from the cache.- Specified by:
removeEntryin classEntryCache<EntryCacheCfg>- Parameters:
entryDN- The DN of the entry to remove from the cache.
-
clear
public void clear()
Description copied from class:EntryCacheRemoves all entries from the cache. The cache should still be available for future use.- Specified by:
clearin classEntryCache<EntryCacheCfg>
-
clearBackend
public void clearBackend(String backendID)
Description copied from class:EntryCacheRemoves all entries from the cache that are associated with the provided backend.- Specified by:
clearBackendin classEntryCache<EntryCacheCfg>- Parameters:
backendID- ID of the backend for which to flush the associated entries.
-
handleLowMemory
public void handleLowMemory()
Description copied from class:EntryCacheAttempts to react to a scenario in which it is determined that the system is running low on available memory. In this case, the entry cache should attempt to free some memory if possible to try to avoid out of memory errors.- Specified by:
handleLowMemoryin classEntryCache<EntryCacheCfg>
-
isConfigurationChangeAcceptable
public boolean isConfigurationChangeAcceptable(EntryCacheCfg configuration, List<org.forgerock.i18n.LocalizableMessage> unacceptableReasons)
Description copied from interface:ConfigurationChangeListenerIndicates whether the proposed change to the configuration is acceptable to this change listener.- Specified by:
isConfigurationChangeAcceptablein interfaceConfigurationChangeListener<EntryCacheCfg>- Parameters:
configuration- The new configuration containing the changes.unacceptableReasons- A list that can be used to hold messages about why the provided configuration is not acceptable.- Returns:
- Returns
trueif the proposed change is acceptable, orfalseif it is not.
-
applyConfigurationChange
public ConfigChangeResult applyConfigurationChange(EntryCacheCfg configuration)
Description copied from interface:ConfigurationChangeListenerApplies the configuration changes to this change listener.- Specified by:
applyConfigurationChangein interfaceConfigurationChangeListener<EntryCacheCfg>- Parameters:
configuration- The new configuration containing the changes.- Returns:
- Returns information about the result of changing the configuration.
-
getMonitorData
public MonitorData getMonitorData()
Description copied from class:EntryCacheRetrieves a set of attributes containing monitor data that should be returned to the client if the corresponding monitor entry is requested.- Specified by:
getMonitorDatain classEntryCache<EntryCacheCfg>- Returns:
- A list of attributes containing monitor data that should be returned to the client if the corresponding monitor entry is requested.
-
getCacheCount
public Long getCacheCount()
Description copied from class:EntryCacheRetrieves the current number of entries stored within the cache.- Specified by:
getCacheCountin classEntryCache<EntryCacheCfg>- Returns:
- The current number of entries stored within the cache.
-
toVerboseString
public String toVerboseString()
Description copied from class:EntryCacheReturn a verbose string representation of the current cache maps. This is useful primary for debugging and diagnostic purposes such as in the entry cache unit tests.This method is invoked by unit tests for debugging.
- Specified by:
toVerboseStringin classEntryCache<EntryCacheCfg>- Returns:
- String verbose string representation of the current cache maps in
the following format: dn:id:backend one cache entry map
representation per line or
nullif all maps are empty.
-
getCacheOrder
public static final EntryCache<? extends EntryCacheCfg>[] getCacheOrder()
Retrieves the current cache order array.- Returns:
- The current cache order array.
-
setCacheOrder
public static final void setCacheOrder(SortedMap<Integer,EntryCache<? extends EntryCacheCfg>> cacheOrderMap)
Sets the current cache order array.- Parameters:
cacheOrderMap- The current cache order array.
-
performBackendPreInitializationProcessing
public void performBackendPreInitializationProcessing(LocalBackend<?> backend)
Performs any processing that may be required whenever a backend is initialized for use in the Directory Server. This method will be invoked after the backend has been initialized but before it has been put into service.- Specified by:
performBackendPreInitializationProcessingin interfaceLocalBackendInitializationListener- Parameters:
backend- The backend that has been initialized and is about to be put into service.
-
performBackendPostFinalizationProcessing
public void performBackendPostFinalizationProcessing(LocalBackend<?> backend)
Performs any processing that may be required whenever a backend is finalized. This method will be invoked after the backend has been taken out of service but before it has been finalized.- Specified by:
performBackendPostFinalizationProcessingin interfaceLocalBackendInitializationListener- Parameters:
backend- The backend that has been taken out of service and is about to be finalized.
-
performBackendPostInitializationProcessing
public void performBackendPostInitializationProcessing(LocalBackend<?> backend)
Description copied from interface:LocalBackendInitializationListenerPerforms any processing that may be required after the Initialisation cycle has been completed, that is all listeners have received the initialisation event, and the backend has been put into service,.- Specified by:
performBackendPostInitializationProcessingin interfaceLocalBackendInitializationListener- Parameters:
backend- The backend that has been initialized and has been put into service.
-
performBackendPreFinalizationProcessing
public void performBackendPreFinalizationProcessing(LocalBackend<?> backend)
Description copied from interface:LocalBackendInitializationListenerPerforms any processing that may be required before starting the finalisation cycle, that is invoked before any listener receive the Finalization event.- Specified by:
performBackendPreFinalizationProcessingin interfaceLocalBackendInitializationListener- Parameters:
backend- The backend that is about to be finalized.
-
-