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/quicksetup/org/opends/quicksetup/installer/Installer.java | 56 ++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 46 insertions(+), 10 deletions(-)
diff --git a/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java b/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
index e4f57d6..b898478 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -242,9 +242,34 @@
public UserData createUserData() {
UserData ud = new UserData();
ud.setServerLocation(getDefaultServerLocation());
+ initializeUserDataWithUserArguments(ud, getUserArguments());
return ud;
}
+ private void initializeUserDataWithUserArguments(UserData ud,
+ String[] userArguments)
+ {
+ for (int i=0; i<userArguments.length; i++)
+ {
+ if (userArguments[i].equalsIgnoreCase("--connectTimeout"))
+ {
+ if (i < userArguments.length - 1)
+ {
+ String sTimeout = userArguments[i+1];
+ try
+ {
+ ud.setConnectTimeout(new Integer(sTimeout));
+ }
+ catch (Throwable t)
+ {
+ LOG.log(Level.WARNING, "Error getting connect timeout: "+t, t);
+ }
+ }
+ break;
+ }
+ }
+ }
+
/**
* {@inheritDoc}
*/
@@ -1553,12 +1578,12 @@
ApplicationTrustManager trustManager = getTrustManager();
trustManager.setHost(auth.getHostName());
ctx = createLdapsContext(ldapUrl, dn, pwd,
- getDefaultLDAPTimeout(), null, trustManager);
+ getConnectTimeout(), null, trustManager);
}
else
{
ctx = createLdapContext(ldapUrl, dn, pwd,
- getDefaultLDAPTimeout(), null);
+ getConnectTimeout(), null);
}
ADSContext adsContext = new ADSContext(ctx);
@@ -2619,12 +2644,12 @@
ApplicationTrustManager trustManager = getTrustManager();
trustManager.setHost(auth.getHostName());
remoteCtx = createLdapsContext(ldapUrl, dn, pwd,
- getDefaultLDAPTimeout(), null, trustManager);
+ getConnectTimeout(), null, trustManager);
}
else
{
remoteCtx = createLdapContext(ldapUrl, dn, pwd,
- getDefaultLDAPTimeout(), null);
+ getConnectTimeout(), null);
}
adsContext = new ADSContext(remoteCtx); // adsContext owns remoteCtx
@@ -3613,7 +3638,7 @@
try
{
ctx = createLdapsContext(ldapUrl, dn, pwd,
- getDefaultLDAPTimeout(), null, trustManager);
+ getConnectTimeout(), null, trustManager);
}
catch (Throwable t)
{
@@ -3623,7 +3648,7 @@
dn = ADSContext.getAdministratorDN(dn);
effectiveDn[0] = dn;
ctx = createLdapsContext(ldapUrl, dn, pwd,
- getDefaultLDAPTimeout(), null, trustManager);
+ getConnectTimeout(), null, trustManager);
}
else
{
@@ -4227,7 +4252,8 @@
{
type = SuffixesToReplicateOptions.Type.NEW_SUFFIX_IN_TOPOLOGY;
}
- lastLoadedCache = new TopologyCache(adsContext, trustManager);
+ lastLoadedCache = new TopologyCache(adsContext, trustManager,
+ getConnectTimeout());
LinkedHashSet<PreferredConnection> cnx =
new LinkedHashSet<PreferredConnection>();
cnx.add(PreferredConnection.getPreferredConnection(
@@ -4409,7 +4435,7 @@
String dn = getUserData().getDirectoryManagerDn();
String pwd = getUserData().getDirectoryManagerPwd();
return createLdapsContext(ldapUrl, dn, pwd,
- getDefaultLDAPTimeout(), null, null);
+ getConnectTimeout(), null, null);
}
/**
@@ -4458,8 +4484,8 @@
}
server.setAdsProperties(adsProperties);
}
- return getRemoteConnection(server, auth.getDn(), auth.getPwd(),
- trustManager, cnx);
+ return getRemoteConnection(server, auth.getDn(), auth.getPwd(),
+ trustManager, getConnectTimeout(), cnx);
}
/**
@@ -5033,6 +5059,16 @@
lastImportProgress = parsedMessage;
}
}
+
+ /**
+ * Returns the timeout to be used to connect in milliseconds.
+ * @return the timeout to be used to connect in milliseconds. Returns
+ * {@code 0} if there is no timeout.
+ */
+ protected int getConnectTimeout()
+ {
+ return getUserData().getConnectTimeout();
+ }
}
/**
--
Gitblit v1.10.0