infinispan 9.4 - 监听器和事件过滤器

infinispan 9.4 - Listeners and event filter

我正在尝试在具有 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>

这是我的演示 class:

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;
    }
}

事件过滤器工厂:

@NamedFactory(name="entity-event-filter-factory")
public class EntityEventFilterFactory implements CacheEventFilterFactory {
    @Override
    public CacheEventFilter<String, EntityDemo> getFilter(Object[] params) {
        return new EntityEventFilter(params);
    }
}

事件过滤器:

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());
    }
}

我已经查看了序列化白名单,但我一无所获。

我尝试在内存配置中为二进制更改对象并禁用兼容性,但后来我得到一个新的异常:

[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

谁能帮我解决这个问题?

你试过这个吗?将 -Dinfinispan.deserialization.whitelist.classes 属性 传递给服务器。

http://infinispan.org/docs/stable/upgrading/upgrading.html#deserialization_whitelist