org.sandev.basics.util
Class NamedSingletonIDCache

java.lang.Object
  extended by org.sandev.basics.util.IDCacheBase
      extended by org.sandev.basics.util.NamedSingletonIDCache
All Implemented Interfaces:
IDCache

public class NamedSingletonIDCache
extends IDCacheBase
implements IDCache

Provides singleton instances of one or more IDCaches. Instances are accessed by unique key. Using multiple caches allows multi-server deployments to run in a single VM without compromising the boundaries between server-specific or node-specific caches.

WARNING: Nodes sharing access to the same IDCache must have the same security and authorization to avoid retrieving more or less information than what should be there.

To share the same cache across multiple nodes with different authorization, write a "privileged" node to hold the cache, and then have all the client nodes get their info served from the privileged node via Authorizers.


Field Summary
protected static java.util.Hashtable caches
          Map of cache instances
 
Fields inherited from class org.sandev.basics.util.IDCacheBase
callback, map, revisionCheck, timeToLiveMillis
 
Constructor Summary
protected NamedSingletonIDCache()
          no access, default ctor.
 
Method Summary
static IDCache getSingletonIDCache(java.lang.String key)
          return the correct singleton cache
protected static IDCache instantiateCache(java.lang.String key)
          Instantiate a cache.
 
Methods inherited from class org.sandev.basics.util.IDCacheBase
checkRevisionNumber, cleanup, clear, find, getCallback, getInstance, getMap, getSortedItems, getStats, getTimeToLiveMillis, idToKey, init, putInstance, removeInstance, setCallback, setRevisionCheck, setTimeToLiveMillis
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.sandev.basics.util.IDCache
cleanup, clear, find, getCallback, getInstance, getMap, getStats, getTimeToLiveMillis, putInstance, removeInstance, setCallback, setTimeToLiveMillis
 

Field Detail

caches

protected static java.util.Hashtable caches
Map of cache instances

Constructor Detail

NamedSingletonIDCache

protected NamedSingletonIDCache()
no access, default ctor. Does nothing.

Method Detail

getSingletonIDCache

public static IDCache getSingletonIDCache(java.lang.String key)
return the correct singleton cache


instantiateCache

protected static IDCache instantiateCache(java.lang.String key)
Instantiate a cache. Make sure we only do this once. It is possible to have several threads try and instantiate the singleton at once. For a cache, it's important to prevent that from happening so you don't throw away a retrieved instance by accident.

Because of the thread lineup, the initial conditional test is actually necessary.