src/share/classes/com/sun/jndi/ldap/pool/Pool.java
Print this page
*** 28,38 ****
import java.util.Map;
import java.util.WeakHashMap;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
- import java.util.Set;
import java.util.LinkedList;
import java.io.PrintStream;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
--- 28,37 ----
*** 81,101 ****
static final boolean debug = com.sun.jndi.ldap.LdapPoolManager.debug;
/*
* Used for connections cleanup
*/
! private static final ReferenceQueue queue = new ReferenceQueue();
! private static final Collection weakRefs =
! Collections.synchronizedList(new LinkedList());
final private int maxSize; // max num of identical conn per pool
final private int prefSize; // preferred num of identical conn per pool
final private int initSize; // initial number of identical conn to create
! final private Map map;
public Pool(int initSize, int prefSize, int maxSize) {
! map = new WeakHashMap();
this.prefSize = prefSize;
this.maxSize = maxSize;
this.initSize = initSize;
}
--- 80,101 ----
static final boolean debug = com.sun.jndi.ldap.LdapPoolManager.debug;
/*
* Used for connections cleanup
*/
! private static final ReferenceQueue<ConnectionsRef> queue =
! new ReferenceQueue<>();
! private static final Collection<Reference<ConnectionsRef>> weakRefs =
! Collections.synchronizedList(new LinkedList<Reference<ConnectionsRef>>());
final private int maxSize; // max num of identical conn per pool
final private int prefSize; // preferred num of identical conn per pool
final private int initSize; // initial number of identical conn to create
! final private Map<Object, ConnectionsRef> map;
public Pool(int initSize, int prefSize, int maxSize) {
! map = new WeakHashMap<>();
this.prefSize = prefSize;
this.maxSize = maxSize;
this.initSize = initSize;
}
*** 133,143 ****
factory);
ConnectionsRef connsRef = new ConnectionsRef(conns);
map.put(id, connsRef);
// Create a weak reference to ConnectionsRef
! Reference weakRef = new ConnectionsWeakRef(connsRef, queue);
// Keep the weak reference through the element of a linked list
weakRefs.add(weakRef);
}
}
--- 133,144 ----
factory);
ConnectionsRef connsRef = new ConnectionsRef(conns);
map.put(id, connsRef);
// Create a weak reference to ConnectionsRef
! Reference<ConnectionsRef> weakRef =
! new ConnectionsWeakRef(connsRef, queue);
// Keep the weak reference through the element of a linked list
weakRefs.add(weakRef);
}
}
*** 146,156 ****
return conns.get(timeout, factory); // get one connection from list
}
private Connections getConnections(Object id) {
! ConnectionsRef ref = (ConnectionsRef) map.get(id);
return (ref != null) ? ref.getConnections() : null;
}
/**
* Goes through the connections in this Pool and expires ones that
--- 147,157 ----
return conns.get(timeout, factory); // get one connection from list
}
private Connections getConnections(Object id) {
! ConnectionsRef ref = map.get(id);
return (ref != null) ? ref.getConnections() : null;
}
/**
* Goes through the connections in this Pool and expires ones that
*** 161,175 ****
* @param threshold connections idle before 'threshold' should be closed
* and removed.
*/
public void expire(long threshold) {
synchronized (map) {
! Collection coll = map.values();
! Iterator iter = coll.iterator();
Connections conns;
while (iter.hasNext()) {
! conns = ((ConnectionsRef) (iter.next())).getConnections();
if (conns.expire(threshold)) {
d("expire(): removing ", conns);
iter.remove();
}
}
--- 162,175 ----
* @param threshold connections idle before 'threshold' should be closed
* and removed.
*/
public void expire(long threshold) {
synchronized (map) {
! Iterator<ConnectionsRef> iter = map.values().iterator();
Connections conns;
while (iter.hasNext()) {
! conns = iter.next().getConnections();
if (conns.expire(threshold)) {
d("expire(): removing ", conns);
iter.remove();
}
}
*** 200,226 ****
}
}
public void showStats(PrintStream out) {
- Map.Entry entry;
Object id;
Connections conns;
out.println("===== Pool start ======================");
out.println("maximum pool size: " + maxSize);
out.println("preferred pool size: " + prefSize);
out.println("initial pool size: " + initSize);
out.println("current pool size: " + map.size());
! Set entries = map.entrySet();
! Iterator iter = entries.iterator();
!
! while (iter.hasNext()) {
! entry = (Map.Entry) iter.next();
id = entry.getKey();
! conns = ((ConnectionsRef) entry.getValue()).getConnections();
out.println(" " + id + ":" + conns.getStats());
}
out.println("====== Pool end =====================");
}
--- 200,221 ----
}
}
public void showStats(PrintStream out) {
Object id;
Connections conns;
out.println("===== Pool start ======================");
out.println("maximum pool size: " + maxSize);
out.println("preferred pool size: " + prefSize);
out.println("initial pool size: " + initSize);
out.println("current pool size: " + map.size());
! for (Map.Entry<Object, ConnectionsRef> entry : map.entrySet()) {
id = entry.getKey();
! conns = entry.getValue().getConnections();
out.println(" " + id + ":" + conns.getStats());
}
out.println("====== Pool end =====================");
}