要跨越Java端的语言边界,要序列化的类需要实现DataSerializable接口;为了让c#中的反序列化器知道它是什么类,我们需要注册一个classID。在这个例子之后,我用Java编写了我的类:
public class Stuff implements DataSerializable{
static { // note that classID (7) must match C#
Instantiator.register(new Instantiator(Stuff.class,(byte)0x07) {
@Override
public DataSerializable newInstance() {
return new Stuff();
}
});
}
private Stuff(){}
public boolean equals(Object obj) {...}
public int hashCode() {...}
public void toData(DataOutput dataOutput) throws IOException {...}
public void fromData(DataInput dataInput) throws IOException, ClassNotFoundException { ...}
}
它看起来不错,但是当我运行它时,我得到了这个例外:
[警告2012/03/30 15:06:00.239 JST tid = 0x1]注册时出错 池上的实例化器: com.gemstone.gemfire.cache.client.ServerOperationException ::: while 执行远程registerInstantiators at com.gemstone.gemfire.cache.client.internal.AbstractOp.processAck(AbstractOp.java:247) 在 com.gemstone.gemfire.cache.client.internal.RegisterInstantiatorsOp $ RegisterInstantiatorsOpImpl.processResponse(RegisterInstantiatorsOp.java:76) 在 com.gemstone.gemfire.cache.client.internal.AbstractOp.attemptReadResponse(AbstractOp.java:163) 在 com.gemstone.gemfire.cache.client.internal.AbstractOp.attempt(AbstractOp.java:363) 在 com.gemstone.gemfire.cache.client.internal.ConnectionImpl.execute(ConnectionImpl.java:229) 在 com.gemstone.gemfire.cache.client.internal.pooling.PooledConnection.execute(PooledConnection.java:321) 在 com.gemstone.gemfire.cache.client.internal.OpExecutorImpl.executeWithPossibleReAuthentication(OpExecutorImpl.java:646) 在 com.gemstone.gemfire.cache.client.internal.OpExecutorImpl.execute(OpExecutorImpl.java:108) 在 com.gemstone.gemfire.cache.client.internal.PoolImpl.execute(PoolImpl.java:624) 在 com.gemstone.gemfire.cache.client.internal.RegisterInstantiatorsOp.execute(RegisterInstantiatorsOp.java:39) 在 com.gemstone.gemfire.internal.cache.PoolManagerImpl.allPoolsRegisterInstantiator(PoolManagerImpl.java:216) 在 com.gemstone.gemfire.internal.InternalInstantiator.sendRegistrationMessageToServers(InternalInstantiator.java:188) 在 com.gemstone.gemfire.internal.InternalInstantiator._register(InternalInstantiator.java:143) 在 com.gemstone.gemfire.internal.InternalInstantiator.register(InternalInstantiator.java:71) 在com.gemstone.gemfire.Instantiator.register(Instantiator.java:168) 在Stuff。(Stuff.java)
引起:java.lang.ClassNotFoundException:Stuff $ 1
我无法弄清楚为什么,有经验的人可以提供帮助吗?提前谢谢!
答案 0 :(得分:1)
在大多数配置中,GemFire服务器需要反序列化对象以对其进行索引,运行查询和调用侦听器。因此,当您注册实例化器时,该类将在分布式系统中的所有计算机上注册。因此,类本身必须可用于加载集群中的任何位置。
异常堆栈跟踪表示错误发生在远程节点上。
检查参与群集的所有计算机上是否有类Stuff。至少在缓存服务器上。