/** * Tests if the allowable lifetime of the given connection has already elapsed. Edge cases: * * <ol> * <li>Non-{@link PooledLDAPConnection} - returns <code>true</code> * <li><code>maxTtl</code> <= 0 - returns <code>true</code> * <li>Connection birthdate in the future - returns <code>true</code> * </ol> */ public boolean isConnectionAlive(LDAPConnection connectionToTest) { if (!(connectionToTest instanceof PooledLDAPConnection)) { if (log.isDebugEnabled()) { log.debug( "isConnectionAlive(): connection not of expected type [" + (connectionToTest == null ? "null" : connectionToTest.getClass().getName()) + "], returning true"); } return true; } if (maxTtl <= 0) { if (log.isDebugEnabled()) { log.debug("isConnectionAlive(): maxTtl set to infinite [" + maxTtl + "], returning true"); } return true; } long now = System.currentTimeMillis(); long then = ((PooledLDAPConnection) connectionToTest).getBirthdate(); long elapsed = now - then; boolean isAlive = elapsed <= maxTtl; if (log.isDebugEnabled()) { log.debug( "isConnectionAlive(): [now = " + now + "][then = " + then + "][elapsed = " + elapsed + "][max TTL = " + maxTtl + "][isAlive = " + isAlive + "]"); } return isAlive; }