org.norther.tammi.core.cache
Class DefaultCacheClient<K,V>

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.core.cache.DefaultCacheClient<K,V>
Type Parameters:
K - the type of keys maintained by the cache.
V - the type of cached values.
All Implemented Interfaces:
Serializable, EventListener, NotificationBroadcaster, NotificationEmitter, NotificationListener, Manageable, MBeanDelegate, Refreshable, CacheClient<K,V>
Direct Known Subclasses:
DefaultKeyCacheClient

public class DefaultCacheClient<K,V>
extends Adaptee
implements CacheClient<K,V>, NotificationListener

A default implementation of CacheClient.

Version:
$Id: DefaultCacheClient.java,v 1.13 2010-06-22 17:50:21 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Constructor Summary
DefaultCacheClient(Class<?>... clazz)
          Constructs a new client.
 
Method Summary
 void clearCached()
          Clears all cached entries without notifying.
 void expireCached(long timestamp)
          Expires all cached entries notifying them about expiration.
 void expireFraction(long timestamp, float fraction)
          Expires the specified fraction of cached entries notifying them about expiration.
 ConcurrentMap<K,V> getCache(boolean... create)
          Gets and optionally creates the cache.
 String getCachedDomain()
          Gets the cached domain.
 CachedMap<K,V> getClientCache(boolean... create)
          Gets the client cache.
 long getExpired()
          Gets the last expire timestamp.
 long getRefreshed()
          Gets the last refresh timestamp.
 SharedCache<K,V> getSharedCache()
          Gets the shared cache.
 ObjectName getSharedCacheName()
          Gets the the shared cache of this client.
 void handleNotification(Notification notif, Object handback)
          Handle domain cache removals.
 boolean isCachingDisabled()
          Checks whether the caching is disabled.
 void postmanaged()
          This method is called when the implementing adaptee has been managed either during post-registration of the corresponding adapter MBean or just after it is explicitly added to the adapter MBean during run-time.
 void refresh()
          Refreshes the MBean.
 void removeCache()
          Removes the cache.
 void setCachingDisabled(boolean flag)
          Sets the caching disabled flag.
 void setSharedCacheName(ObjectName cache)
          Sets the shared cache of this client.
 void unmanaged()
          This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultCacheClient

public DefaultCacheClient(Class<?>... clazz)
Constructs a new client.

Parameters:
clazz - an optional shared cache class.
Method Detail

postmanaged

public void postmanaged()
Description copied from interface: Manageable
This method is called when the implementing adaptee has been managed either during post-registration of the corresponding adapter MBean or just after it is explicitly added to the adapter MBean during run-time.

Specified by:
postmanaged in interface Manageable
Overrides:
postmanaged in class Adaptee

unmanaged

public void unmanaged()
               throws Exception
Description copied from interface: Manageable
This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.

Specified by:
unmanaged in interface Manageable
Overrides:
unmanaged in class Adaptee
Throws:
Exception - if the adaptee refused to be unmanaged.

isCachingDisabled

public boolean isCachingDisabled()
Description copied from interface: CacheClient
Checks whether the caching is disabled.

Specified by:
isCachingDisabled in interface CacheClient<K,V>
Returns:
true if the caching is disabled, true otherwise.

setCachingDisabled

public void setCachingDisabled(boolean flag)
Description copied from interface: CacheClient
Sets the caching disabled flag.

Specified by:
setCachingDisabled in interface CacheClient<K,V>
Parameters:
flag - the caching disabled flag.

expireCached

public void expireCached(long timestamp)
Description copied from interface: CacheClient
Expires all cached entries notifying them about expiration.

Specified by:
expireCached in interface CacheClient<K,V>
Parameters:
timestamp - the timestamp of the expiration.

expireFraction

public void expireFraction(long timestamp,
                           float fraction)
Description copied from interface: CacheClient
Expires the specified fraction of cached entries notifying them about expiration.

Specified by:
expireFraction in interface CacheClient<K,V>
Parameters:
timestamp - the timestamp of the expiration.
fraction - the fraction of entries to expire (0.0..1.0).

clearCached

public void clearCached()
Description copied from interface: CacheClient
Clears all cached entries without notifying.

Specified by:
clearCached in interface CacheClient<K,V>

getCache

public ConcurrentMap<K,V> getCache(boolean... create)
Description copied from interface: CacheClient
Gets and optionally creates the cache.

Specified by:
getCache in interface CacheClient<K,V>
Parameters:
create - true to create a missing cache.
Returns:
the cache or null if disabled.

removeCache

public void removeCache()
Description copied from interface: CacheClient
Removes the cache.

Specified by:
removeCache in interface CacheClient<K,V>

getSharedCacheName

public ObjectName getSharedCacheName()
Description copied from interface: CacheClient
Gets the the shared cache of this client.

Specified by:
getSharedCacheName in interface CacheClient<K,V>
Returns:
the object name of the shared cache or a query.

setSharedCacheName

public void setSharedCacheName(ObjectName cache)
Description copied from interface: CacheClient
Sets the shared cache of this client. If it is not set, the default one will be used.

Specified by:
setSharedCacheName in interface CacheClient<K,V>
Parameters:
cache - the object name of the shared cache or a query.

refresh

public void refresh()
Description copied from interface: Refreshable
Refreshes the MBean.

Specified by:
refresh in interface Refreshable

getRefreshed

public long getRefreshed()
Description copied from interface: Refreshable
Gets the last refresh timestamp.

Specified by:
getRefreshed in interface Refreshable
Returns:
the timestamp of the last refresh.

getExpired

public long getExpired()
Gets the last expire timestamp.

Returns:
the timestamp of the last expire.

handleNotification

public void handleNotification(Notification notif,
                               Object handback)
Handle domain cache removals.

Specified by:
handleNotification in interface NotificationListener
Parameters:
notif - the notification.
handback - not used.

getSharedCache

public SharedCache<K,V> getSharedCache()
Gets the shared cache.

Returns:
the shared cache.

getClientCache

public CachedMap<K,V> getClientCache(boolean... create)
Gets the client cache.

Parameters:
create - true to create a missing cache.
Returns:
the cache for the specified key or null.

getCachedDomain

public String getCachedDomain()
Gets the cached domain.

Returns:
the cached domain or null.


Copyright © 2004 The Norther Organization. All rights reserved.