WSO2 Carbon 4.4.x Kernel allows users to have 6 Cache entry listeners provided under the
javax.cache.event package. These Cache entry listeners are listed below.
These are the extension points provided in WSO2 carbon products for caching. These interfaces enable you to observe and take actions on the changes made to cache entries based on the relevant events. That is, if you need to perform some action when a cache entry is created, the
CacheEntryCreatedListener interface can be implemented.
Once you implement a listener, for it to actually listen to the relevant event, you need to register your implementation on the cache. All the event handlers in these listeners gets CacheEntryEvent<? extends K, ? extends V> cacheEntryEvent object. So you can actually get the key and the value of the cache entry that triggers the particular event.
The following sample illustrates how to provide your custom implementation for these listeners and register them so that you can actually listen to these events. These implementations need to be bundled as an OSGi bundle and deployed for your Carbon product.
The process of implementing and deploying cache listeners are explained in the following sections:
Implementing cache listeners
This section illustrates sample implementations for the aforementioned listener classes. A bundle activator class will register these listeners into the cache and create an OSGi bundle out of the classes. Since the implementation process for all these 6 listeners is similar, this section illustrates only the implementation of
Registering the listener
Once you implement the listener class, you need to register this listener in the cache. For this, let’s create a bundle activator class and register the listener as shown below.
Deploying the OSGi bundle
The following Maven plugin needs to be included in the
pom.xml of your project to create an OSGi bundle.
In addition to the aforementioned POM update, the packaging of your Maven project needs to be set to bundle (i.e:
<packaging>bundle</packaging>). You can implement the remaining 5 listeners in a similar manner and create OSGi bundles. After building the OSGi bundle, add it to the
<PRODUCT_HOME>/repository/components/dropins directory in your Carbon product.