Search in sources :

Example 16 with BufferObjectDataOutput

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

the class PortableSerializer method write.

@Override
public void write(ObjectDataOutput out, Object o) throws IOException {
    if (o instanceof Portable) {
        Portable p = (Portable) o;
        if (!(out instanceof BufferObjectDataOutput)) {
            throw new IllegalArgumentException("ObjectDataOutput must be instance of BufferObjectDataOutput!");
        }
        if (p.getClassId() == 0) {
            throw new IllegalArgumentException("Portable class ID cannot be zero!");
        }
        out.writeInt(p.getFactoryId());
        out.writeInt(p.getClassId());
        writeInternal((BufferObjectDataOutput) out, p);
        return;
    }
    if (o instanceof PortableGenericRecord) {
        writePortableGenericRecord(out, (PortableGenericRecord) o);
        return;
    }
    throw new IllegalArgumentException("PortableSerializer can only write Portable and PortableGenericRecord");
}
Also used : Portable(com.hazelcast.nio.serialization.Portable) BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput)

Example 17 with BufferObjectDataOutput

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

the class CompactStreamSerializer method write.

// ========================== WRITE =============================//
@Override
public void write(ObjectDataOutput out, Object o) throws IOException {
    assert out instanceof BufferObjectDataOutput;
    BufferObjectDataOutput bufferObjectDataOutput = (BufferObjectDataOutput) out;
    write(bufferObjectDataOutput, o, false);
}
Also used : BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput)

Example 18 with BufferObjectDataOutput

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

the class AbstractSerializationServiceTest method testWriteObject_serializerFail.

@Test(expected = HazelcastSerializationException.class)
public void testWriteObject_serializerFail() throws Exception {
    abstractSerializationService.register(StringBuffer.class, new StringBufferSerializer(true));
    BufferObjectDataOutput out = abstractSerializationService.createObjectDataOutput();
    abstractSerializationService.writeObject(out, new StringBuffer());
}
Also used : BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 19 with BufferObjectDataOutput

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

the class BufferPoolTest method takeOutputBuffer_whenPooledInstanceWithVersionSetIsReturned.

@Test
public void takeOutputBuffer_whenPooledInstanceWithVersionSetIsReturned() {
    BufferObjectDataOutput found1 = bufferPool.takeOutputBuffer();
    assertEquals(Version.UNKNOWN, found1.getVersion());
    found1.setVersion(Versions.CURRENT_CLUSTER_VERSION);
    bufferPool.returnOutputBuffer(found1);
    BufferObjectDataOutput found2 = bufferPool.takeOutputBuffer();
    assertEquals(Version.UNKNOWN, found2.getVersion());
}
Also used : BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with BufferObjectDataOutput

use of com.hazelcast.internal.nio.BufferObjectDataOutput 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);
    }
}
Also used : BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) Constructor(java.lang.reflect.Constructor) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput)

Aggregations

BufferObjectDataOutput (com.hazelcast.internal.nio.BufferObjectDataOutput)21 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Test (org.junit.Test)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)6 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)3 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)3 IOException (java.io.IOException)3 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)2 Address (com.hazelcast.cluster.Address)1 Connection (com.hazelcast.internal.nio.Connection)1 IOUtil.readData (com.hazelcast.internal.nio.IOUtil.readData)1 IOUtil.writeData (com.hazelcast.internal.nio.IOUtil.writeData)1 Data (com.hazelcast.internal.serialization.Data)1 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)1 BufferPool (com.hazelcast.internal.serialization.impl.bufferpool.BufferPool)1 CompactStreamSerializerAdapter (com.hazelcast.internal.serialization.impl.compact.CompactStreamSerializerAdapter)1 CompactWithSchemaStreamSerializerAdapter (com.hazelcast.internal.serialization.impl.compact.CompactWithSchemaStreamSerializerAdapter)1 ExecutionContext (com.hazelcast.jet.impl.execution.ExecutionContext)1 SenderReceiverKey (com.hazelcast.jet.impl.execution.ExecutionContext.SenderReceiverKey)1