我正在尝试将Infinispan 9.4.0和Hot Rod Client的两个实例与分布式缓存中的过滤器一起使用侦听器。当我尝试将新条目放入缓存时,出现以下异常:
[Server:instance-one] 13:09:57,468 ERROR [stderr] (HotRod-ServerHandler-4-2) Exception in thread "HotRod-ServerHandler-4-2" org.infinispan.commons.CacheException: ISPN000936: Class 'com.cm.broadcaster.infinispan.entity.EntityDemo' blocked by deserialization white list. Adjust the configuration serialization white list regular expression to include this class.
这是缓存配置:
<distributed-cache name="entityCache" remote-timeout="3000" statistics-available="false">
<memory>
<object size="20" strategy="LRU" />
</memory>
<compatibility enabled="true"/>
<file-store path="entity-store" passivation="true"/>
<indexing index="NONE"/>
<state-transfer timeout="60000" chunk-size="1024"/>
</distributed-cache>
这是我的演示课程:
public class EntityDemo implements Serializable {
private static final long serialVersionUID = 1L;
private long id;
private String name;
private String value;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
EventFilterFactory:
@NamedFactory(name="entity-event-filter-factory")
public class EntityEventFilterFactory implements CacheEventFilterFactory {
@Override
public CacheEventFilter<String, EntityDemo> getFilter(Object[] params) {
return new EntityEventFilter(params);
}
}
EventFilter:
public class EntityEventFilter implements Serializable, CacheEventFilter<String, EntityDemo> {
private static final long serialVersionUID = 1L;
private final long filter;
public EntityEventFilter(Object[] params) {
this.filter = Long.valueOf(String.valueOf(params[0]));
}
@Override
public boolean accept(String key, EntityDemo oldValue, Metadata oldMetadata, EntityDemo newValue, Metadata newMetadata, EventType eventType) {
if (eventType.isCreate()) {
if (oldValue.getId() % filter == 0)
return true;
}
return false;
}
}
我的测试代码:
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.addServers("localhost:11222");
RemoteCacheManager rcm = new RemoteCacheManager(cb.build());
RemoteCache<String, EntityDemo> rc = rcm.<String,
EntityDemo>getCache("entityCache");
rc.addClientListener(new CustomListener(), new Object[]{"1"}, null);
EntityDemo e = new EntityDemo();
e.setId(1);
e.setName("Demo");
e.setValue("Demo");
rc.put("1", e);
听众:
@ClientListener(filterFactoryName="entity-event-filter-factory")
public class CustomListener {
@ClientCacheEntryCreated
public void entryCreated(ClientCacheEntryCreatedEvent<String> event) {
System.out.println("Entry created!");
System.out.println(event.getKey());
}
}
我已经查看了要序列化的白名单,但是什么也没发现。
我尝试更改 binary 的内存配置中的对象并禁用兼容性,但是随后我得到了一个新的例外:
[Server:instance-one] 13:56:42,131 ERROR [org.infinispan.interceptors.impl.InvocationContextInterceptor] (HotRod-ServerHandler-4-2) ISPN000136: Error executing command PutKeyValueCommand, writing keys [WrappedByteArray{bytes=[B0x01012903033E0131, hashCode=1999574342}]: java.lang.ClassCastException: java.lang.String cannot be cast to com.cm.broadcaster.infinispan.entity.EntityDemo
有人可以帮我吗?
答案 0 :(得分:2)
您尝试过吗?将-Dinfinispan.deserialization.whitelist.classes属性传递到服务器。
http://infinispan.org/docs/stable/upgrading/upgrading.html#deserialization_whitelist