org.jboss.shotoku.cache
Class ShotokuCacheItem<K,T>

java.lang.Object
  extended by org.jboss.shotoku.cache.ShotokuCacheItem<K,T>
Type Parameters:
K - Type of the key of the objects held in cache. The keys should bahave well as map keys (most probably, the hashCode() and equals() methods should be overriden).
T - Type of the object that will be stored in the cache.
Direct Known Subclasses:
ShotokuResourceWatcher

public abstract class ShotokuCacheItem<K,T>
extends java.lang.Object

Extend this class if you want to store objects in the cache that will be updated on every Shotoku service timer timeout. The cache item will be auto-registered in the service upon construction - so take care when constructing objects of this class.

Author:
Adam Warski (adamw@aster.pl)

Constructor Summary
ShotokuCacheItem()
           
ShotokuCacheItem(long interval)
           
 
Method Summary
 T get(K key)
          Gets an object that is bound to the given key in the cache.
protected  ContentManager getContentManager(K key)
          Use this to bind a content manager with a key.
abstract  T init(K key)
          Called when the user demanded an object which hasn't been accessed before, and thus, which hasn't been yet initialized.
protected  ContentManager initContentManager(K key)
          Called when getContentManager(key) is called for the first time.
 void put(K key, T object)
          Binds the given key with the given object in the cache.
 void remove()
          Removes all keys handled by this ShotokuCacheItem from the cache.
 void update()
          Called by the Shotoku service.
abstract  void update(K key, T currentObject)
          Called by the service periodically to update the object held.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShotokuCacheItem

public ShotokuCacheItem(long interval)
Parameters:
interval - Interval at which the update operation will be executed. Effectively, the interval will be rounded to the nearest multiplicity of the service timer interval. The interval should be given in milliseconds.

ShotokuCacheItem

public ShotokuCacheItem()
Method Detail

put

public final void put(K key,
                      T object)
               throws CacheException
Binds the given key with the given object in the cache. The real key to which the object will be bound is: keyBase/key.

Parameters:
key - Key of the object.
object - Object that should be bound.
Throws:
CacheException

get

public final T get(K key)
Gets an object that is bound to the given key in the cache. If this object is not in the cache, it will be initialized.

Parameters:
key - Key of the object to get.
Returns:
Value of the object.

remove

public final void remove()
Removes all keys handled by this ShotokuCacheItem from the cache.


update

public final void update()
Called by the Shotoku service. You shouldn't call it from inside your program.


update

public abstract void update(K key,
                            T currentObject)
Called by the service periodically to update the object held. If the object in the cache should be changed, the implementing method must call put(key, newObject).

Parameters:
key - Key of the object to update.
currentObject - Current value held in the cache.

init

public abstract T init(K key)
Called when the user demanded an object which hasn't been accessed before, and thus, which hasn't been yet initialized. Here, put(key, initialObject) should not be called, as the returned object is automatically placed in the cache.

Parameters:
key - Key of the object to initialize.
Returns:
Initial value of an object with the given key.

getContentManager

protected final ContentManager getContentManager(K key)
Use this to bind a content manager with a key. There will always be at most one content manager for each key. On first call for a given key, initContentManager(key) will be called.

Parameters:
key - Key for which to get the content manager.
Returns:
Content manager bound with the given key.

initContentManager

protected ContentManager initContentManager(K key)
Called when getContentManager(key) is called for the first time. By default returns the default content manager with no prefix.

Parameters:
key - Key for which the content manager should be initialized.
Returns:
Default content manager with no prefix.


Copyright © -2006 . All Rights Reserved.