From 3fcf167e0af7a8f405442b3b4c8b07404ec6c0ff Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Fri, 02 Mar 2007 09:22:58 +0000
Subject: [PATCH] issue 504,505,507 : res-synchronization after restore or import

---
 opendj-sdk/opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java |  105 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 92 insertions(+), 13 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java b/opendj-sdk/opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java
index 0996049..7a4f620 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java
@@ -158,6 +158,8 @@
 
   private boolean solveConflictFlag = true;
 
+  private boolean disabled = false;
+
   static final String CHANGELOG_SERVER_ATTR = "ds-cfg-changelog-server";
   static final String BASE_DN_ATTR = "ds-cfg-synchronization-dn";
   static final String SERVER_ID_ATTR = "ds-cfg-directory-server-id";
@@ -1093,18 +1095,10 @@
   @Override
   public void run()
   {
-    /* synchroThreads
-     * create the threads that will wait for incoming changes
-     * TODO : should use a pool of threads shared between all the servers
-     * TODO : need to make number of thread configurable
-     * TODO : need to handle operation dependencies
+    /*
+     * create the threads that will wait for incoming changes.
      */
-    for (int i=0; i<listenerThreadNumber; i++)
-    {
-      ListenerThread myThread = new ListenerThread(this);
-      myThread.start();
-      synchroThreads.add(myThread);
-    }
+    createListeners();
 
     while (shutdown  == false)
     {
@@ -1113,8 +1107,11 @@
         synchronized (this)
         {
           this.wait(1000);
-          // save the RUV
-          state.save();
+          if (!disabled )
+          {
+            // save the RUV
+            state.save();
+          }
         }
       } catch (InterruptedException e)
       { }
@@ -1123,6 +1120,22 @@
   }
 
   /**
+   * create the threads that will wait for incoming changes.
+   * TODO : should use a pool of threads shared between all the servers
+   * TODO : need to make number of thread configurable
+   */
+  private void createListeners()
+  {
+    synchroThreads.clear();
+    for (int i=0; i<listenerThreadNumber; i++)
+    {
+      ListenerThread myThread = new ListenerThread(this);
+      myThread.start();
+      synchroThreads.add(myThread);
+    }
+  }
+
+  /**
    * Shutdown this SynchronizationDomain.
    */
   public void shutdown()
@@ -1854,4 +1867,70 @@
   {
     return solveConflictFlag;
   }
+
+  /**
+   * Disable the Synchronization on this domain.
+   * The session to the Synchronization server will be stopped.
+   * The domain will not be destroyed but call to the pre-operation
+   * methods will result in failure.
+   * The listener threads will be destroyed.
+   * The monitor informations will still be accessible.
+   */
+  public void disable()
+  {
+    state.save();
+    state.clear();
+    disabled = true;
+    //  stop the listener threads
+    for (ListenerThread thread : synchroThreads)
+    {
+      thread.shutdown();
+    }
+    broker.stop(); // this will cut the session and wake-up the listeners
+  }
+
+  /**
+   * Enable back the domain after a previous disable.
+   * The domain will connect back to a Synchronization Server and
+   * will recreate threads to listen for messages from the Sycnhronization
+   * server.
+   * The ServerState will also be read again from the local database.
+   */
+  public void enable()
+  {
+    state.clear();
+    state.loadState();
+    disabled = false;
+
+    try
+    {
+      broker.start(changelogServers);
+    } catch (Exception e)
+    {
+      /* TODO should mark that changelog service is
+       * not available, log an error and retry upon timeout
+       * should we stop the modifications ?
+       */
+      e.printStackTrace();
+      return;
+    }
+    createListeners();
+  }
+
+  /**
+   * Do whatever is needed when a backup is started.
+   * We need to make sure that the serverState is correclty save.
+   */
+  public void backupStart()
+  {
+    state.save();
+  }
+
+  /**
+   * Do whatever is needed when a backup is finished.
+   */
+  public void backupEnd()
+  {
+    // Nothing is needed at the moment
+  }
 }

--
Gitblit v1.10.0