java - Apache Ignte:如何在 XML 缓存配置中定义 CacheInterceptors
问题描述
我在 XML 中定义了一个缓存配置,如下所示:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<!--
Alter configuration below as needed.
-->
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<!-- test configuration -->
<property name="cacheConfiguration">
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="TestCache" />
<property name="cacheMode" value="LOCAL" />
</bean>
</property>
</bean>
</beans>
此外,我实现了一个 CacheInterceptor:
package com.avl.drive.dataservice.setup.test;
import javax.cache.Cache.Entry;
import org.apache.ignite.cache.CacheInterceptor;
import org.apache.ignite.lang.IgniteBiTuple;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
public class TestCacheInterceptor<K, V> implements CacheInterceptor<K, V> {
private static final long serialVersionUID = 8568641462030568760L;
private static Logger logger = LogManager.getLogger("ConsoleLogger");
@Override
public V onGet(K key, V val) {
logger.debug("TestCacheInterceptor onGet");
return null;
}
@Override
public V onBeforePut(Entry<K, V> entry, V newVal) {
logger.debug("TestCacheInterceptor onBeforePut");
return null;
}
@Override
public void onAfterPut(Entry<K, V> entry) {
logger.debug("TestCacheInterceptor onAfterPut");
}
@Override
public @Nullable IgniteBiTuple<Boolean, V> onBeforeRemove(Entry<K, V> entry) {
logger.debug("TestCacheInterceptor onBeforeRemove");
return null;
}
@Override
public void onAfterRemove(Entry<K, V> entry) {
logger.debug("TestCacheInterceptor onAfterRemove");
}
}
在 Ignite 文档中,我只找到了使用 Java 配置添加拦截器的示例。
如何在 XML 缓存配置中添加此 CacheInterceptor?
解决方案
找到了解决方案...
CacheConfiguration 必须如下所示:
<!-- test configuration -->
<property name="cacheConfiguration">
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="TestCache" />
<property name="cacheMode" value="LOCAL" />
<property name="interceptor">
<bean class="com.avl.drive.dataservice.setup.test.TestCacheInterceptor" />
</property>
</bean>
</property>
推荐阅读
- java - 无法使用 Java Jira Rest Client 更新 jira 中问题的单选字段
- amazon-web-services - K8s cronjob 一天没有正确安排好几次
- javascript - 删除特定对象后,从数组中的对象中设置新序列
- php - 身份验证页面没有在 laravel 中获取 css
- python-3.x - 迭代时更新 pandas 中的数据框
- symfony - 多文件上传约束
- visual-studio-extensions - 从 Visual Studio 访问时,Visual Studio 私有库 atom.xml 会引发错误
- html - 编辑 sass 文件不会更新我的 index.html 页面
- r - 收集三个不同变量的 3 个不同检测
- php - PHP 扩展在内存中可用多长时间?