From c11b3a5611e1a431e62c6cfa23b881a5fdbb62b9 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 01 Sep 2014 12:51:46 +0000
Subject: [PATCH] OPENDJ-1206 (CR-4393) Create a new ReplicationBackend/ChangelogBackend to support cn=changelog

---
 opendj-sdk/opends/src/server/org/opends/server/api/Backend.java |   65 ++++++++++++++++++++++++++++----
 1 files changed, 57 insertions(+), 8 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/api/Backend.java b/opendj-sdk/opends/src/server/org/opends/server/api/Backend.java
index fcbb39c..b35c1cd 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/api/Backend.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/api/Backend.java
@@ -29,12 +29,15 @@
 import java.util.ArrayList;
 import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Queue;
 import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedQueue;
 
 import org.opends.messages.Message;
 import org.opends.server.admin.Configuration;
 import org.opends.server.config.ConfigException;
 import org.opends.server.core.*;
+import org.opends.server.core.PersistentSearch.CancellationCallback;
 import org.opends.server.monitors.BackendMonitor;
 import org.opends.server.types.*;
 
@@ -79,6 +82,10 @@
   /** The writability mode for this backend. */
   private WritabilityMode writabilityMode = WritabilityMode.ENABLED;
 
+  /** The set of persistent searches registered with this backend. */
+  private final ConcurrentLinkedQueue<PersistentSearch> persistentSearches =
+      new ConcurrentLinkedQueue<PersistentSearch>();
+
   /**
    * Configure this backend based on the information in the provided
    * configuration.
@@ -146,16 +153,26 @@
   /**
    * Performs any necessary work to finalize this backend, including
    * closing any underlying databases or connections and deregistering
-   * any suffixes that it manages with the Directory Server.  This may
+   * any suffixes that it manages with the Directory Server. This may
    * be called during the Directory Server shutdown process or if a
-   * backend is disabled with the server online.  It must not return
-   * until the backend is closed.
-   * <BR><BR>
-   * This method may not throw any exceptions.  If any problems are
-   * encountered, then they may be logged but the closure should
-   * progress as completely as possible.
+   * backend is disabled with the server online.
+   * It must not return until the backend is closed.
+   * <p>
+   * This method may not throw any exceptions. If any problems are encountered,
+   * then they may be logged but the closure should progress as completely as
+   * possible.
+   * <p>
+   * This method must be called by all overriding methods with
+   * <code>super.finalizeBackend()</code>.
    */
-  public abstract void finalizeBackend();
+  public void finalizeBackend()
+  {
+    for (PersistentSearch psearch : persistentSearches)
+    {
+      psearch.cancel();
+    }
+    persistentSearches.clear();
+  }
 
 
 
@@ -867,7 +884,39 @@
     return backendMonitor;
   }
 
+  /**
+   * Registers the provided persistent search operation with this backend so
+   * that it will be notified of any add, delete, modify, or modify DN
+   * operations that are performed.
+   *
+   * @param persistentSearch
+   *          The persistent search operation to register with this backend
+   */
+  public void registerPersistentSearch(PersistentSearch persistentSearch)
+  {
+    persistentSearches.add(persistentSearch);
 
+    persistentSearch.registerCancellationCallback(new CancellationCallback()
+    {
+      @Override
+      public void persistentSearchCancelled(PersistentSearch psearch)
+      {
+        persistentSearches.remove(psearch);
+      }
+    });
+  }
+
+  /**
+   * Returns the persistent searches currently active against this local
+   * backend.
+   *
+   * @return the list of persistent searches currently active against this local
+   *         backend
+   */
+  public Queue<PersistentSearch> getPersistentSearches()
+  {
+    return persistentSearches;
+  }
 
   /**
    * Sets the backend monitor for this backend.

--
Gitblit v1.10.0