Ehcache(2.9.x) - API Developer Guide, Cache Manager Event Listeners
About CacheManager Event Listeners
CacheManager event listeners allow implementers to register callback methods that will be executed when a CacheManager event occurs. CacheManager listeners implement the CacheManagerEventListener interface. The events include:
- Adding a Cache
- Removing a Cache
Callbacks to these methods are synchronous and unsynchronized. It is the responsibility of the implementer to safely handle the potential performance and thread safety issues depending on what their listener is doing.
Configuring a Cache Manager Event Listener
One CacheManagerEventListenerFactory and hence one CacheManagerEventListener can be specified per CacheManager instance. The factory is configured as below:
<cacheManagerEventListenerFactory class="" properties=""/>
The entry specifies a CacheManagerEventListenerFactory which will be used to create a CacheManagerEventListener, which is notified when Caches are added or removed from the CacheManager. The attributes of a CacheManagerEventListenerFactory are:
- class — a fully qualified factory class name.
- properties — comma-separated properties having meaning only to the factory.
Callbacks to listener methods are synchronous and unsynchronized. It is the responsibility of the implementer to safely handle the potential performance and thread safety issues depending on what their listener is doing. If no class is specified, or there is no cacheManagerEventListenerFactory element, no listener is created. There is no default.
Implementing a CacheManager Event Listener Factory and CacheManager Event Listener
CacheManagerEventListenerFactory is an abstract factory for creating CacheManager listeners. Implementers should provide their own concrete factory extending this abstract factory. It can then be configured in ehcache.xml.
The factory class needs to be a concrete subclass of the abstract factory CacheManagerEventListenerFactory, which is reproduced below:
/**
* An abstract factory for creating {@link CacheManagerEventListener}s.
* Implementers should provide their own concrete factory extending this
* factory. It can then be configured in ehcache.xml.
*
*/
public abstract class CacheManagerEventListenerFactory {
/**
* Create a CacheManagerEventListener
*
* @param properties implementation specific properties.
* These are configured as comma-separated name value pairs in ehcache.xml.
* Properties may be null.
* @return a constructed CacheManagerEventListener
*/
public abstract CacheManagerEventListener createCacheManagerEventListener(Properties properties);
}
The factory creates a concrete implementation of CacheManagerEventListener, which is reproduced below:
/**
* Allows implementers to register callback methods that will be executed when a
* <code>CacheManager</code> event occurs.
*
* The lifecycle events are:
* <ol>
* <li>init
* <li>dispose
* </ol>
*
*
* CacheManager change events are:
* <ol>
* <li>adding a <code>Cache</code>
* <li>removing a <code>Cache</code>
* </ol>
*
* Note that the caches that are part of the initial configuration are not considered "changes".
* It is only caches added or removed beyond the initial config.
*
* Callbacks to these methods are synchronous and unsynchronized. It is the responsibility of
* the implementer to safely handle the potential performance and thread safety issues
* depending on what their listener is doing.
* @author Greg Luck
* @version $Id: CacheManagerEventListener.java 5594 2012-05-07 16:04:31Z cdennis $
* @since 1.2
* @see CacheEventListener
*/
public interface CacheManagerEventListener { /**
* Call to start the listeners and do any other required initialisation.
* init should also handle any work to do with the caches that are part of the initial configuration.
* @throws CacheException - all exceptions are wrapped in CacheException
*/
void init() throws CacheException; /**
* Returns the listener status.
* @return the status at the point in time the method is called
*/
Status getStatus(); /**
* Stop the listener and free any resources.
* @throws CacheException - all exceptions are wrapped in CacheException
*/
void dispose() throws CacheException; /**
* Called immediately after a cache has been added and activated.
* <p/>
* Note that the CacheManager calls this method from a synchronized method. Any attempt to
* call a synchronized method on CacheManager from this method will cause a deadlock.
* <p/>
* Note that activation will also cause a CacheEventListener status change notification
* from {@link net.sf.ehcache.Status#STATUS_UNINITIALISED} to
* {@link net.sf.ehcache.Status#STATUS_ALIVE}. Care should be taken on processing that
* notification because:
* <ul>
* <li>the cache will not yet be accessible from the CacheManager.
* <li>the addCaches methods which cause this notification are synchronized on the
* CacheManager. An attempt to call {@link net.sf.ehcache.CacheManager#getEhcache(String)}
* will cause a deadlock.
* </ul>
* The calling method will block until this method returns.
* <p/>
* @param cacheName the name of the <code>Cache</code> the operation relates to
* @see CacheEventListener
*/
void notifyCacheAdded(String cacheName); /**
* Called immediately after a cache has been disposed and removed. The calling method will
* block until this method returns.
* <p/>
* Note that the CacheManager calls this method from a synchronized method. Any attempt to
* call a synchronized method on CacheManager from this method will cause a deadlock.
* <p/>
* Note that a {@link CacheEventListener} status changed will also be triggered. Any
* attempt from that notification to access CacheManager will also result in a deadlock.
* @param cacheName the name of the <code>Cache</code> the operation relates to
*/
void notifyCacheRemoved(String cacheName); }
The implementations need to be placed in the classpath accessible to Ehcache. Ehcache uses the ClassLoader returned by Thread.currentThread().getContextClassLoader() to load classes.
Ehcache(2.9.x) - API Developer Guide, Cache Manager Event Listeners的更多相关文章
- Ehcache(2.9.x) - API Developer Guide, Cache Loaders
About Cache Loaders A CacheLoader is an interface that specifies load() and loadAll() methods with a ...
- Ehcache(2.9.x) - API Developer Guide, Cache Event Listeners
About Cache Event Listeners Cache listeners allow implementers to register callback methods that wil ...
- Ehcache(2.9.x) - API Developer Guide, Cache Exception Handlers
About Exception Handlers By default, most cache operations will propagate a runtime CacheException o ...
- Ehcache(2.9.x) - API Developer Guide, Cache Decorators
About Cache Decorators Ehcache uses the Ehcache interface, of which Cache is an implementation. It i ...
- Ehcache(2.9.x) - API Developer Guide, Cache Eviction Algorithms
About Cache Eviction Algorithms A cache eviction algorithm is a way of deciding which element to evi ...
- Ehcache(2.9.x) - API Developer Guide, Cache Usage Patterns
There are several common access patterns when using a cache. Ehcache supports the following patterns ...
- Ehcache(2.9.x) - API Developer Guide, Cache Extensions
About Cache Extensions Cache extensions are a general-purpose mechanism to allow generic extensions ...
- Ehcache(2.9.x) - API Developer Guide, Write-Through and Write-Behind Caches
About Write-Through and Write-Behind Caches Write-through caching is a caching pattern where writes ...
- Ehcache(2.9.x) - API Developer Guide, Basic Caching
Creating a CacheManager All usages of the Ehcache API start with the creation of a CacheManager. The ...
随机推荐
- exit和_exit的区别
参考 http://www.cnblogs.com/hnrainll/archive/2011/08/17/2142001.html p.p1 { margin: 0.0px 0.0px 0.0px ...
- linux下的shell命令的编写,以及java怎样调用linux的shell命令(java怎样获取linux上的网卡的ip信息)
程序猿都非常懒,你懂的! 近期在开发中,须要用到server的ip和mac信息.可是server是架设在linux系统上的,对于多网口,在获取ip时就产生了非常大的问题.以下是在windows系统上, ...
- 开始学习web前端技术
不能再蹉跎了,不能再徘徊了,不能再犹豫了,犹豫徘徊等于白来…… 感觉之前浪费了太多的岁月,必须得学习一门实用的技术来充实自己空虚的心情了. 想来想去网页应该是万金油的,大大小小多多少少都得用到.既然如 ...
- Ogre分层渲染 (转)
Ogre分层渲染 转载请注明出处!http://www.cnblogs.com/pulas 在超大的场景中,如果既想看到近处的物体,又想看到很远的物体,则必须把相机的远近裁剪面距离设得很大.远近裁剪面 ...
- IOS 手绘地图导航
手绘地图导航 第三方库 NAMapKit, 1)支持在手绘图上标记.缩放 2)支持在单张图片 3)支持瓦片小图片 思路 前提:美工已经切好手绘图,并告知我们当前的缩放级别. 1)确定好手绘图左上角点在 ...
- iOS修改声明为readonly的属性值
本文讨论的是,对于类中声明为 readonly 的属性值,我们就不可以修改其值了么?如何可以,那么如何修改呢? 为了便于说明,定义一个 ACLStudent 的类: ACLStudent.h @int ...
- iOS开发——语法篇OC篇&高级语法精讲二
Objective高级语法精讲二 Objective-C是基于C语言加入了面向对象特性和消息转发机制的动态语言,这意味着它不仅需要一个编译器,还需要Runtime系统来动态创建类和对象,进行消息发送和 ...
- 赵雅智_Fragment生命周期
官网帮助文档链接: http://developer.android.com/guide/components/fragments.html 主要看两张图.和跑代码 一,Fragment的生命周 w ...
- VRP相关知识整理
一.扩展问题分类: ★ the capacitated vehicle routing problem (CVRP) , 即classical VRP ★ the vehicle routing pr ...
- 进程间通信之XSI IPC
XSI IPC源自于系统V的IPC功能. 有三种IPC我们称作XSI IPC,即消息队列.信号量以及共享存储器,它们之间有很多相似之处. 1.标识符和键 每个内核中的IPC结构(消息队列.信号量或共享 ...