use of com.hazelcast.internal.serialization.impl.bufferpool.BufferPool 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);
}
}
use of com.hazelcast.internal.serialization.impl.bufferpool.BufferPool in project hazelcast by hazelcast.
the class AbstractSerializationService method toBytes.
@Override
public byte[] toBytes(int padding, Object obj, PartitioningStrategy strategy) {
checkNotNull(obj);
BufferPool pool = bufferPoolThreadLocal.get();
BufferObjectDataOutput out = pool.takeOutputBuffer();
try {
SerializerAdapter serializer = serializerFor(obj);
int partitionHash = calculatePartitionHash(obj, strategy);
out.writeInt(partitionHash, ByteOrder.BIG_ENDIAN);
out.writeInt(serializer.getTypeId(), ByteOrder.BIG_ENDIAN);
serializer.write(out, obj);
return out.toByteArray(padding);
} catch (Throwable e) {
throw handleSerializeException(obj, e);
} finally {
pool.returnOutputBuffer(out);
}
}
use of com.hazelcast.internal.serialization.impl.bufferpool.BufferPool 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;
}
final int typeId = data.getType();
final SerializerAdapter serializer = serializerFor(typeId);
if (serializer == null) {
if (active) {
throw newHazelcastSerializationException(typeId);
}
throw notActiveExceptionSupplier.get();
}
Object obj = null;
BufferPool pool = bufferPoolThreadLocal.get();
BufferObjectDataInput in = pool.takeInputBuffer(data);
try {
ClassLocator.onStartDeserialization();
obj = serializer.read(in);
if (managedContext != null) {
obj = managedContext.initialize(obj);
}
return (T) obj;
} catch (Throwable e) {
throw handleException(e);
} finally {
ClassLocator.onFinishDeserialization();
serializer.conditionallyReturnInputBufferToPool(obj, in, pool);
}
}
use of com.hazelcast.internal.serialization.impl.bufferpool.BufferPool in project hazelcast by hazelcast.
the class AbstractSerializationService method toBytes.
private byte[] toBytes(Object obj, int leftPadding, boolean writeHash, PartitioningStrategy strategy, ByteOrder serializerTypeIdByteOrder, boolean includeSchema) {
checkNotNull(obj);
checkNotNull(serializerTypeIdByteOrder);
BufferPool pool = bufferPoolThreadLocal.get();
BufferObjectDataOutput out = pool.takeOutputBuffer();
try {
out.position(leftPadding);
SerializerAdapter serializer = serializerFor(obj, includeSchema);
if (writeHash) {
int partitionHash = calculatePartitionHash(obj, strategy);
out.writeInt(partitionHash, BIG_ENDIAN);
}
out.writeInt(serializer.getTypeId(), serializerTypeIdByteOrder);
serializer.write(out, obj);
return out.toByteArray();
} catch (Throwable e) {
throw handleSerializeException(obj, e);
} finally {
pool.returnOutputBuffer(out);
}
}
Aggregations