From d04fb0f282e0fd9a4bc80d3f9d5ee15506a3b83b Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Mon, 08 Dec 2008 08:03:33 +0000
Subject: [PATCH] Merge the replication-service branch with the OpenDS trunk

---
 opends/src/server/org/opends/server/replication/server/MonitorData.java |   66 ++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 1 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/server/MonitorData.java b/opends/src/server/org/opends/server/replication/server/MonitorData.java
index 0801257..25b9992 100644
--- a/opends/src/server/org/opends/server/replication/server/MonitorData.java
+++ b/opends/src/server/org/opends/server/replication/server/MonitorData.java
@@ -69,6 +69,10 @@
   private ConcurrentHashMap<Short, ServerState> LDAPStates =
     new ConcurrentHashMap<Short, ServerState>();
 
+  // A Map containing the ServerStates of each RS.
+  private ConcurrentHashMap<Short, ServerState> RSStates =
+    new ConcurrentHashMap<Short, ServerState>();
+
   // For each LDAP server, the last(max) CN it published
   private ConcurrentHashMap<Short, ChangeNumber> maxCNs =
     new ConcurrentHashMap<Short, ChangeNumber>();
@@ -86,6 +90,9 @@
   private ConcurrentHashMap<Short, Long> fmRSDate =
     new ConcurrentHashMap<Short, Long>();
 
+  private ConcurrentHashMap<Short, Long> missingChangesRS =
+    new ConcurrentHashMap<Short, Long>();
+
 
   /**
    * Get an approximation of the latency delay of the replication.
@@ -129,13 +136,29 @@
   }
 
   /**
+   * Get the number of missing changes for a Replication Server.
+   *
+   * @param serverId   The server ID.
+   *
+   * @return           The number of missing changes.
+   */
+  public long getMissingChangesRS(short serverId)
+  {
+    Long res = missingChangesRS.get(serverId);
+    if (res==null)
+      return 0;
+    else
+      return res;
+  }
+
+  /**
    * Build the monitor data that are computed from the collected ones.
    */
   public void completeComputing()
   {
     String mds = "";
 
-    // Computes the missing changes counters
+    // Computes the missing changes counters for LDAP servers
     // For each LSi ,
     //   Regarding each other LSj
     //    Sum the difference : max(LSj) - state(LSi)
@@ -167,6 +190,36 @@
       }
       mds += "=" + lsiMissingChanges;
       this.missingChanges.put(lsiSid,lsiMissingChanges);
+    }
+
+    // Computes the missing changes counters for RS :
+    // Sum the difference of seqnuence numbers for each element in the States.
+
+    for (short lsiSid : RSStates.keySet())
+    {
+      ServerState lsiState = this.RSStates.get(lsiSid);
+      Long lsiMissingChanges = (long)0;
+      if (lsiState != null)
+      {
+        Iterator<Short> lsjMaxItr = this.maxCNs.keySet().iterator();
+        while (lsjMaxItr.hasNext())
+        {
+          Short lsjSid = lsjMaxItr.next();
+          ChangeNumber lsjMaxCN = this.maxCNs.get(lsjSid);
+          ChangeNumber lsiLastCN = lsiState.getMaxChangeNumber(lsjSid);
+
+          int missingChangesLsiLsj =
+            ChangeNumber.diffSeqNum(lsjMaxCN, lsiLastCN);
+
+          mds +=
+            "+ diff("+lsjMaxCN+"-"
+                     +lsiLastCN+")="+missingChangesLsiLsj;
+
+          lsiMissingChanges += missingChangesLsiLsj;
+        }
+      }
+      mds += "=" + lsiMissingChanges;
+      this.missingChangesRS.put(lsiSid,lsiMissingChanges);
 
       if (debugEnabled())
         TRACER.debugInfo(
@@ -307,6 +360,17 @@
   }
 
   /**
+   * Set the state of the RS with the provided serverId.
+   *
+   * @param serverId   The server ID.
+   * @param state      The server state.
+   */
+  public void setRSState(short serverId, ServerState state)
+  {
+    RSStates.put(serverId, state);
+  }
+
+  /**
    * Set the state of the LDAP server with the provided serverId.
    * @param serverId The server ID.
    * @param newFmd The first missing date.

--
Gitblit v1.10.0