- [Issue 1591] consolidate common exclude/include EntryCache functionality:
this fix consolidates exclude and include filter sets functionality under the
single filtersAllowCaching() method, common to all cache implementations.
| | |
| | | |
| | | |
| | | import java.util.List; |
| | | import java.util.HashSet; |
| | | import java.util.concurrent.locks.Lock; |
| | | |
| | | import org.opends.server.core.DirectoryServer; |
| | |
| | | import org.opends.server.types.InitializationException; |
| | | import org.opends.server.types.LockType; |
| | | import org.opends.server.types.LockManager; |
| | | import org.opends.server.types.SearchFilter; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import org.opends.server.admin.std.server.EntryCacheCfg; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | |
| | | |
| | | |
| | | /** |
| | | * The set of filters that define the entries that should |
| | | * be excluded from the cache. |
| | | */ |
| | | protected HashSet<SearchFilter> excludeFilters; |
| | | |
| | | |
| | | |
| | | /** |
| | | * The set of filters that define the entries that should |
| | | * be included in the cache. |
| | | */ |
| | | protected HashSet<SearchFilter> includeFilters; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Initializes this entry cache implementation so that it will be |
| | | * available for storing and retrieving entries. |
| | | * |
| | |
| | | |
| | | |
| | | /** |
| | | * Indicates whether the current set of exclude and include filters |
| | | * allow caching of the specified entry. |
| | | * @param entry The entry to evaluate against exclude and include |
| | | * filter sets. |
| | | * @return <CODE>true</CODE> if current set of filters allow caching |
| | | * the entry and <CODE>false</CODE> otherwise. |
| | | */ |
| | | protected boolean filtersAllowCaching(Entry entry) |
| | | { |
| | | // If there is a set of exclude filters, then make sure that the |
| | | // provided entry doesn't match any of them. |
| | | if (! excludeFilters.isEmpty()) |
| | | { |
| | | for (SearchFilter f : excludeFilters) |
| | | { |
| | | try |
| | | { |
| | | if (f.matchesEntry(entry)) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // This shouldn't happen, but if it does then we can't be |
| | | // sure whether the entry should be excluded, so we will |
| | | // by default. |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // If there is a set of include filters, then make sure that the |
| | | // provided entry matches at least one of them. |
| | | if (! includeFilters.isEmpty()) |
| | | { |
| | | boolean matchFound = false; |
| | | for (SearchFilter f : includeFilters) |
| | | { |
| | | try |
| | | { |
| | | if (f.matchesEntry(entry)) |
| | | { |
| | | matchFound = true; |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // This shouldn't happen, but if it does, then |
| | | // just ignore it. |
| | | } |
| | | } |
| | | |
| | | if (! matchFound) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public void performBackendInitializationProcessing(Backend backend) |
| | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * The set of time units that will be used for expressing the task retention |
| | | * time. |
| | |
| | | // The mapping between entry backends/IDs and entries. |
| | | private HashMap<Backend,HashMap<Long,CacheEntry>> idMap; |
| | | |
| | | // The set of filters that define the entries that should be excluded from the |
| | | // cache. |
| | | private HashSet<SearchFilter> excludeFilters; |
| | | |
| | | // The set of filters that define the entries that should be included in the |
| | | // cache. |
| | | private HashSet<SearchFilter> includeFilters; |
| | | |
| | | // The maximum percentage of JVM memory that should be used by the cache. |
| | | private int maxMemoryPercent; |
| | | |
| | |
| | | */ |
| | | public void putEntry(Entry entry, Backend backend, long entryID) |
| | | { |
| | | // If there is a set of exclude filters, then make sure that the provided |
| | | // entry doesn't match any of them. |
| | | if (! excludeFilters.isEmpty()) |
| | | { |
| | | for (SearchFilter f : excludeFilters) |
| | | { |
| | | try |
| | | { |
| | | if (f.matchesEntry(entry)) |
| | | { |
| | | return; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // This shouldn't happen, but if it does then we can't be sure whether |
| | | // the entry should be excluded, so we will by default. |
| | | return; |
| | | } |
| | | } |
| | | // Check exclude and include filters first. |
| | | if (!filtersAllowCaching(entry)) { |
| | | return; |
| | | } |
| | | |
| | | |
| | | // If there is a set of include filters, then make sure that the provided |
| | | // entry matches at least one of them. |
| | | if (! includeFilters.isEmpty()) |
| | | { |
| | | boolean matchFound = false; |
| | | for (SearchFilter f : includeFilters) |
| | | { |
| | | try |
| | | { |
| | | if (f.matchesEntry(entry)) |
| | | { |
| | | matchFound = true; |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // This shouldn't happen, but if it does, then just ignore it. |
| | | } |
| | | } |
| | | |
| | | if (! matchFound) |
| | | { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | |
| | | // Create the cache entry based on the provided information. |
| | | CacheEntry cacheEntry = new CacheEntry(entry, backend, entryID); |
| | | |
| | |
| | | */ |
| | | public boolean putEntryIfAbsent(Entry entry, Backend backend, long entryID) |
| | | { |
| | | // If there is a set of exclude filters, then make sure that the provided |
| | | // entry doesn't match any of them. |
| | | if (! excludeFilters.isEmpty()) |
| | | { |
| | | for (SearchFilter f : excludeFilters) |
| | | { |
| | | try |
| | | { |
| | | if (f.matchesEntry(entry)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // This shouldn't happen, but if it does then we can't be sure whether |
| | | // the entry should be excluded, so we will by default. |
| | | return false; |
| | | } |
| | | } |
| | | // Check exclude and include filters first. |
| | | if (!filtersAllowCaching(entry)) { |
| | | return true; |
| | | } |
| | | |
| | | |
| | | // If there is a set of include filters, then make sure that the provided |
| | | // entry matches at least one of them. |
| | | if (! includeFilters.isEmpty()) |
| | | { |
| | | boolean matchFound = false; |
| | | for (SearchFilter f : includeFilters) |
| | | { |
| | | try |
| | | { |
| | | if (f.matchesEntry(entry)) |
| | | { |
| | | matchFound = true; |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // This shouldn't happen, but if it does, then just ignore it. |
| | | } |
| | | } |
| | | |
| | | if (! matchFound) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | |
| | | // Create the cache entry based on the provided information. |
| | | CacheEntry cacheEntry = new CacheEntry(entry, backend, entryID); |
| | | |
| | |
| | | // The DN of the configuration entry for this entry cache. |
| | | private DN configEntryDN; |
| | | |
| | | // The set of filters that define the entries that should be excluded from the |
| | | // cache. |
| | | private Set<SearchFilter> excludeFilters; |
| | | |
| | | // The set of filters that define the entries that should be included in the |
| | | // cache. |
| | | private Set<SearchFilter> includeFilters; |
| | | |
| | | // The maximum amount of space in bytes that can be consumed in the filesystem |
| | | // before we need to start purging entries. |
| | | private long maxAllowedMemory; |
| | |
| | | */ |
| | | public void putEntry(Entry entry, Backend backend, long entryID) { |
| | | |
| | | // If there is a set of exclude filters, then make sure that the provided |
| | | // entry doesn't match any of them. |
| | | if (! excludeFilters.isEmpty()) { |
| | | for (SearchFilter f : excludeFilters) { |
| | | try { |
| | | if (f.matchesEntry(entry)) { |
| | | return; |
| | | } |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // This shouldn't happen, but if it does then we can't be sure whether |
| | | // the entry should be excluded, so we will by default. |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // If there is a set of include filters, then make sure that the provided |
| | | // entry matches at least one of them. |
| | | if (! includeFilters.isEmpty()) { |
| | | boolean matchFound = false; |
| | | for (SearchFilter f : includeFilters) { |
| | | try { |
| | | if (f.matchesEntry(entry)) { |
| | | matchFound = true; |
| | | break; |
| | | } |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // This shouldn't happen, but if it does, then just ignore it. |
| | | } |
| | | } |
| | | |
| | | if (! matchFound) { |
| | | return; |
| | | } |
| | | // Check exclude and include filters first. |
| | | if (!filtersAllowCaching(entry)) { |
| | | return; |
| | | } |
| | | |
| | | // Obtain a lock on the cache. If this fails, then don't do anything. |
| | |
| | | */ |
| | | public boolean putEntryIfAbsent(Entry entry, Backend backend, long entryID) |
| | | { |
| | | // If there is a set of exclude filters, then make sure that the provided |
| | | // entry doesn't match any of them. |
| | | if (! excludeFilters.isEmpty()) { |
| | | for (SearchFilter f : excludeFilters) { |
| | | try { |
| | | if (f.matchesEntry(entry)) { |
| | | return true; |
| | | } |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // This shouldn't happen, but if it does then we can't be sure whether |
| | | // the entry should be excluded, so we will by default. |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // If there is a set of include filters, then make sure that the provided |
| | | // entry matches at least one of them. |
| | | if (! includeFilters.isEmpty()) { |
| | | boolean matchFound = false; |
| | | for (SearchFilter f : includeFilters) { |
| | | try { |
| | | if (f.matchesEntry(entry)) { |
| | | matchFound = true; |
| | | break; |
| | | } |
| | | } catch (Exception e) { |
| | | if (debugEnabled()) { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // This shouldn't happen, but if it does, then just ignore it. |
| | | } |
| | | } |
| | | |
| | | if (! matchFound) { |
| | | return true; |
| | | } |
| | | // Check exclude and include filters first. |
| | | if (!filtersAllowCaching(entry)) { |
| | | return true; |
| | | } |
| | | |
| | | try { |
| | |
| | | // The DN of the configuration entry for this entry cache implementation. |
| | | private DN configEntryDN; |
| | | |
| | | // The set of filters that define the entries that should be excluded from the |
| | | // cache. |
| | | private HashSet<SearchFilter> excludeFilters; |
| | | |
| | | // The set of filters that define the entries that should be included in the |
| | | // cache. |
| | | private HashSet<SearchFilter> includeFilters; |
| | | |
| | | // The reference queue that will be used to notify us whenever a soft |
| | | // reference is freed. |
| | | private ReferenceQueue<CacheEntry> referenceQueue; |
| | |
| | | */ |
| | | public void putEntry(Entry entry, Backend backend, long entryID) |
| | | { |
| | | // If there is a set of exclude filters, then make sure that the provided |
| | | // entry doesn't match any of them. |
| | | if (! excludeFilters.isEmpty()) |
| | | { |
| | | for (SearchFilter f : excludeFilters) |
| | | { |
| | | try |
| | | { |
| | | if (f.matchesEntry(entry)) |
| | | { |
| | | return; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // This shouldn't happen, but if it does then we can't be sure whether |
| | | // the entry should be excluded, so we will by default. |
| | | return; |
| | | } |
| | | } |
| | | // Check exclude and include filters first. |
| | | if (!filtersAllowCaching(entry)) { |
| | | return; |
| | | } |
| | | |
| | | |
| | | // If there is a set of include filters, then make sure that the provided |
| | | // entry matches at least one of them. |
| | | if (! includeFilters.isEmpty()) |
| | | { |
| | | boolean matchFound = false; |
| | | for (SearchFilter f : includeFilters) |
| | | { |
| | | try |
| | | { |
| | | if (f.matchesEntry(entry)) |
| | | { |
| | | matchFound = true; |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // This shouldn't happen, but if it does, then just ignore it. |
| | | } |
| | | } |
| | | |
| | | if (! matchFound) |
| | | { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | |
| | | // Create the cache entry based on the provided information. |
| | | CacheEntry cacheEntry = new CacheEntry(entry, backend, entryID); |
| | | SoftReference<CacheEntry> ref = |
| | |
| | | public boolean putEntryIfAbsent(Entry entry, Backend backend, |
| | | long entryID) |
| | | { |
| | | // If there is a set of exclude filters, then make sure that the provided |
| | | // entry doesn't match any of them. |
| | | if (! excludeFilters.isEmpty()) |
| | | { |
| | | for (SearchFilter f : excludeFilters) |
| | | { |
| | | try |
| | | { |
| | | if (f.matchesEntry(entry)) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // This shouldn't happen, but if it does then we can't be sure whether |
| | | // the entry should be excluded, so we will by default. |
| | | return false; |
| | | } |
| | | } |
| | | // Check exclude and include filters first. |
| | | if (!filtersAllowCaching(entry)) { |
| | | return true; |
| | | } |
| | | |
| | | |
| | | // If there is a set of include filters, then make sure that the provided |
| | | // entry matches at least one of them. |
| | | if (! includeFilters.isEmpty()) |
| | | { |
| | | boolean matchFound = false; |
| | | for (SearchFilter f : includeFilters) |
| | | { |
| | | try |
| | | { |
| | | if (f.matchesEntry(entry)) |
| | | { |
| | | matchFound = true; |
| | | break; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | // This shouldn't happen, but if it does, then just ignore it. |
| | | } |
| | | } |
| | | |
| | | if (! matchFound) |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | |
| | | // See if the entry already exists. If so, then return false. |
| | | if (dnMap.containsKey(entry.getDN())) |
| | | { |