嗯..在某些情况下,我有一个需要在hazelcast实例上进行操作的Object。所以我实现了HazelcastInstanceAware接口,但这似乎不适用于嵌套类......
以下核心向控制台输出“null”:
public class 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只能应用于根对象..任何想法?这是一个Bug吗?
答案 0 :(得分:0)
HazelcastInstanceAware仅适用于要反序列化的根对象。我们不会查看实现此接口的实例的对象图。