From 91ab043447a92fe894e52bcd0d3f02c6af06f81b Mon Sep 17 00:00:00 2001
From: abobrov <abobrov@localhost>
Date: Mon, 16 Jul 2007 13:24:35 +0000
Subject: [PATCH] - [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.
---
opendj-sdk/opends/src/server/org/opends/server/api/EntryCache.java | 94 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 94 insertions(+), 0 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/api/EntryCache.java b/opendj-sdk/opends/src/server/org/opends/server/api/EntryCache.java
index 113016d..cddfc66 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/api/EntryCache.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/api/EntryCache.java
@@ -29,6 +29,7 @@
import java.util.List;
+import java.util.HashSet;
import java.util.concurrent.locks.Lock;
import org.opends.server.core.DirectoryServer;
@@ -38,6 +39,7 @@
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;
@@ -104,6 +106,22 @@
/**
+ * 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.
*
@@ -511,6 +529,82 @@
/**
+ * 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)
--
Gitblit v1.10.0