嗯..在某些情况下,我有一个需要在hazelcast实例上执行操作的对象。所以我实现了HazelcastInstanceAware接口,但这似乎不适用于嵌套类...
以下核心输出到控制台“ null”:
公共类NullError实现了Serializable,HazelcastInstanceAware {
私有瞬态HazelcastInstance instance1;
私有瞬态HazelcastInstance instance2;
public static void main(String[] args) throws Exception {
//new NullError().test();
new NullError().lala();
}
private void lala() throws Exception {
instance1 = Hazelcast.newHazelcastInstance();
instance2 = Hazelcast.newHazelcastInstance();
IMap<Object, Object> foo = instance1.getMap("foo");
foo.put("foo", new Foo(instance1));
((Callable) instance2.getMap("foo").get("foo")).call();
}
public static class Foo implements Serializable, Callable {
public Bar bar;
public Foo(HazelcastInstance instance) {
bar = new Bar(instance);
}
@Override
public Object call() throws Exception {
return bar.call();
}
}
public static class Bar implements Callable, Serializable, HazelcastInstanceAware {
private transient HazelcastInstance i;
public Bar(HazelcastInstance instance) {
this.i = instance;
}
@Override
public void setHazelcastInstance(HazelcastInstance instance) {
this.i = instance;
}
@Override
public Object call() throws Exception {
System.out.println(i);
return null;
}
}
}
该文档没有提到HazelcastInstanceAware仅适用于根对象..有什么想法吗?这是错误吗?
最佳答案
HazelcastInstanceAware仅适用于要反序列化的根对象。我们不研究实现此接口的实例的对象图。