Search in sources :

Example 16 with BufferObjectDataInput

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) {
    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);
    }
}
Also used : BufferPool(com.hazelcast.internal.serialization.impl.bufferpool.BufferPool) SerializationUtil.createSerializerAdapter(com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter) CompactWithSchemaStreamSerializerAdapter(com.hazelcast.internal.serialization.impl.compact.CompactWithSchemaStreamSerializerAdapter) CompactStreamSerializerAdapter(com.hazelcast.internal.serialization.impl.compact.CompactStreamSerializerAdapter) SerializationUtil.isNullData(com.hazelcast.internal.serialization.impl.SerializationUtil.isNullData) Data(com.hazelcast.internal.serialization.Data) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput)

Example 17 with BufferObjectDataInput

use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.

the class PortableSerializer method readAsInternalGenericRecord.

public InternalGenericRecord readAsInternalGenericRecord(ObjectDataInput in) throws IOException {
    int factoryId = in.readInt();
    int classId = in.readInt();
    int version = in.readInt();
    BufferObjectDataInput input = (BufferObjectDataInput) in;
    ClassDefinition cd = setupPositionAndDefinition(input, factoryId, classId, version);
    return new PortableInternalGenericRecord(this, input, cd, true);
}
Also used : ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput)

Example 18 with BufferObjectDataInput

use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.

the class PortableSerializer method read.

@Override
public Object read(ObjectDataInput in) throws IOException {
    if (!(in instanceof BufferObjectDataInput)) {
        throw new IllegalArgumentException("ObjectDataInput must be instance of BufferObjectDataInput!");
    }
    int factoryId = in.readInt();
    int classId = in.readInt();
    BufferObjectDataInput input = (BufferObjectDataInput) in;
    return read(input, factoryId, classId);
}
Also used : BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput)

Example 19 with BufferObjectDataInput

use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.

the class CompactStreamSerializer method readGenericRecord.

public GenericRecord readGenericRecord(ObjectDataInput in, boolean schemaIncludedInBinary) throws IOException {
    Schema schema = getOrReadSchema(in, schemaIncludedInBinary);
    BufferObjectDataInput input = (BufferObjectDataInput) in;
    return new DefaultCompactReader(this, input, schema, null, schemaIncludedInBinary);
}
Also used : BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput)

Example 20 with BufferObjectDataInput

use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.

the class AbstractSerializationServiceTest method testReadObject_ServiceInactive.

@Test
public void testReadObject_ServiceInactive() throws Exception {
    expectedException.expect(HazelcastInstanceNotActiveException.class);
    abstractSerializationService.register(StringBuffer.class, new StringBufferSerializer(false));
    Data data = abstractSerializationService.toData(new StringBuffer());
    abstractSerializationService.dispose();
    BufferObjectDataInput in = abstractSerializationService.createObjectDataInput(data);
    in.position(HeapData.TYPE_OFFSET);
    abstractSerializationService.readObject(in);
}
Also used : Data(com.hazelcast.internal.serialization.Data) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)28 QuickTest (com.hazelcast.test.annotation.QuickTest)12 Test (org.junit.Test)12 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)11 Data (com.hazelcast.internal.serialization.Data)10 BufferObjectDataOutput (com.hazelcast.internal.nio.BufferObjectDataOutput)6 HeapData (com.hazelcast.internal.serialization.impl.HeapData)5 IOException (java.io.IOException)5 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)3 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)3 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)2 SerializationUtil.isNullData (com.hazelcast.internal.serialization.impl.SerializationUtil.isNullData)2 BufferPool (com.hazelcast.internal.serialization.impl.bufferpool.BufferPool)2 CompactStreamSerializerAdapter (com.hazelcast.internal.serialization.impl.compact.CompactStreamSerializerAdapter)2 CompactWithSchemaStreamSerializerAdapter (com.hazelcast.internal.serialization.impl.compact.CompactWithSchemaStreamSerializerAdapter)2 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)2 HazelcastException (com.hazelcast.core.HazelcastException)1 IOUtil.readData (com.hazelcast.internal.nio.IOUtil.readData)1 IOUtil.writeData (com.hazelcast.internal.nio.IOUtil.writeData)1