|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jboss.shotoku.cache.CacheItem<K,T>
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 objects that will be stored in the cache.public class CacheItem<K,T>
Use this class if you want to store objects in a cache that
will be updated on a regular intervals of time, by a service daemon
thread. All data is held in one node of a org.jboss.cache.TreeCache.
Instances of this class can be obtained using the create(CacheItemDataSource)
and create(CacheItemDataSource, Fqn, String, long) methods, provided a
CacheItemDataSource.
If a key is requested for the first time, it is initialized with the
CacheItemDataSource.init(Object) method. Later, the
CacheItemDataSource.update(Object, Object) method
is called to (possibly) update the currently held value.
The cache item will be auto-registered in the service upon construction
--- so take care when constructing objects of this class. When you want to
remove all keys, from the TreeCache node, that are handled by this cache item,
simply call the unregister() method.
| Method Summary | ||
|---|---|---|
static
|
create(CacheItemDataSource<K,T> dataSource)
Creates and registeres a new cache item, with default parameter values (see create(CacheItemDataSource, Fqn, String, long)): the fqn will be auto-generated,
a default cache mbean name will be used, update will happen on each service thread
update and there will be no limit on the length of a key update. |
|
static
|
create(CacheItemDataSource<K,T> dataSource,
Fqn fqn,
java.lang.String mbeanName,
long interval)
Creates and registeres a new cache item. |
|
T |
get(K key)
Gets an object that is bound to the given key in the associated TreeCache node. |
|
Fqn |
getFqn()
|
|
int |
getId()
|
|
java.lang.String |
getInfo()
|
|
long |
getInterval()
|
|
ConcurrentSet<K> |
getKeysDuringUpdate()
|
|
java.util.concurrent.ConcurrentMap<K,java.lang.Throwable> |
getKeysExceptions()
|
|
java.util.concurrent.ConcurrentMap<K,java.lang.Long> |
getKeysUpdates()
|
|
java.lang.String |
getMbeanName()
|
|
java.lang.String |
getName()
|
|
void |
register()
Registers this cache item in the service. |
|
void |
reportUpdateOk(K key)
Reports that an update of a key ended wihtout any exceptions. |
|
void |
reportUpdateWithException(K key,
java.lang.Throwable t)
Reports that an update of a key ended with an exception. |
|
void |
resetKey(java.lang.Object key)
Resets the given key, that is, it's update status. |
|
void |
setInterval(long interval)
|
|
void |
unregister()
Removes all keys handled by this cache item from the associated TreeCache node and stops updates on this cache item. |
|
void |
update()
Called by the service update thread to update all keys and associated values. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static <K,T> CacheItemUser<K,T> create(CacheItemDataSource<K,T> dataSource)
create(CacheItemDataSource, Fqn, String, long)): the fqn will be auto-generated,
a default cache mbean name will be used, update will happen on each service thread
update and there will be no limit on the length of a key update.
dataSource - Data source from which the resulting cache item will read.
public static <K,T> CacheItemUser<K,T> create(CacheItemDataSource<K,T> dataSource,
Fqn fqn,
java.lang.String mbeanName,
long interval)
dataSource - Data source from which the resulting cache item will read.fqn - An fqn of the node in TreeCache, where data should be held. If it is null,
a unique fqn will be auto-generated for this cache item.mbeanName - A name of an RenewableCacheServiceMBean mbean, which
should be used to perform cache operations. This mbeans holds a reference
to a org.jboss.cache.TreeCache. If it is null, a default mbean
name will be used.interval - Interval at which the update operation will be executed.
Effectively, the interval will be rounded to the nearest multiplicity of
the service update thread interval. The interval should be given in milliseconds.
If it is 0, the update() method will be executed on every service
thread update.public void register()
CacheItemUsercreate(CacheItemDataSource)),
so you will only need to use it if you previously
manually unregistered the cache item using CacheItemUser.unregister().
register in interface CacheItemUser<K,T>public void unregister()
CacheItemUser
unregister in interface CacheItemUser<K,T>public Fqn getFqn()
getFqn in interface CacheItemUser<K,T>public long getInterval()
getInterval in interface CacheItemUser<K,T>CacheItemDataSource.update(Object, Object) method will
be executed on every service thread update (for every key).public void setInterval(long interval)
setInterval in interface CacheItemUser<K,T>interval - Interval at which the update operation will be executed.
Effectively, the interval will be rounded to the nearest multiplicity of
the service update thread interval. The interval should be given in milliseconds.
If it is 0, the CacheItemDataSource.update(Object, Object) method will
be executed on every service thread update (for every key).public java.lang.String getMbeanName()
getMbeanName in interface CacheItemUser<K,T>RenewableCacheServiceMBean interface, associated
with this cache item.public ConcurrentSet<K> getKeysDuringUpdate()
getKeysDuringUpdate in interface CacheItemUser<K,T>public java.util.concurrent.ConcurrentMap<K,java.lang.Long> getKeysUpdates()
getKeysUpdates in interface CacheItemUser<K,T>public java.util.concurrent.ConcurrentMap<K,java.lang.Throwable> getKeysExceptions()
getKeysExceptions in interface CacheItemUser<K,T>public int getId()
getId in interface CacheItemUser<K,T>public java.lang.String getInfo()
getInfo in interface CacheItemUser<K,T>CacheItemDataSource.getInfo().public java.lang.String getName()
getName in interface CacheItemUser<K,T>CacheItem --- the fully qualified name of the class
implementing CacheItemDataSource.public final T get(K key)
CacheItemUserCacheItemDataSource.init(Object) method of a data source
that was passed to create(CacheItemDataSource)).
get in interface CacheItemUser<K,T>key - Key of the object to get.
public void update()
CacheItemOperations
update in interface CacheItemOperations<K,T>public void resetKey(java.lang.Object key)
CacheItemUser
resetKey in interface CacheItemUser<K,T>key - Key, which update status should be reset.public void reportUpdateOk(K key)
CacheItemOperations
reportUpdateOk in interface CacheItemOperations<K,T>key - Key which has been updated.
public void reportUpdateWithException(K key,
java.lang.Throwable t)
CacheItemOperations
reportUpdateWithException in interface CacheItemOperations<K,T>key - Key which has been updated.t - Exception which was thrown during the update.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||