use of com.hazelcast.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 BufferObjectDataInput input = node.getSerializationService().createObjectDataInput(data);
input.position(offset);
final byte packetVersion = input.readByte();
if (packetVersion != Packet.VERSION) {
logger.warning("Received a JoinRequest with a different packet version! This -> " + Packet.VERSION + ", Incoming -> " + packetVersion + ", Sender -> " + datagramPacketReceive.getAddress());
return null;
}
try {
return input.readObject();
} finally {
input.close();
}
} 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 {
throw e;
}
}
} catch (Exception e) {
logger.warning(e);
}
return null;
}
use of com.hazelcast.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 new HazelcastInstanceNotActiveException();
}
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);
}
}
use of com.hazelcast.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class BufferPoolImpl method takeInputBuffer.
@Override
public BufferObjectDataInput takeInputBuffer(Data data) {
BufferObjectDataInput in = inputQueue.poll();
if (in == null) {
in = serializationService.createObjectDataInput((byte[]) null);
}
in.init(data.toByteArray(), HeapData.DATA_OFFSET);
return in;
}
use of com.hazelcast.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class PortablePositionNavigator method navigateContextToNextPortableTokenFromPortableField.
// returns true if managed to advance, false if advance failed due to null field
private static boolean navigateContextToNextPortableTokenFromPortableField(PortableNavigatorContext ctx) throws IOException {
BufferObjectDataInput in = ctx.getIn();
// find the field position that's stored in the fieldDefinition int the context and navigate to it
int pos = getStreamPositionOfTheField(ctx);
in.position(pos);
// check if it's null, if so return false indicating that the navigation has failed
boolean isNull = in.readBoolean();
if (isNull) {
return false;
}
// read factory and class Id and validate if it's the same as expected in the fieldDefinition
int factoryId = in.readInt();
int classId = in.readInt();
int versionId = in.readInt();
// initialise context with the given portable field for further navigation
ctx.advanceContextToNextPortableToken(factoryId, classId, versionId);
return true;
}
use of com.hazelcast.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class PortablePositionNavigator method createPositionForSingleCellPrimitiveArrayAccess.
private static PortablePosition createPositionForSingleCellPrimitiveArrayAccess(PortableNavigatorContext ctx, PortablePathCursor path, int index) throws IOException {
// assumes position.getIndex() >= 0
BufferObjectDataInput in = ctx.getIn();
in.position(getStreamPositionOfTheField(ctx));
// read the array length and ignore it, it has been already validated
in.readInt();
int streamPosition;
if (ctx.getCurrentFieldType() == FieldType.UTF || ctx.getCurrentFieldType() == FieldType.UTF_ARRAY) {
// UTF arrays actually need iterating over all elements to read the length of each element
// it's impossible to dead-reckon about a cell's position
int currentIndex = 0;
while (index > currentIndex) {
int indexElementLen = in.readInt();
in.position(in.position() + indexElementLen);
currentIndex++;
}
streamPosition = in.position();
} else {
// in primitive non-utf arrays we can dead-reckon about a cell's position
streamPosition = in.position() + index * ctx.getCurrentFieldType().getSingleType().getTypeSize();
}
return PortablePositionFactory.createSinglePrimitivePosition(ctx.getCurrentFieldDefinition(), streamPosition, index, path.isLastToken());
}
Aggregations