0

为了跨越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: : 在 com.gemstone.gemfire.cache 执行远程 registerInstantiators 时。 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。在 com.gemstone.gemfire.cache.client.internal.pooling.PooledConnection.execute 执行(ConnectionImpl.java:229)(PooledConnection.java:第321章.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。在 Stuff.(Stuff.java) 的 com.gemstone.gemfire.Instantiator.register(Instantiator.java:168) 注册(InternalInstantiator.java:71)

引起:java.lang.ClassNotFoundException: Stuff$1

我不知道为什么,有没有经验的人可以提供帮助?提前致谢!

4

1 回答 1

1

在大多数配置中,GemFire 服务器需要反序列化对象以便索引它们、运行查询和调用侦听器。因此,当您注册实例化器时,该类将在分布式系统中的所有机器上注册。因此,类本身必须可用于在集群中的任何地方加载。

正如异常堆栈跟踪所说,错误发生在远程节点上。

检查参与集群的所有机器上是否有 Stuff 类。至少在缓存服务器上。

于 2012-04-03T10:16:02.533 回答