aicas logo Jamaica 3.4 release 8

com.sun.jndi.ldap.pool
Class Pool

java.lang.Object
  extended by com.sun.jndi.ldap.pool.Pool

public final class Pool
extends Object

A map of pool ids to Connections. Key is an object that uniquely identifies a PooledConnection request (typically information needed to create the connection). The definitions of the key's equals() and hashCode() methods are vital to its unique identification in a Pool. Value is a ConnectionsRef, which is a reference to Connections, a list of equivalent connections. Supports methods that - retrieves (or creates as necessary) a connection from the pool - removes expired connections from the pool Connections cleanup: A WeakHashMap is used for mapping the pool ids and Connections. A SoftReference from the value to the key is kept to hold the map entry as long as possible. This allows the GC to remove Connections from the Pool under situations of VM running out of resources. To take an appropriate action of 'closing the connections' before the GC reclaims the ConnectionsRef objects, the ConnectionsRef objects are made weakly reachable through a list of weak references registered with a reference queue. Upon an entry gets removed from the WeakHashMap, the ConnectionsRef (value in the map) object is weakly reachable. When another sweep of clearing the weak references is made by the GC it puts the corresponding ConnectionsWeakRef object into the reference queue. The reference queue is monitored lazily for reclaimable Connections whenever a pooled connection is requested or a call to remove the expired connections is made. The monitoring is done regularly when idle connection timeout is set as the PoolCleaner removes expired connections periodically. As determined by the experiements, cleanup of resources using the ReferenceQueue mechanism is reliable and has immidiate effect than the finalizer approach.


Constructor Summary
Pool(int initSize, int prefSize, int maxSize)
           
 
Method Summary
 void expire(long threshold)
          Goes through the connections in this Pool and expires ones that have been idle before 'threshold'.
 PooledConnection getPooledConnection(Object id, long timeout, PooledConnectionFactory factory)
          Gets a pooled connection for id.
 void showStats(PrintStream out)
           
 String toString()
          toString creates a printable string that represents this object for debugging purposes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Pool

public Pool(int initSize,
            int prefSize,
            int maxSize)
Method Detail

getPooledConnection

public PooledConnection getPooledConnection(Object id,
                                            long timeout,
                                            PooledConnectionFactory factory)
                                     throws NamingException
Gets a pooled connection for id. The pooled connection might be newly created, as governed by the maxSize and prefSize settings. If a pooled connection is unavailable and cannot be created due to the maxSize constraint, this call blocks until the constraint is removed or until 'timeout' ms has elapsed.

Parameters:
id - identity of the connection to get
timeout - the number of milliseconds to wait before giving up
factory - the factory to use for creating the connection if creation is necessary
Returns:
a pooled connection
Throws:
NamingException - the connection could not be created due to an error.

expire

public void expire(long threshold)
Goes through the connections in this Pool and expires ones that have been idle before 'threshold'. An expired connection is closed and then removed from the pool (removePooledConnection() will eventually be called, and the list of pools itself removed if it becomes empty).

Parameters:
threshold - connections idle before 'threshold' should be closed and removed.

showStats

public void showStats(PrintStream out)

toString

public String toString()
Description copied from class: Object
toString creates a printable string that represents this object for debugging purposes.

The default implementation returns getClass().getName() + '@' + Integer.toHexString(hashCode()).

Overrides:
toString in class Object
Returns:
a string identifying this object.

aicas logo Jamaica 3.4 release 8

aicas GmbH, Karlsruhe - Germany    www.aicas.com
Copyright 2001-2009 aicas GmbH. All Rights Reserved.