From b05ed82c390ac4d8ac800597ba37ffb5e1f39f1b Mon Sep 17 00:00:00 2001
From: abobrov <abobrov@localhost>
Date: Sat, 14 Jul 2007 20:56:31 +0000
Subject: [PATCH] - [Issue 1771]  entry cache implementations should flush entries when backends go offline:    this fix makes entry cache registered with backend initialization listener and clears related     entries when their backend about to go offline.

---
 opends/src/server/org/opends/server/api/EntryCache.java |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/opends/src/server/org/opends/server/api/EntryCache.java b/opends/src/server/org/opends/server/api/EntryCache.java
index 0907459..113016d 100644
--- a/opends/src/server/org/opends/server/api/EntryCache.java
+++ b/opends/src/server/org/opends/server/api/EntryCache.java
@@ -31,6 +31,7 @@
 import java.util.List;
 import java.util.concurrent.locks.Lock;
 
+import org.opends.server.core.DirectoryServer;
 import org.opends.server.config.ConfigException;
 import org.opends.server.types.DN;
 import org.opends.server.types.Entry;
@@ -72,8 +73,22 @@
  */
 public abstract class EntryCache
        <T extends EntryCacheCfg>
+       implements BackendInitializationListener
 {
   /**
+   * Default constructor which is implicitly called from all entry
+   * cache implementations.
+   */
+  public EntryCache()
+  {
+    // Register with backend initialization listener to clear cache
+    // entries belonging to given backend that about to go offline.
+    DirectoryServer.registerBackendInitializationListener(this);
+  }
+
+
+
+  /**
    * The tracer object for the debug logger.
    */
   private static final DebugTracer TRACER = getTracer();
@@ -492,4 +507,27 @@
    * to avoid out of memory errors.
    */
   public abstract void handleLowMemory();
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  public void performBackendInitializationProcessing(Backend backend)
+  {
+    // Do nothing.
+  }
+
+
+
+  /**
+   * {@inheritDoc}
+   */
+  public void performBackendFinalizationProcessing(Backend backend)
+  {
+    // Do not clear any backends if the server is shutting down.
+    if ( !(DirectoryServer.getInstance().isShuttingDown()) ) {
+      clearBackend(backend);
+    }
+  }
 }

--
Gitblit v1.10.0