我有一个使用自定义CacheStore实现的客户端/服务器测试。我希望服务器节点上的自定义CacheStore而不是客户端节点上的自定义CacheStore,但Ignite正在尝试在客户端上加载自定义实现。有没有办法避免这种情况?
服务器代码:
IgniteConfiguration igniteCfg = new IgniteConfiguration();
Ignite ignite = Ignition.start(igniteCfg);
CacheConfiguration<String, String> cacheCfg = new CacheConfiguration<>("test");
cacheCfg.setReadThrough(true);
cacheCfg.setCacheStoreFactory(new CacheStoreFactory());
IgniteCache<String, String> cache = ignite.getOrCreateCache(cacheCfg);
CacheStore:
public class CacheStoreFactory implements Factory<CacheStore<? super String, ? super String>> {
@Override
public CacheStore<? super String, ? super String> create() {
return new CacheStoreAdapter<String, String>() {
@Override
public String load(String key) throws CacheLoaderException {
System.out.println("load: key=" + key);
return key;
}
@Override
public void write(Entry<? extends String, ? extends String> entry) throws CacheWriterException {
}
@Override
public void delete(Object key) throws CacheWriterException {
}
};
}
}
客户端:
IgniteConfiguration igniteCfg = new IgniteConfiguration();
igniteCfg.setClientMode(true);
Ignite ignite = Ignition.start(igniteCfg);
CacheConfiguration<String, String> cacheCfg = new CacheConfiguration<>("test");
IgniteCache<String, String> cache = ignite.getOrCreateCache(cacheCfg);
String value = cache.get("someKey");
在服务器上正确调用CacheStore,客户端似乎正常工作,但客户端记录此错误:
Caused by: java.lang.ClassNotFoundException: org.dalsing.ignite.server.test.CacheStoreFactory
答案 0 :(得分:0)
TRANSACTIONAL
缓存需要客户端上的缓存存储。对于ATOMIC
缓存(这是默认模式),不需要它,因此您可以安全地忽略该异常。