public class WeakTable extends Object
==
tests to work for
proxies to remote servers the same as they would for direct references
to remote servers, which also maintain this property.
Here is an example that uses this class to ensure that exactly one
copy of a java.io.Resolvable
object exists in each
VM:
private WeakTable knownProxies; public Object readResolve() { // deferred creation means this table is not allocated on the server if (knownProxies == null) knownProxies = new WeakTable(); return knownProxies.getOrAdd(remoteServer, this); }
Modifier and Type | Class and Description |
---|---|
static interface |
WeakTable.KeyGCHandler
Handler for clients that need to know when a key is removed
from the table because it has been collected.
|
Modifier and Type | Field and Description |
---|---|
private static PrintStream |
DEBUG
Print debug messages to this stream if not
null . |
private WeakTable.KeyGCHandler |
handler
Object to call back when keys are collected
|
private ReferenceQueue |
refQueue
The queue of cleared SpaceProxy objects.
|
private HashMap |
table
The map of known objects.
|
Constructor and Description |
---|
WeakTable()
Create a new WeakTable object to maintain the maps.
|
WeakTable(WeakTable.KeyGCHandler handler)
Create a new WeakTable object to maintain the maps that calls
back the designated object when keys are collected.
|
Modifier and Type | Method and Description |
---|---|
Object |
get(Object key)
Return the value associated with given key, or
null
if no value can be found. |
Object |
getOrAdd(Object key,
Object proxy)
Return the object that this key maps to.
|
Object |
remove(Object key)
Remove the object that the given key maps to.
|
void |
removeBlanks()
Remove any blank entries from the table.
|
private HashMap table
private ReferenceQueue refQueue
private static PrintStream DEBUG
null
.private WeakTable.KeyGCHandler handler
public WeakTable()
public WeakTable(WeakTable.KeyGCHandler handler)
public Object getOrAdd(Object key, Object proxy)
public Object get(Object key)
null
if no value can be found.public Object remove(Object key)
public void removeBlanks()
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.