要在Java端跨越語言邊界,要序列化的類需要實現DataSerializable接口;爲了讓c#中的反序列化器知道它是什麼類,我們需要註冊一個classID。下面的例子中,我寫我的Java類是這樣的:GemFire:在Java中序列化對象,然後在c#中反序列化它們#
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.client.internal.AbstractOp.processAck執行遠程registerInstantiators (AbstractOp.java:247) at com.gemstone.g emfire.cache.client.internal.RegisterInstantiatorsOp $ RegisterInstantiatorsOpImpl.processResponse(RegisterInstantiatorsOp.java:76) 在 com.gemstone.gemfire.cache.client.internal.AbstractOp.attemptReadResponse(AbstractOp.java:163) 在 融爲一體。 gemstone.gemfire.cache.client.internal.AbstractOp.attempt(AbstractOp.java:363) 在 com.gemstone.gemfire.cache.client.internal.ConnectionImpl.execute(ConnectionImpl.java:229) 在 融爲一體。 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) at com.gemstone.gemfire.internal.InternalInstantiator._register(InternalInstantiator.java:143) at com.gemstone.gemfire.internal.InternalInstantiator.register(InternalInstantiator.java:71) 在com.gemstone.gemfire.Instantiator.register(Instantiator.java:168) 在東西。(Stuff.java)
導致:java.lang.ClassNotFoundException:東西$ 1
我想不通爲什麼,有沒有人有經驗可以幫助?提前致謝!
您能否提供更多或完整的代碼示例。 – Avinash 2013-09-06 11:57:24