【问题标题】:infinispan 9.4 - Listeners and event filterinfinispan 9.4 - 监听器和事件过滤器
【发布时间】:2018-10-30 19:57:40
【问题描述】:

我正在尝试在具有 Infinispan 9.4.0 和 Hot Rod 客户端的两个实例的分布式缓存中使用带有过滤器的侦听器。当我尝试将新条目放入缓存时,出现以下异常:

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

事件过滤器:

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

我查看了关于序列化的白名单,但我什么也没找到。

我尝试在 binarymemory 配置中更改 object 并禁用 compatibility,但后来我得到了一个新的例外:

[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

谁能帮我解决这个问题?

【问题讨论】:

    标签: infinispan infinispan-9


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢!我昨天找到了该信息,但我没有更新我的问题。
    猜你喜欢
    • 2020-01-27
    • 2016-06-16
    • 2014-02-21
    • 2020-05-06
    • 2020-11-29
    • 2019-12-02
    • 1970-01-01
    • 2011-07-24
    • 2012-04-28
    相关资源
    最近更新 更多