JBoss Community Archive (Read Only)

Infinispan 6.0

Infinispan Custom Interceptors

Introduction

It is possible to add custom interceptors to Infinispan, both declaratively and programatically. Custom interceptors are an way of extending Infinispan by being able to influence or respond to any modifications to cache. Example of such modifications are: elements are added/removed/updated or transactions are committed. For a detailed list refer to CommandInterceptor API.

Adding custom interceptors declaratively

Custom interceptors can be added on a per named cache basis. This is because each named cache have it's own interceptor stack. Following xml snippet depicts the ways in which an custom interceptor can be added.

   <namedCache name="cacheWithCustomInterceptors">
      <!--
      Define custom interceptors.  All custom interceptors need to extend org.jboss.cache.interceptors.base.CommandInterceptor
      -->
      <customInterceptors>
         <interceptor position="FIRST" class="com.mycompany.CustomInterceptor1">
            <properties>
               <property name="attributeOne" value="value1" />
               <property name="attributeTwo" value="value2" />
            </properties>
         </interceptor>
         <interceptor position="LAST" class="com.mycompany.CustomInterceptor2"/>
         <interceptor index="3" class="com.mycompany.CustomInterceptor1"/>
         <interceptor before="org.infinispanpan.interceptors.CallInterceptor" class="com.mycompany.CustomInterceptor2"/>
         <interceptor after="org.infinispanpan.interceptors.CallInterceptor" class="com.mycompany.CustomInterceptor1"/>
      </customInterceptors>
   </namedCache>
Adding custom interceptors programatically

In order to do that one needs to obtain a reference to the AdvancedCache. This can be done ass follows:

CacheManager cm = getCacheManager();//magic
Cache aCache = cm.getCache("aName");
AdvancedCache advCache = aCache.getAdvancedCache();
Then one of the addInterceptor() methods should be used to add the actual interceptor. For further documentation refer to AdvancedCache javadoc.

Custom interceptor design

  • Custom interceptors must extend BaseCustomInterceptor

  • Custom interceptors must declare a public, empty constructor to enable construction.

  • Custom  interceptors will have setters for any property defined through property tag.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-11 09:39:19 UTC, last content change 2012-09-21 08:50:48 UTC.