...
Code Block | ||
---|---|---|
| ||
class HashMetaData {
private Map<WeakReference<SSLSocket>, InetAddress> m =
Collections.synchronizedMap(
new HashMap<WeakReference<SSLSocket>, InetAddress>());
ReferenceQueue queue = new ReferenceQueue();
public void storeTempConnection(SSLSocket sock, InetAddress ip) {
WeakReference<SSLSocket> wr;
// Poll for dead entries before adding more
while ((wr = (WeakReference) queue.poll()) != null) {
// Removes the WeakReference object and the value (not the referent)
m.remove(wr);
}
wr = new WeakReference<SSLSocket>(sock, queue);
m.put(wr, ip);
}
public void removeTempConnection(SSLSocket sock) {
m.remove(sock);
}
}
|
...
Code Block | ||
---|---|---|
| ||
class HashMetaData { private Map<SoftReference<SSLSocket>, InetAddress> m = Collections.synchronizedMap( new HashMap<SoftReference<SSLSocket>, InetAddress>()); ReferenceQueue queue = new ReferenceQueue(); public void storeTempConnection(SSLSocket sock, InetAddress ip) { SoftReference<SSLSocket> sr; while ((sr = (SoftReference) queue.poll()) != null) { // Removes the WeakReference object and the value (not the referent) m.remove(sr); } sr = new SoftReference<SSLSocket>(sock, queue); m.put(sr, ip); } public void removeTempConnection(SSLSocket sock) { m.remove(sock); } } |
...