net.spy.factory
Class GenFactory<T extends Instance>

java.lang.Object
  extended by net.spy.SpyObject
      extended by net.spy.factory.GenFactory<T>

public abstract class GenFactory<T extends Instance>
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<T> getCache()
          Get the cache for this factory.
protected abstract  java.util.Collection<T> getInstances()
          Get the collection of all Instance objects to be cached.
protected  CacheEntry<T> getNewCacheEntry()
          Get a CacheEntry instance to be populated with a collection of Instance objects.
 T getObject(int id)
          Get an object by ID.
 java.util.Collection<T> getObjects()
          Get all objects cached by this factory.
protected  T 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<T> 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<T> 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<T> getInstances()
Get the collection of all Instance objects to be cached.


handleNullLookup

protected T 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 T 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<T> getObjects()
Get all objects cached by this factory.


recache

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



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