murphytalk
murphytalk

Reputation: 1297

GemFire: serialize objects in Java and then deserialize them in c#

To cross the language boundary in Java side the class to be serialized needs to implement the DataSerializable interface; and in order to let the deserializer in c# know what class it is , we need to register a classID. Following the example, I write my class in Java like this:

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 { ...}
}

It looks OK but when I run it I get this exception:

[warning 2012/03/30 15:06:00.239 JST tid=0x1] Error registering instantiator on pool: com.gemstone.gemfire.cache.client.ServerOperationException: : While performing a remote registerInstantiators at com.gemstone.gemfire.cache.client.internal.AbstractOp.processAck(AbstractOp.java:247) at com.gemstone.gemfire.cache.client.internal.RegisterInstantiatorsOp$RegisterInstantiatorsOpImpl.processResponse(RegisterInstantiatorsOp.java:76) at com.gemstone.gemfire.cache.client.internal.AbstractOp.attemptReadResponse(AbstractOp.java:163) at com.gemstone.gemfire.cache.client.internal.AbstractOp.attempt(AbstractOp.java:363) at com.gemstone.gemfire.cache.client.internal.ConnectionImpl.execute(ConnectionImpl.java:229) at com.gemstone.gemfire.cache.client.internal.pooling.PooledConnection.execute(PooledConnection.java:321) at com.gemstone.gemfire.cache.client.internal.OpExecutorImpl.executeWithPossibleReAuthentication(OpExecutorImpl.java:646) at com.gemstone.gemfire.cache.client.internal.OpExecutorImpl.execute(OpExecutorImpl.java:108) at com.gemstone.gemfire.cache.client.internal.PoolImpl.execute(PoolImpl.java:624) at com.gemstone.gemfire.cache.client.internal.RegisterInstantiatorsOp.execute(RegisterInstantiatorsOp.java:39) at com.gemstone.gemfire.internal.cache.PoolManagerImpl.allPoolsRegisterInstantiator(PoolManagerImpl.java:216) at 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) at com.gemstone.gemfire.Instantiator.register(Instantiator.java:168) at Stuff.(Stuff.java)

Caused by: java.lang.ClassNotFoundException: Stuff$1

I could not figure out why, is there anyone who has experience can help? Thanks in advance!

Upvotes: 0

Views: 1991

Answers (1)

Alexey Kharlamov
Alexey Kharlamov

Reputation: 11

In most configurations GemFire servers need to deserialize objects in order to index them, run queries and call listeners. So when you register instantiator the class will be registered on all machines in the Distributed System. Hence, the class itself must be available for loading everywhere in the cluster.

As exception stack trace says the error happens on a remote node.

Check if you have the class Stuff on all machines participating in the cluster. At least on cache servers.

Upvotes: 1

Related Questions