use of com.hazelcast.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class BufferPoolTest method returnInputBuffer.
@Test
public void returnInputBuffer() {
BufferObjectDataInput in = mock(BufferObjectDataInput.class);
bufferPool.returnInputBuffer(in);
// lets see if the item was pushed on the queue
assertEquals(1, bufferPool.inputQueue.size());
// we need to make sure clear was called
verify(in, times(1)).clear();
}
use of com.hazelcast.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class OperationSerializationTest method copy.
private Operation copy(Operation op) {
try {
BufferObjectDataOutput out = serializationService.createObjectDataOutput(1000);
op.writeData(out);
BufferObjectDataInput in = serializationService.createObjectDataInput(out.toByteArray());
Constructor constructor = op.getClass().getConstructor();
constructor.setAccessible(true);
Operation copiedOperation = (Operation) constructor.newInstance();
copiedOperation.readData(in);
return copiedOperation;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.hazelcast.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class PortablePositionNavigator method createPositionForPortableFieldAccess.
private static PortablePosition createPositionForPortableFieldAccess(PortableNavigatorContext ctx, PortablePathCursor path) throws IOException {
BufferObjectDataInput in = ctx.getIn();
in.position(getStreamPositionOfTheField(ctx));
// read and validate portable properties
boolean nil = in.readBoolean();
int factoryId = in.readInt();
int classId = in.readInt();
int streamPosition = in.position();
validateFactoryAndClass(ctx.getCurrentFieldDefinition(), factoryId, classId, path.path());
return PortablePositionFactory.createSinglePortablePosition(ctx.getCurrentFieldDefinition(), streamPosition, factoryId, classId, nil, path.isLastToken());
}
use of com.hazelcast.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class PortablePositionNavigator method navigateContextToNextPortableTokenFromPortableArrayCell.
// this navigation always succeeds since the caller validates if the index is inbound
private static void navigateContextToNextPortableTokenFromPortableArrayCell(PortableNavigatorContext ctx, PortablePathCursor path, int index) throws IOException {
BufferObjectDataInput in = ctx.getIn();
// find the array field position that's stored in the fieldDefinition int the context and navigate to it
int pos = getStreamPositionOfTheField(ctx);
in.position(pos);
// read array length and ignore
in.readInt();
// 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();
validateFactoryAndClass(ctx.getCurrentFieldDefinition(), factoryId, classId, path.path());
// calculate the offset of the cell given by the index
final int cellOffset = in.position() + index * Bits.INT_SIZE_IN_BYTES;
in.position(cellOffset);
// read the position of the portable addressed in this array cell (array contains portable position only)
int portablePosition = in.readInt();
// navigate to portable position and read it's version
in.position(portablePosition);
int versionId = in.readInt();
// initialise context with the given portable field for further navigation
ctx.advanceContextToNextPortableToken(factoryId, classId, versionId);
}
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) {
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);
if (managedContext != null) {
obj = managedContext.initialize(obj);
}
return (T) obj;
} catch (Throwable e) {
throw handleException(e);
} finally {
ClassLocator.onFinishDeserialization();
pool.returnInputBuffer(in);
}
}
Aggregations