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.
|
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.
|
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 © 2016–2018. All rights reserved.