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.
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.
Adding custom interceptors programatically
In order to do that one needs to obtain a reference to the AdvancedCache. This can be done ass follows:
Then one of the addInterceptor() methods should be used to add the actual interceptor. For further documentation refer to AdvancedCache javadoc.
- Custom interceptors must extend CommandInterceptor
- Custom interceptors must declare a public, empty constructor to enable construction.
- Custom interceptors will have setters for any property defined through property tag.