From 03fe0954e42abf00746b8efa4c79ee74cf514427 Mon Sep 17 00:00:00 2001
From: ludovicp <ludovicp@localhost>
Date: Thu, 27 May 2010 15:10:50 +0000
Subject: [PATCH] Fix an issue with connection timeouts in CLI. The timeout is now configurable on CLI with the --connectTimeout option (expressed in milliseconds), the default is 30 000 milliseconds. This solves Issue 4196.

---
 opends/src/ads/org/opends/admin/ads/TopologyCache.java |   25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/opends/src/ads/org/opends/admin/ads/TopologyCache.java b/opends/src/ads/org/opends/admin/ads/TopologyCache.java
index 3dc2954..8d36d01 100644
--- a/opends/src/ads/org/opends/admin/ads/TopologyCache.java
+++ b/opends/src/ads/org/opends/admin/ads/TopologyCache.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2008-2009 Sun Microsystems, Inc.
+ *      Copyright 2008-2010 Sun Microsystems, Inc.
  */
 
 package org.opends.admin.ads;
@@ -69,6 +69,7 @@
 {
   private ADSContext adsContext;
   private ApplicationTrustManager trustManager;
+  private int timeout;
   private String dn;
   private String pwd;
   private Set<ServerDescriptor> servers = new HashSet<ServerDescriptor>();
@@ -90,12 +91,16 @@
    * @param trustManager the ApplicationTrustManager that must be used to trust
    * certificates when we create connections to the registered servers to read
    * their configuration.
+   * @param timeout the timeout to establish the connection in milliseconds.
+   * Use {@code 0} to express no timeout.
    */
   public TopologyCache(ADSContext adsContext,
-      ApplicationTrustManager trustManager)
+      ApplicationTrustManager trustManager,
+      int timeout)
   {
     this.adsContext = adsContext;
     this.trustManager = trustManager;
+    this.timeout = timeout;
     dn = ConnectionUtils.getBindDN(adsContext.getDirContext());
     pwd = ConnectionUtils.getBindPassword(adsContext.getDirContext());
   }
@@ -207,6 +212,16 @@
   }
 
   /**
+   * Returns the timeout to establish the connection in milliseconds.
+   * @return the timeout to establish the connection in milliseconds. Returns
+   * {@code 0} to express no timeout.
+   */
+  public int getConnectTimeout()
+  {
+    return timeout;
+  }
+
+  /**
    * Reads the replication monitoring.
    * @throws NamingException if an error occurs reading the replication
    * monitoring.
@@ -373,6 +388,7 @@
   {
     return new ServerLoader(serverProperties, dn, pwd,
         trustManager == null ? null : trustManager.createCopy(),
+            timeout,
             getPreferredConnections(), getFilter());
   }
 
@@ -464,11 +480,12 @@
       ServerLoader loader =
         getServerLoader(replicationServer.getAdsProperties());
       ctx = loader.createContext();
-      NamingEnumeration monitorEntries = ctx.search(jndiName, filter, ctls);
+      NamingEnumeration<SearchResult> monitorEntries =
+        ctx.search(jndiName, filter, ctls);
 
       while(monitorEntries.hasMore())
       {
-        SearchResult sr = (SearchResult)monitorEntries.next();
+        SearchResult sr = monitorEntries.next();
 
         String dn = ConnectionUtils.getFirstValue(sr, "domain-name");
         int replicaId = -1;

--
Gitblit v1.10.0