예제 #1
0
  public static LDAPConnection getConnection() {

    LDAPConnection connectionToGive = null;
    if (LDAPConnectionPool.connections.size() == 0) { // create a new connection
      connectionToGive = LDAPConnectionPool.establishNewConnection();
    } else { // else use an existing one...
      try {
        if (LDAPConnectionPool.verbose) {
          System.out.println("Pool size : " + LDAPConnectionPool.connections.size());
        }
        connectionToGive = (LDAPConnection) LDAPConnectionPool.connections.firstElement();
        LDAPConnectionPool.connections.removeElementAt(0);
        if (LDAPConnectionPool.verbose) {
          System.out.println(
              "reusing connection. " + LDAPConnectionPool.connections.size() + " connections left");
        }
      } catch (final NoSuchElementException zeroErr) {

      }
    }
    return connectionToGive;
  }
예제 #2
0
 public static void closeAllConnections() {
   final Enumeration allConnections = LDAPConnectionPool.connections.elements();
   while (allConnections.hasMoreElements()) {
     LDAPConnectionPool.closeConnection((LDAPConnection) allConnections.nextElement());
   }
 }