From 39dd44d3acfe4b40413778ec3abf4d3026118aa9 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Fri, 19 Oct 2007 17:30:27 +0000
Subject: [PATCH] Fix for issue 2317: check servers for clock difference when configuring replication When the servers that are being replicated have a clock difference of more than 5 minutes inform the user of this.  This is done in both the graphical setup and dsreplication tools.

---
 opends/src/quicksetup/org/opends/quicksetup/util/Utils.java |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java b/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
index 4cb0518..fed0bfe 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
@@ -39,11 +39,14 @@
 import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.io.RandomAccessFile;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
+import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 import javax.naming.ldap.InitialLdapContext;
 import javax.naming.ldap.LdapName;
@@ -1388,6 +1391,50 @@
     }
     return emptyStream;
   }
+
+  /**
+   * Returns the current time of a server in milliseconds.
+   * @param ctx the connection to the server.
+   * @return the current time of a server in milliseconds.
+   */
+  public static long getServerClock(InitialLdapContext ctx)
+  {
+    long time = -1;
+    String v = null;
+    SearchControls ctls = new SearchControls();
+    ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
+    ctls.setReturningAttributes(
+        new String[] {
+            "currentTime"
+        });
+    String filter = "(objectclass=*)";
+
+    try
+    {
+      LdapName jndiName = new LdapName("cn=monitor");
+      NamingEnumeration listeners = ctx.search(jndiName, filter, ctls);
+
+      while(listeners.hasMore())
+      {
+        SearchResult sr = (SearchResult)listeners.next();
+
+        v = getFirstValue(sr, "currentTime");
+
+        TimeZone utcTimeZone = TimeZone.getTimeZone("UTC");
+
+        SimpleDateFormat formatter =
+             new SimpleDateFormat("yyyyMMddHHmmss'Z'");
+        formatter.setTimeZone(utcTimeZone);
+
+        time = formatter.parse(v).getTime();
+      }
+    }
+    catch (Throwable t)
+    {
+      LOG.log(Level.WARNING, "Error retrieving server current time: "+t, t);
+    }
+    return time;
+  }
 }
 
 /**

--
Gitblit v1.10.0