< prev index next >

src/java.naming/share/classes/com/sun/jndi/ldap/LdapPoolManager.java

Print this page
rev 15155 : 8156824: com.sun.jndi.ldap.pool.PoolCleaner should clear its context class loader
Reviewed-by:


  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.jndi.ldap;
  27 
  28 import java.io.PrintStream;
  29 import java.io.OutputStream;
  30 import java.util.Hashtable;
  31 import java.util.Locale;
  32 import java.util.StringTokenizer;
  33 
  34 import javax.naming.ldap.Control;
  35 import javax.naming.NamingException;
  36 import javax.naming.CommunicationException;
  37 import java.security.AccessController;
  38 import java.security.PrivilegedAction;
  39 
  40 import com.sun.jndi.ldap.pool.PoolCleaner;
  41 import com.sun.jndi.ldap.pool.Pool;

  42 
  43 /**
  44  * Contains utilities for managing connection pools of LdapClient.
  45  * Contains method for
  46  * - checking whether attempted connection creation may be pooled
  47  * - creating a pooled connection
  48  * - closing idle connections.
  49  *
  50  * If a timeout period has been configured, then it will automatically
  51  * close and remove idle connections (those that have not been
  52  * used for the duration of the timeout period).
  53  *
  54  * @author Rosanna Lee
  55  */
  56 
  57 public final class LdapPoolManager {
  58     private static final String DEBUG =
  59         "com.sun.jndi.ldap.connect.pool.debug";
  60 
  61     public static final boolean debug =


 146         }
 147 
 148         // Determine supported protocols
 149         str= getProperty(POOL_PROTOCOL, DEFAULT_PROTOCOLS);
 150         parser = new StringTokenizer(str);
 151         count = parser.countTokens();
 152         String proto;
 153         for (int i = 0; i < count; i++) {
 154             proto = parser.nextToken();
 155             if ("plain".equalsIgnoreCase(proto)) {
 156                 supportPlainProtocol = true;
 157             } else if ("ssl".equalsIgnoreCase(proto)) {
 158                 supportSslProtocol = true;
 159             } else {
 160                 // ignore
 161             }
 162         }
 163 
 164         if (idleTimeout > 0) {
 165             // Create cleaner to expire idle connections
 166             new PoolCleaner(idleTimeout, pools).start();










 167         }
 168 
 169         if (debug) {
 170             showStats(System.err);
 171         }
 172     }
 173 
 174     // Cannot instantiate one of these
 175     private LdapPoolManager() {
 176     }
 177 
 178     /**
 179      * Find the index of the pool for the specified mechanism. If not
 180      * one of "none", "simple", "DIGEST-MD5", or "GSSAPI",
 181      * return -1.
 182      * @param mech mechanism type
 183      */
 184     private static int findPool(String mech) {
 185         if ("none".equalsIgnoreCase(mech)) {
 186             return NONE;




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.jndi.ldap;
  27 
  28 import java.io.PrintStream;
  29 import java.io.OutputStream;
  30 import java.util.Hashtable;
  31 import java.util.Locale;
  32 import java.util.StringTokenizer;
  33 
  34 import javax.naming.ldap.Control;
  35 import javax.naming.NamingException;
  36 import javax.naming.CommunicationException;
  37 import java.security.AccessController;
  38 import java.security.PrivilegedAction;
  39 
  40 import com.sun.jndi.ldap.pool.PoolCleaner;
  41 import com.sun.jndi.ldap.pool.Pool;
  42 import jdk.internal.misc.InnocuousThread;
  43 
  44 /**
  45  * Contains utilities for managing connection pools of LdapClient.
  46  * Contains method for
  47  * - checking whether attempted connection creation may be pooled
  48  * - creating a pooled connection
  49  * - closing idle connections.
  50  *
  51  * If a timeout period has been configured, then it will automatically
  52  * close and remove idle connections (those that have not been
  53  * used for the duration of the timeout period).
  54  *
  55  * @author Rosanna Lee
  56  */
  57 
  58 public final class LdapPoolManager {
  59     private static final String DEBUG =
  60         "com.sun.jndi.ldap.connect.pool.debug";
  61 
  62     public static final boolean debug =


 147         }
 148 
 149         // Determine supported protocols
 150         str= getProperty(POOL_PROTOCOL, DEFAULT_PROTOCOLS);
 151         parser = new StringTokenizer(str);
 152         count = parser.countTokens();
 153         String proto;
 154         for (int i = 0; i < count; i++) {
 155             proto = parser.nextToken();
 156             if ("plain".equalsIgnoreCase(proto)) {
 157                 supportPlainProtocol = true;
 158             } else if ("ssl".equalsIgnoreCase(proto)) {
 159                 supportSslProtocol = true;
 160             } else {
 161                 // ignore
 162             }
 163         }
 164 
 165         if (idleTimeout > 0) {
 166             // Create cleaner to expire idle connections
 167             PrivilegedAction<Void> pa = new PrivilegedAction<Void>() {
 168                 public Void run() {
 169                     Thread t = InnocuousThread.newSystemThread(
 170                             "LDAP PoolCleaner",
 171                             new PoolCleaner(idleTimeout, pools));
 172                     assert t.getContextClassLoader() == null;
 173                     t.setDaemon(true);
 174                     t.start();
 175                     return null;
 176                 }};
 177             AccessController.doPrivileged(pa);
 178         }
 179 
 180         if (debug) {
 181             showStats(System.err);
 182         }
 183     }
 184 
 185     // Cannot instantiate one of these
 186     private LdapPoolManager() {
 187     }
 188 
 189     /**
 190      * Find the index of the pool for the specified mechanism. If not
 191      * one of "none", "simple", "DIGEST-MD5", or "GSSAPI",
 192      * return -1.
 193      * @param mech mechanism type
 194      */
 195     private static int findPool(String mech) {
 196         if ("none".equalsIgnoreCase(mech)) {
 197             return NONE;


< prev index next >