use of com.unboundid.ldap.sdk.LDAPConnectionPool in project oxCore by GluuFederation.
the class LdapConnectionProvider method createConnectionPoolWithWaitImpl.
private LDAPConnectionPool createConnectionPoolWithWaitImpl(Properties props, FailoverServerSet failoverSet, BindRequest bindRequest, LDAPConnectionOptions connectionOptions, int maxConnections, SSLUtil sslUtil) throws LDAPException {
String connectionPoolMaxWaitTime = props.getProperty("connection-pool-max-wait-time");
int connectionPoolMaxWaitTimeSeconds = 30;
if (StringHelper.isNotEmpty(connectionPoolMaxWaitTime)) {
connectionPoolMaxWaitTimeSeconds = Integer.parseInt(connectionPoolMaxWaitTime);
}
LOG.debug("Using LDAP connection pool timeout: '" + connectionPoolMaxWaitTimeSeconds + "'");
LDAPConnectionPool createdConnectionPool = null;
LDAPException lastException = null;
int attempt = 0;
long currentTime = System.currentTimeMillis();
long maxWaitTime = currentTime + connectionPoolMaxWaitTimeSeconds * 1000;
do {
attempt++;
if (attempt > 0) {
LOG.info("Attempting to create connection pool: " + attempt);
}
try {
createdConnectionPool = createConnectionPoolImpl(failoverSet, bindRequest, connectionOptions, maxConnections, sslUtil);
break;
} catch (LDAPException ex) {
if (ex.getResultCode().intValue() != ResultCode.CONNECT_ERROR_INT_VALUE) {
throw ex;
}
lastException = ex;
}
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
LOG.error("Exception happened in sleep", ex);
return null;
}
currentTime = System.currentTimeMillis();
} while (maxWaitTime > currentTime);
if ((createdConnectionPool == null) && (lastException != null)) {
throw lastException;
}
return createdConnectionPool;
}
use of com.unboundid.ldap.sdk.LDAPConnectionPool in project zm-mailbox by Zimbra.
the class LdapConnectionPool method createConnPool.
private static LDAPConnectionPool createConnPool(LdapServerConfig config) throws LdapException {
LdapServerPool serverPool = new LdapServerPool(config);
ServerSet serverSet = serverPool.getServerSet();
BindRequest bindRequest = createBindRequest(config);
PostConnectProcessor postConnectProcessor = null;
if (serverPool.getConnectionType() == LdapConnType.STARTTLS) {
SSLContext startTLSContext = LdapSSLUtil.createSSLContext(config.sslAllowUntrustedCerts());
postConnectProcessor = new StartTLSPostConnectProcessor(startTLSContext);
}
LDAPConnectionPool connPool = null;
try {
connPool = new LDAPConnectionPool(serverSet, bindRequest, config.getConnPoolInitSize(), config.getConnPoolMaxSize(), postConnectProcessor);
connPool.setRetryFailedOperationsDueToInvalidConnections(true);
} catch (LDAPException e) {
throw UBIDLdapException.mapToLdapException(e);
}
return connPool;
}
use of com.unboundid.ldap.sdk.LDAPConnectionPool in project zm-mailbox by Zimbra.
the class LdapConnectionPool method addToPoolMap.
private static synchronized void addToPoolMap(LDAPConnectionPool connPool) {
String poolName = connPool.getConnectionPoolName();
LDAPConnectionPool pool = connPools.get(poolName);
assert (pool == null);
connPools.put(poolName, connPool);
}
use of com.unboundid.ldap.sdk.LDAPConnectionPool in project zm-mailbox by Zimbra.
the class LdapConnectionPool method createConnectionPool.
static LDAPConnectionPool createConnectionPool(String connPoolName, LdapServerConfig config) throws LdapException {
LDAPConnectionPool connPool = null;
if (InMemoryLdapServer.isOn()) {
connPool = createConnPoolToInMemoryLdapServer(config);
} else {
connPool = createConnPool(config);
}
connPool.setConnectionPoolName(connPoolName);
connPool.setMaxWaitTimeMillis(config.getConnPoolTimeoutMillis());
boolean onCheckoutHealthCheckEnabled = config.isConnPoolHelathCheckOnCheckoutEnabled();
boolean backgroundHealthCheckEnabled = !onCheckoutHealthCheckEnabled;
// because otherwise it has no effect anyway.
if (backgroundHealthCheckEnabled) {
connPool.setHealthCheckIntervalMillis(config.getConnPoolHelathCheckBackgroundIntervalMillis());
}
GetEntryLDAPConnectionPoolHealthCheck healthChecker = new GetEntryLDAPConnectionPoolHealthCheck(// entryDN (null means root DSE)
null, // maxResponseTime
config.getConnPoolHelathCheckMaxResponseTimeMillis(), // invokeOnCreate
false, // invokeOnCheckout
onCheckoutHealthCheckEnabled, // invokeOnRelease
false, // invokeForBackgroundChecks
backgroundHealthCheckEnabled, // invokeOnException
false);
connPool.setHealthCheck(healthChecker);
addToPoolMap(connPool);
return connPool;
}
use of com.unboundid.ldap.sdk.LDAPConnectionPool in project zm-mailbox by Zimbra.
the class TestLdapConnection method onCheckoutHealthCheck.
@Test
public void onCheckoutHealthCheck() throws Exception {
SKIP_FOR_INMEM_LDAP_SERVER(SkipTestReason.CONNECTION_POOL_HEALTH_CHECK);
Map<KnownKey, String> lcKeysToModify = new HashMap<KnownKey, String>();
lcKeysToModify.put(LC.ldap_connect_pool_health_check_on_checkout_enabled, "true");
// lcKeysToModify.put(LC.ldap_connect_pool_health_check_after_exception_enabled, "false");
// lcKeysToModify.put(LC.ldap_connect_pool_health_check_background_enabled, "false");
Map<KnownKey, String> origLCKeyValues = setLocalConfig(lcKeysToModify);
final int NUM_CONNS = 10;
ExternalLdapConfig ldapConfig = new ExternalLdapConfig(LDAP_URL_ON_CHECKOUT, START_TLS_ENABLED, null, BIND_DN, BIND_PASSWORD, null, null);
LDAPConnectionPool connPool = populateConnPool(ldapConfig, NUM_CONNS);
// stop ldap server here
System.out.println("Before health check, availConns = " + connPool.getCurrentAvailableConnections());
stopLdap();
// try to get a connection from the pool to trigger health check
boolean caughtException = false;
try {
UBIDLdapContext zlc = getContext(ldapConfig);
} catch (ServiceException e) {
caughtException = true;
}
assertTrue(caughtException);
System.out.println("After health check, availConns = " + connPool.getCurrentAvailableConnections());
assertEquals(0, connPool.getCurrentAvailableConnections());
// put the config key back
setLocalConfig(origLCKeyValues);
startLdap();
// get a connection now, should be successful
UBIDLdapContext zlc = getContext(ldapConfig);
closeContext(zlc);
}
Aggregations