此内容没有您所选择的语言版本。

5.5. Custom Listeners for Remote Cache


Custom listeners for a remote cache can be registered in the same way as an embedded cache, with the exception that sync=false must be present. For instance:
Using only Java

from(infinispan://?cacheContainer=#cacheManager&sync=false&customListener=#myCustomListener")
  .to(mock:result);
Copy to Clipboard Toggle word wrap

Using Blueprint and Java

Java class:

public class RemoteCacheManagerFactory {      
    ConfigurationBuilder clientBuilder;
    public RemoteCacheManagerFactory(String hostname, int port) {
        clientBuilder = new ConfigurationBuilder();
        clientBuilder.addServer()
            .host(hostname).port(port);
    }
    public RemoteCacheManager newRemoteCacheManager() {
        return new RemoteCacheManager(clientBuilder.build());
    }
}
Copy to Clipboard Toggle word wrap
blueprint.xml:
<bean id=”remoteCacheManagerFactory” class=“com.jboss.datagrid.RemoteCacheManagerFactory”>  
    <argument value=”localhost”/>      
    <argument value="11222”/>      
</bean>
 
<bean id=”cacheManager”
    factory-ref=”remoteCacheManagerFactory” 
    factory-method=“newRemoteCacheManager”>   
</bean>

<bean id="myCustomListener" class="org.example.com.CustomListener"/>

<camelContext id="route" xmlns="http://camel.apache.org/schema/blueprint">
    <route>
        <from uri="infinispan://?cacheContainer=#cacheManager&sync=false&customListener=#myCustomListener"/>
        <to uri="mock:result"/>
    </route>
</camelContext>
Copy to Clipboard Toggle word wrap

The instance of myCustomListener must exist. Users are encouraged to extend the org.apache.camel.component.infinispan.remote.InfinispanRemoteCustomListener class and annotate the resulting class with @ClientListener; this annotation is found in org.infinispan.client.hotrod.annotation.
Remote listeners may also be associated with custom filters and converters as shown below:
@ClientListener(includeCurrentState=true, filterFactoryName = "static-filter-factory", converterFactoryName = "static-converter-factory")
  private static class MyCustomListener extends InfinispanRemoteCustomListener {
}
Copy to Clipboard Toggle word wrap
In order to use custom filters or converters classes annotated with @NamedFactory must be implemented. A skeleton that implements the necessary methods is shown below:
import org.infinispan.notifications.cachelistener.filter;

@NamedFactory(name = "static-converter-factory")
public static class StaticConverterFactory implements CacheEventConverterFactory {
  @Override
  public CacheEventConverter<Integer, String, CustomEvent> getConverter(Object[] params) {
    ...
  }

  static class StaticConverter implements CacheEventConverter<Integer, String, CustomEvent>, Serializable {
    @Override
    public CustomEvent convert(Integer key, String previousValue, Metadata previousMetadata, 
                               String value, Metadata metadata, EventType eventType) {
      ...
    }
  }
}
   
@NamedFactory(name = "static-filter-factory")
public static class StaticCacheEventFilterFactory implements CacheEventFilterFactory {
  @Override
  public CacheEventFilter<Integer, String> getFilter(final Object[] params) {
    ...
  }

  static class StaticCacheEventFilter implements CacheEventFilter<Integer, String>, Serializable {
    @Override
    public boolean accept(Integer key, String previousValue, Metadata previousMetadata, 
                          String value, Metadata metadata, EventType eventType) {
      ...
    }
  }
}
Copy to Clipboard Toggle word wrap
Custom filters and converters must be registered with the server. Registering these classes is documented in the Remote Event Listeners section of the Red Hat JBoss Data Grid Developer Guide.

Note

In order to listen for remote HotRod events the cacheManager must be of type RemoteCacheManager and instantiated.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat