1.3.3.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 1.1. Adding Custom Interceptors
Define Custom Interceptors
All custom interceptors must extend org.jboss.cache.interceptors.base.CommandInterceptor. Use the customInterceptors method to add custom interceptors to the cache:<namedCache name="cacheWithCustomInterceptors"> <customInterceptors>
<namedCache name="cacheWithCustomInterceptors"> <customInterceptors>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Define the Position of the New Custom Interceptor
Interceptors must have a defined position. Valid options are: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.
<namedCache name="cacheWithCustomInterceptors"> <customInterceptors> <interceptor position="FIRST" class="com.mycompany.CustomInterceptor1"><namedCache name="cacheWithCustomInterceptors"> <customInterceptors> <interceptor position="FIRST" class="com.mycompany.CustomInterceptor1">Copy to Clipboard Copied! Toggle word wrap Toggle overflow Define Interceptor Properties
Define specific interceptor properties.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Apply Other Custom Interceptors
In this example, the next custom interceptor is called CustomInterceptor2.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Define the
index,before, andafterAttributes.- The
indexidentifies the position of this interceptor in the chain, with 0 being the first position. This attribute is mutually exclusive withposition,before, andafter. - The
aftermethod places the new interceptor directly after the instance of the named interceptor specified via its fully qualified class name. This attribute is mutually exclusive withposition,before, andindex. - The
beforemethod places the new interceptor directly before the instance of the named interceptor specified via its fully qualified class name. This attribute is mutually exclusive withposition,after, andindex.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Note
This configuration is only valid for JBoss Data Grid's Library Mode.