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/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java |   33 +++++++++++++++++++++++++++++----
 1 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java b/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
index 503c6ae..26282cb 100644
--- a/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
+++ b/opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2009 Sun Microsystems, Inc.
+ *      Copyright 2006-2010 Sun Microsystems, Inc.
  */
 
 package org.opends.guitools.uninstaller;
@@ -155,6 +155,8 @@
       userData.setForceOnError(args.isForceOnError());
       userData.setTrustManager(args.getTrustManager());
 
+      userData.setConnectTimeout(getConnectTimeout());
+
       /*
        * Step 2: check that the provided parameters are compatible.
        */
@@ -249,6 +251,7 @@
       }
       info = ControlPanelInfo.getInstance();
       info.setTrustManager(userData.getTrustManager());
+      info.setConnectTimeout(getConnectTimeout());
       info.regenerateDescriptor();
       info.setConnectionPolicy(ConnectionProtocolPolicy.USE_ADMIN);
 
@@ -1161,7 +1164,7 @@
     try
     {
       info.setTrustManager(userData.getTrustManager());
-
+      info.setConnectTimeout(getConnectTimeout());
       String host = "localhost";
       int port = 389;
       String adminUid = userData.getAdminUID();
@@ -1181,7 +1184,8 @@
         LOG.log(Level.SEVERE, "Error parsing url: "+adminConnectorUrl);
       }
       ctx = createAdministrativeContext(host, port, useSSL, useStartTLS, dn,
-          pwd, userData.getTrustManager());
+          pwd, getConnectTimeout(),
+          userData.getTrustManager());
 
       ADSContext adsContext = new ADSContext(ctx);
       if (interactive && (userData.getTrustManager() == null))
@@ -1195,7 +1199,7 @@
       }
       LOG.log(Level.INFO, "Reloading topology");
       TopologyCache cache = new TopologyCache(adsContext,
-          userData.getTrustManager());
+          userData.getTrustManager(), getConnectTimeout());
       cache.getFilter().setSearchMonitoringInformation(false);
       cache.reloadTopology();
 
@@ -1556,4 +1560,25 @@
      super.println(msg);
      LOG.log(Level.WARNING, msg.toString());
    }
+
+   /**
+    * Returns the timeout to be used to connect in milliseconds.  The method
+    * must be called after parsing the arguments.
+    * @return the timeout to be used to connect in milliseconds.  Returns
+    * {@code 0} if there is no timeout.
+    * @throw {@code IllegalStateException} if the method is called before
+    * parsing the arguments.
+    */
+   private int getConnectTimeout()
+   {
+     try
+     {
+       return parser.getSecureArgsList().connectTimeoutArg.getIntValue();
+     }
+     catch (ArgumentException ae)
+     {
+       throw new IllegalStateException("Argument parser is not parsed: "+ae,
+           ae);
+     }
+   }
 }

--
Gitblit v1.10.0