net.spy.factory
Class GenFactory

java.lang.Object
  extended by net.spy.SpyObject
      extended by net.spy.factory.GenFactory

public abstract class GenFactory
extends SpyObject

Generic object instance cache.


Constructor Summary
protected GenFactory(java.lang.String key, long time)
          Get an instance of GenFactory.
 
Method Summary
protected  CacheEntry getCache()
          Get the cache for this factory.
protected abstract  java.util.Collection getInstances()
          Get the collection of all Instance objects to be cached.
protected  CacheEntry getNewCacheEntry()
          Get a CacheEntry instance to be populated with a collection of Instance objects.
 java.lang.Object getObject(int id)
          Get an object by ID.
 java.util.Collection getObjects()
          Get all objects cached by this factory.
protected  java.lang.Object handleNullLookup(int id)
          This method is called whenever getObject would return null.
 void recache()
          Reset the cache for this factory.
 
Methods inherited from class net.spy.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenFactory

protected GenFactory(java.lang.String key,
                     long time)
Get an instance of GenFactory.

Parameters:
key - the cache key to use
time - the refresh duration of the cache
Method Detail

getCache

protected CacheEntry getCache()
Get the cache for this factory. If the cache does not exist, getNewCacheEntry() will be called to get an uninitialized CacheEntry instance, and getInstances() will be called to get a collection of instances to populate the cache.

Returns:
a CacheEntry

getNewCacheEntry

protected CacheEntry getNewCacheEntry()
Get a CacheEntry instance to be populated with a collection of Instance objects. The default implentation returns an instance of HashCacheEntry.

Returns:
an empty CacheEntry instance.

getInstances

protected abstract java.util.Collection getInstances()
Get the collection of all Instance objects to be cached.


handleNullLookup

protected java.lang.Object handleNullLookup(int id)
This method is called whenever getObject would return null. The result of this object will be used instead. Alternatively, one may throw a RuntimeException indicating a failure.

Parameters:
id - the ID of the object that was requested.
Returns:
null

getObject

public java.lang.Object getObject(int id)
Get an object by ID.

Parameters:
id - the object ID
Returns:
the object instance, or null if there's no such object

getObjects

public java.util.Collection getObjects()
Get all objects cached by this factory.


recache

public void recache()
Reset the cache for this factory.



Copyright © 1995-2005 SPY Internetworking. All Rights Reserved.