use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class MulticastService method receive.
private JoinMessage receive() {
try {
try {
multicastSocket.receive(datagramPacketReceive);
} catch (IOException ignore) {
return null;
}
try {
final byte[] data = datagramPacketReceive.getData();
final int offset = datagramPacketReceive.getOffset();
final int length = datagramPacketReceive.getLength();
final byte[] processed = inputProcessor != null ? inputProcessor.process(data, offset, length) : data;
final BufferObjectDataInput input = node.getSerializationService().createObjectDataInput(processed);
if (inputProcessor == null) {
// If pre-processed the offset is already taken into account.
input.position(offset);
}
final byte packetVersion = input.readByte();
if (packetVersion != Packet.VERSION) {
logger.warning("Received a JoinRequest with a different packet version, or encrypted. " + "Verify that the sender Node, doesn't have symmetric-encryption on. This -> " + Packet.VERSION + ", Incoming -> " + packetVersion + ", Sender -> " + datagramPacketReceive.getAddress());
return null;
}
return input.readObject();
} catch (Exception e) {
if (e instanceof EOFException || e instanceof HazelcastSerializationException) {
long now = System.currentTimeMillis();
if (now - lastLoggedJoinSerializationFailure > JOIN_SERIALIZATION_ERROR_SUPPRESSION_MILLIS) {
lastLoggedJoinSerializationFailure = now;
logger.warning("Received a JoinRequest with an incompatible binary-format. " + "An old version of Hazelcast may be using the same multicast discovery port. " + "Are you running multiple Hazelcast clusters on this host? " + "(This message will be suppressed for 60 seconds). ");
}
} else if (e instanceof GeneralSecurityException) {
logger.warning("Received a JoinRequest with an incompatible encoding. " + "Symmetric-encryption is enabled on this node, the remote node either doesn't have it on, " + "or it uses different cipher." + "(This message will be suppressed for 60 seconds). ");
} else {
throw e;
}
}
} catch (Exception e) {
logger.warning(e);
}
return null;
}
use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class SerializingGenericRecordCloner method build.
@Override
@Nonnull
public GenericRecord build() {
try {
for (FieldDescriptor field : schema.getFields()) {
String fieldName = field.getFieldName();
Writer writer = fields.get(fieldName);
if (writer != null) {
writer.write();
} else {
// Field is not overwritten. Write the field from the generic record.
FieldKind fieldKind = field.getKind();
fieldOperations(fieldKind).writeFieldFromRecordToWriter(cw, genericRecord, fieldName);
}
}
cw.end();
byte[] bytes = cw.toByteArray();
Class associatedClass = genericRecord.getAssociatedClass();
BufferObjectDataInput dataInput = bufferObjectDataInputFunc.apply(bytes);
return new DefaultCompactReader(serializer, dataInput, schema, associatedClass, false);
} catch (IOException e) {
throw new HazelcastSerializationException(e);
}
}
use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class PortableContextImpl method lookupClassDefinition.
@Override
public ClassDefinition lookupClassDefinition(Data data) throws IOException {
if (!data.isPortable()) {
throw new IllegalArgumentException("Data is not Portable!");
}
BufferObjectDataInput in = serializationService.createObjectDataInput(data);
int factoryId = in.readInt();
int classId = in.readInt();
int version = in.readInt();
ClassDefinition classDefinition = lookupClassDefinition(factoryId, classId, version);
if (classDefinition == null) {
classDefinition = readClassDefinition(in, factoryId, classId, version);
}
return classDefinition;
}
use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class Networking method handleFlowControlPacket.
private void handleFlowControlPacket(Address fromAddr, byte[] packet) throws IOException {
BufferObjectDataInput input = createObjectDataInput(nodeEngine, packet);
for (; ; ) {
final long executionId = input.readLong();
if (executionId == TERMINAL_EXECUTION_ID) {
break;
}
final Map<SenderReceiverKey, SenderTasklet> senderMap = jobExecutionService.getSenderMap(executionId);
for (; ; ) {
final int vertexId = input.readInt();
if (vertexId == TERMINAL_VERTEX_ID) {
break;
}
int ordinal = input.readInt();
int sendSeqLimitCompressed = input.readInt();
final SenderTasklet t;
if (senderMap != null && (t = senderMap.get(new SenderReceiverKey(vertexId, ordinal, fromAddr))) != null) {
t.setSendSeqLimitCompressed(sendSeqLimitCompressed);
}
}
}
}
use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class AbstractSerializationService method toObject.
@Override
public final <T> T toObject(final Object object, Class aClass) {
if (!(object instanceof Data)) {
return (T) object;
}
Data data = (Data) object;
if (isNullData(data)) {
return null;
}
BufferPool pool = bufferPoolThreadLocal.get();
BufferObjectDataInput in = pool.takeInputBuffer(data);
try {
ClassLocator.onStartDeserialization();
final int typeId = data.getType();
final SerializerAdapter serializer = serializerFor(typeId);
if (serializer == null) {
if (active) {
throw newHazelcastSerializationException(typeId);
}
throw notActiveExceptionSupplier.get();
}
Object obj = serializer.read(in, aClass);
if (managedContext != null) {
obj = managedContext.initialize(obj);
}
return (T) obj;
} catch (Throwable e) {
throw handleException(e);
} finally {
ClassLocator.onFinishDeserialization();
pool.returnInputBuffer(in);
}
}
Aggregations