Apache Ignite 缓存和 PeerClassLoading

Apache Ignite Caching and PeerClassLoading

1.是否可以将非 POJO class 实例作为缓存的值?

例如,我有一个 QueryThread class,它是 java.lang.Thread 的子 class,我正试图将此实例放入缓存中。看起来 put 操作失败了,因为这个缓存总是空的。

考虑以下 class:

public class QueryThread extends Thread {

private IgniteCache<?, ?> cache;
private String queryId;
private String query;
private long timeIntervalinMillis;
private volatile boolean running = false;

public QueryThread(IgniteCache<?, ?> dataCache, String queryId, String query, long timeIntervalinMillis) {
    this.queryId = queryId;
    this.cache = dataCache;
    this.query = query;
    this.timeIntervalinMillis = timeIntervalinMillis;
}

public void exec() throws Throwable {
    SqlFieldsQuery qry = new SqlFieldsQuery(query, false);
    while (running) {
        List<List<?>> queryResult = cache.query(qry).getAll();
        for (List<?> list : queryResult) {
            System.out.println("result : "+list);
        }
        System.out.println("..... ");
        Thread.sleep(timeIntervalinMillis);
    }
}
}

此 class 不是 POJO。如何在缓存中存储此 class 的实例? 我尝试实施 Serializable(没有帮助)。 我需要能够做到这一点:

queryCache.put(queryId, queryThread);

接下来我尝试使用 IgniteCallable 接口广播 class。但是我的 class 在构造函数中接受了多个参数。如果 class 采用无参数构造函数,我觉得 PeerClassLoading 很容易:

 IgniteCompute compute = ignite.compute(ignite.cluster().forServers());
     compute.broadcast(new IgniteCallable<MyServiceImpl>() {

        @Override
        public MyServiceImpl call() throws Exception {
            MyServiceImpl myService = new MyServiceImpl();
            return myService;
        }

    });

2。在具有多参数构造函数的 class 的情况下如何执行 PeerClassLoading?

  1. 限制将Thread实例放入缓存,Thread实例调用Native Methods无法序列化。这就是为什么你总是得到空值。

  2. PeerClassLoading 是 Ignite 中一个特殊的分布式类加载器,用于节点间字节码交换。所以,它只是关于在节点之间共享 classes。构造函数 class 中有多少参数没有意义。 但是,另一方面,您创建的对象将被序列化并发送到其他节点,并且对于反序列化,它将需要一个默认(非参数)构造函数。