ApacheIgnite缓存和PeerClassLoading
1。是否可以将非POJO类实例作为缓存的值? 例如,我有一个QueryThread类,它是java.lang.Thread的子类,我试图将这个实例放在缓存中。看起来put操作失败,因为此缓存始终为空 考虑以下类别:ApacheIgnite缓存和PeerClassLoading,ignite,Ignite,1。是否可以将非POJO类实例作为缓存的值? 例如,我有一个QueryThread类,它是java.lang.Thread的子类,我试图将这个实例放在缓存中。看起来put操作失败,因为此缓存始终为空 考虑以下类别: public class QueryThread extends Thread { private IgniteCache<?, ?> cache; private String queryId; private String query; private long t
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);
}
}
}
接下来,我尝试使用Ignite可调用接口广播该类。但是我的类在构造函数中接受多个参数。如果类采用无参数构造函数,我觉得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;
}
});
IgniteCompute=ignite.compute(ignite.cluster().forserver());
compute.broadcast(新的IgniteCallable(){
@凌驾
public MyServiceImpl call()引发异常{
MyServiceImpl myService=新的MyServiceImpl();
返回myService;
}
});
2。对于具有多参数构造函数的类,如何进行PeerClassLoading?
关于第2点->第1点。我的PeerClassLoading方法正确吗(如示例所示)。如果我的构造函数有多个参数,还有其他方法可以执行PeerClassLoading吗?最好创建一个实现IgniteCallable的类,并将其作为参数应用于广播,因为Java在序列化2上除了匿名类之外,还总是使用一个外部类。正如我前面所说的,PeerClassLoading是关于类的,但是您需要发送其类的实例。您可以将类与任何构造函数一起使用,但是,除此之外,您还需要添加一个用于序列化的默认构造函数。我可以发送一个类而不是该类的实例吗?我怎么做?你能给我一些代码示例吗?或者在源代码中有一些示例代码可以参考吗?关于第#2->1点。我的PeerClassLoading方法正确吗(如示例所示)。如果我的构造函数有多个参数,还有其他方法可以执行PeerClassLoading吗?最好创建一个实现IgniteCallable的类,并将其作为参数应用于广播,因为Java在序列化2上除了匿名类之外,还总是使用一个外部类。正如我前面所说的,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;
}
});