GigaSpaces XAP 9.7.2 API

com.sun.jini.collection
Class WeakTable

java.lang.Object
  extended by com.sun.jini.collection.WeakTable

public class WeakTable
extends Object

This class is designed to allow weakly held keys to weakly held objects. For example, it can be used for smart proxy objects that maintain equality for references to the same remote server. If a single VM twice invokes a remote method that returns a proxy for the same JavaSpaces(TM) server, the references returned by that method should be the same. This allows == 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);
  }
 

Author:
Sun Microsystems, Inc.

Nested Class Summary
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 Summary
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.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WeakTable

public WeakTable()
Create a new WeakTable object to maintain the maps.


WeakTable

public WeakTable(WeakTable.KeyGCHandler handler)
Create a new WeakTable object to maintain the maps that calls back the designated object when keys are collected.

Method Detail

getOrAdd

public Object getOrAdd(Object key,
                       Object proxy)
Return the object that this key maps to. If it currently maps to no object, set it to map to the given object. Return either the existing entry or the new one, whichever is used.


get

public Object get(Object key)
Return the value associated with given key, or null if no value can be found.


remove

public Object remove(Object key)
Remove the object that the given key maps to. If found return the object, otherwise return null.


removeBlanks

public void removeBlanks()
Remove any blank entries from the table. This can be invoked by a reaping thread if you like.


GigaSpaces XAP 9.7.2 API

Copyright © GigaSpaces.