I am using 3.5 version of hazelcast with kryoserializer. When I start first server then hazelcast started successfully but when I start second server which is in cluster with it then it is throwing below error :
2015-08-04 13:02:56 Aug 04, 2015 1:02:56 PM com.hazelcast.spi.impl.operationexecutor.classic.ClassicOperationExecutor
2015-08-04 13:02:56 SEVERE: [192.168.1.67]:5701 [dev] [3.5] Failed to process packet: Packet{header=17, isResponse=false, isOperation=true, isEvent=false, partitionId=-1, conn=Connection [/
192.168.1.67:5701 -> /
192.168.1.75:55784], endpoint=Address[192.168.1.75]:5701, live=true, type=MEMBER} on hz._hzInstance_1_dev.generic-operation.thread-1
2015-08-04 13:02:56 com.hazelcast.nio.serialization.HazelcastSerializationException: java.io.EOFException: Cannot read 4 bytes!
2015-08-04 13:02:56 at com.hazelcast.nio.serialization.SerializationServiceImpl.handleException(SerializationServiceImpl.java:380)
2015-08-04 13:02:56 at com.hazelcast.nio.serialization.SerializationServiceImpl.toObject(SerializationServiceImpl.java:282)
2015-08-04 13:02:56 at com.hazelcast.spi.impl.NodeEngineImpl.toObject(NodeEngineImpl.java:200)
2015-08-04 13:02:56 at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:294)
2015-08-04 13:02:56 at com.hazelcast.spi.impl.operationexecutor.classic.OperationThread.processPacket(OperationThread.java:142)
2015-08-04 13:02:56 at com.hazelcast.spi.impl.operationexecutor.classic.OperationThread.process(OperationThread.java:115)
2015-08-04 13:02:56 at com.hazelcast.spi.impl.operationexecutor.classic.OperationThread.doRun(OperationThread.java:101)
2015-08-04 13:02:56 at com.hazelcast.spi.impl.operationexecutor.classic.OperationThread.run(OperationThread.java:76)
2015-08-04 13:02:56 Caused by: java.io.EOFException: Cannot read 4 bytes!
2015-08-04 13:02:56 at com.hazelcast.nio.serialization.ByteArrayObjectDataInput.checkAvailable(ByteArrayObjectDataInput.java:543)
2015-08-04 13:02:56 at com.hazelcast.nio.serialization.ByteArrayObjectDataInput.readInt(ByteArrayObjectDataInput.java:255)
2015-08-04 13:02:56 at com.hazelcast.nio.serialization.ByteArrayObjectDataInput.readInt(ByteArrayObjectDataInput.java:249)
2015-08-04 13:02:56 at com.hazelcast.cluster.impl.ConfigCheck.readData(ConfigCheck.java:217)
2015-08-04 13:02:56 at com.hazelcast.cluster.impl.JoinMessage.readData(JoinMessage.java:80)
2015-08-04 13:02:56 at com.hazelcast.cluster.impl.operations.MasterDiscoveryOperation.readInternal(MasterDiscoveryOperation.java:46)
2015-08-04 13:02:56 at com.hazelcast.spi.Operation.readData(Operation.java:451)
2015-08-04 13:02:56 at com.hazelcast.nio.serialization.DataSerializer.read(DataSerializer.java:111)
2015-08-04 13:02:56 at com.hazelcast.nio.serialization.DataSerializer.read(DataSerializer.java:39)
2015-08-04 13:02:56 at com.hazelcast.nio.serialization.StreamSerializerAdapter.read(StreamSerializerAdapter.java:41)
2015-08-04 13:02:56 at com.hazelcast.nio.serialization.SerializationServiceImpl.toObject(SerializationServiceImpl.java:276)
2015-08-04 13:02:56 ... 6 more
======================
<tcp-ip enabled="true">
<interface>192.168.1.89</interface>
<interface>192.168.1.75</interface>
</tcp-ip>
=================
And below is the code to set the serializer :
SerializerConfig serializerConfig = new SerializerConfig()
.setTypeClass(Object.class).setImplementation(
new KryoSerializer());
Config config = new FileSystemXmlConfig(HAZELCAST_CONFIG_FILE_PATH);
config.getSerializationConfig().getSerializerConfigs()
.add(serializerConfig);
hz = Hazelcast.newHazelcastInstance(config);
=======================================
Below is KeryoSerializer class
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
import com.adeptia.indigo.logging.Logger;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.KryoException;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.StreamSerializer;
public class KryoSerializer implements StreamSerializer<Object> {
private static final int TYPE_ID = 1;
private Logger log = Logger.getLogger("Hazelcast cache");
private static final ThreadLocal<Kryo> kryoThreadLocal = new ThreadLocal<Kryo>() {
@Override
protected Kryo initialValue() {
Kryo kryo = new Kryo();
kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
kryo.register(Object.class);
return kryo;
}
};
public int getTypeId() {
return TYPE_ID;
}
public void write(ObjectDataOutput objectDataOutput, Object object)
throws IOException {
Kryo kryo = kryoThreadLocal.get();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(
1024);
DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(
byteArrayOutputStream);
try {
Output output = new Output(deflaterOutputStream);
kryo.writeClassAndObject(output, object);
output.close();
objectDataOutput.write(byteArrayOutputStream.toByteArray());
} finally {
try {
deflaterOutputStream.close();
} catch (IOException e) {
log.error("Error while closing DeflaterOutputStream during Kryo serializaton "
+ e);
}
try {
byteArrayOutputStream.close();
} catch (IOException e) {
log.error("Error while closing byteArrayOutputStream during Kryo serializaton "
+ e);
}
}
}
public Object read(ObjectDataInput objectDataInput) throws IOException {
InflaterInputStream in = new InflaterInputStream(
(InputStream) objectDataInput);
try {
Input input = new Input(in);
Kryo kryo = kryoThreadLocal.get();
return kryo.readClassAndObject(input);
} finally {
try {
in.close();
} catch (IOException e) {
log.error("Error while closing InflaterInputStream during Kryo deserializaton "
+ e);
}
}
}
public void destroy() {
// We don't need to implement it as the Kryo does all the required
// things.
}
}
Can you please let me know how to resolve this