37.2. Adding Custom Interceptors Declaratively
Each named cache in Red Hat JBoss Data Grid has its own interceptor stack. As a result, custom interceptors can be added on a per named cache basis.
A custom interceptor can be added using XML. Use the following procedure to add custom interceptors.
Procedure 37.1. Adding Custom Interceptors
<local-cache name="cacheWithCustomInterceptors"> <custom-interceptors> <interceptor position="FIRST" class="com.mycompany.CustomInterceptor1"> <property name="attributeOne" value="value1" /> <property name="attributeTwo" value="value2" /> </interceptor> <interceptor position="LAST" class="com.mycompany.CustomInterceptor2"/> <interceptor index="3" class="com.mycompany.CustomInterceptor1"/> <interceptor before="org.infinispan.interceptors.CallInterceptor" class="com.mycompany.CustomInterceptor2"/> <interceptor after="org.infinispan.interceptors.CallInterceptor" class="com.mycompany.CustomInterceptor1"/> </customInterceptors> </local-cache>
Define Custom Interceptors
All custom interceptors must extendorg.infinispan.interceptors.base.BaseCustomInterceptor
.Define the Position of the New Custom Interceptor
Interceptors must have a defined position. These options are mutually exclusive, meaning an interceptor cannot have both a position attribute and index attribute. Valid options are:via Position Attribute
FIRST
- Specifies that the new interceptor is placed first in the chain.LAST
- Specifies that the new interceptor is placed last in the chain.OTHER_THAN_FIRST_OR_LAST
- Specifies that the new interceptor can be placed anywhere except first or last in the chain.
via Index Attribute
- The
index
identifies the position of this interceptor in the chain. This index begins at 0, being the first position in the chain, and goes up to a number of interceptors in a given configuration.
via Before or After Attributes
- The
after
attributes places the new interceptor directly after the instance of the named interceptor, specified via its fully qualified class name. - The
before
attribute places the new interceptor directly before the instance of the named interceptor, specified via its fully qualified class name.
Define Interceptor Properties
Define specific interceptor properties.
Apply Other Custom Interceptors
In this example, the next custom interceptor is called CustomInterceptor2.
Note
Custom interceptors with the position
OTHER_THAN_FIRST_OR_LAST
may cause the CacheManager to fail.
Note
This configuration is only valid for JBoss Data Grid's Library Mode.