APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.jndi.ldap.pool

public final Class Pool

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Map, .WeakHashMap, .Collection, .Collections, .LinkedList, java.util.concurrent.TimeUnit, java.util.concurrent.locks.ReentrantLock, java.io.PrintStream, java.lang.ref.Reference, .ReferenceQueue, javax.naming.CommunicationException, .NamingException

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 experimentation, cleanup of resources using the ReferenceQueue mechanism is reliable and has more immediate effect than the finalizer approach.
Author
Rosanna Lee

Field Summary

Modifier and TypeField and Description
pack-priv static final boolean
private final int
private final Map<Object, ConnectionsRef>
private final ReentrantLock
private final int
private final int
private static final ReferenceQueue<ConnectionsRef>
private static final Collection<Reference<ConnectionsRef>>

Constructor Summary

AccessConstructor and Description
public
Pool(int initSize, int prefSize, int maxSize)

Method Summary

Modifier and TypeMethod and Description
private long
checkRemaining(long start, long timeout)

private void
d(String msg, int i)

private void
d(String msg, Object obj)

public void
expire(long
connections idle before 'threshold' should be closed and removed.
threshold
)

Goes through the connections in this Pool and expires ones that have been idle before 'threshold'.

private static void
private Connections
private PooledConnection
getOrCreatePooledConnection(PooledConnectionFactory factory, Connections conns, long start, long timeout)

public PooledConnection

Returns:

a pooled connection
getPooledConnection
(Object
identity of the connection to get
id
,
long
the number of milliseconds to wait before giving up
timeout
,
PooledConnectionFactory
the factory to use for creating the connection if creation is necessary
factory
)

Gets a pooled connection for id. The pooled connection might be newly created, as governed by the maxSize and prefSize settings.

public void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

debugback to summary
pack-priv static final boolean debug
initSizeback to summary
private final int initSize
mapback to summary
private final Map<Object, ConnectionsRef> map
mapLockback to summary
private final ReentrantLock mapLock
maxSizeback to summary
private final int maxSize
prefSizeback to summary
private final int prefSize
queueback to summary
private static final ReferenceQueue<ConnectionsRef> queue
weakRefsback to summary
private static final Collection<Reference<ConnectionsRef>> weakRefs

Constructor Detail

Poolback to summary
public Pool(int initSize, int prefSize, int maxSize)

Method Detail

checkRemainingback to summary
private long checkRemaining(long start, long timeout) throws CommunicationException
dback to summary
private void d(String msg, int i)
dback to summary
private void d(String msg, Object obj)
expireback to summary
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:long

connections idle before 'threshold' should be closed and removed.

expungeStaleConnectionsback to summary
private static void expungeStaleConnections()
getOrCreateConnectionsback to summary
private Connections getOrCreateConnections(PooledConnectionFactory factory, Object id) throws NamingException
getOrCreatePooledConnectionback to summary
private PooledConnection getOrCreatePooledConnection(PooledConnectionFactory factory, Connections conns, long start, long timeout) throws NamingException
getPooledConnectionback to summary
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:Object

identity of the connection to get

timeout:long

the number of milliseconds to wait before giving up

factory:PooledConnectionFactory

the factory to use for creating the connection if creation is necessary

Returns:PooledConnection

a pooled connection

Exceptions
NamingException:
the connection could not be created due to an error.
showStatsback to summary
public void showStats(PrintStream out)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.