Search in sources :

Example 46 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class PortableReadResultSet method readPortable.

@Override
public void readPortable(PortableReader reader) throws IOException {
    readCount = reader.readInt("readCount");
    // reading the items.
    int size = reader.readInt("count");
    this.items = new ArrayList<Data>(size);
    ObjectDataInput rawDataInput = reader.getRawDataInput();
    for (int k = 0; k < size; k++) {
        Data item = rawDataInput.readData();
        items.add(item);
    }
}
Also used : Data(com.hazelcast.nio.serialization.Data) ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 47 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class ReplicatedMapPortableEntryEvent method readPortable.

public void readPortable(PortableReader reader) throws IOException {
    eventType = EntryEventType.getByType(reader.readInt("e"));
    uuid = reader.readUTF("u");
    final ObjectDataInput in = reader.getRawDataInput();
    key = in.readData();
    value = in.readData();
    oldValue = in.readData();
    numberOfAffectedEntries = in.readInt();
}
Also used : ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 48 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class ClientPartitionLostListenerTest method test_portableMapPartitionLostEvent_deserialization.

@Test
public void test_portableMapPartitionLostEvent_deserialization() throws IOException {
    final Address source = new Address();
    final PortablePartitionLostEvent event = new PortablePartitionLostEvent();
    final PortableReader reader = mock(PortableReader.class);
    final ObjectDataInput input = mock(ObjectDataInput.class);
    when(reader.getRawDataInput()).thenReturn(input);
    when(reader.readInt("p")).thenReturn(1);
    when(reader.readInt("l")).thenReturn(2);
    when(input.readObject()).thenReturn(source);
    event.readPortable(reader);
    assertEquals(1, event.getPartitionId());
    assertEquals(2, event.getLostBackupCount());
    assertEquals(source, event.getSource());
}
Also used : PortablePartitionLostEvent(com.hazelcast.spi.impl.PortablePartitionLostEvent) Address(com.hazelcast.nio.Address) HazelcastTestSupport.getAddress(com.hazelcast.test.HazelcastTestSupport.getAddress) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) PortableReader(com.hazelcast.nio.serialization.PortableReader) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 49 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class SerializationV1Portable method readPortable.

@Override
public void readPortable(PortableReader in) throws IOException {
    this.aByte = in.readByte("1");
    this.aBoolean = in.readBoolean("2");
    this.character = in.readChar("3");
    this.aShort = in.readShort("4");
    this.integer = in.readInt("5");
    this.aLong = in.readLong("6");
    this.aFloat = in.readFloat("7");
    this.aDouble = in.readDouble("8");
    this.string = in.readUTF("9");
    this.bytes = in.readByteArray("a1");
    this.booleans = in.readBooleanArray("a2");
    this.chars = in.readCharArray("a3");
    this.shorts = in.readShortArray("a4");
    this.ints = in.readIntArray("a5");
    this.longs = in.readLongArray("a6");
    this.floats = in.readFloatArray("a7");
    this.doubles = in.readDoubleArray("a8");
    this.strings = in.readUTFArray("a9");
    this.innerPortable = in.readPortable("p");
    ObjectDataInput rawDataInput = in.getRawDataInput();
    boolean isNotNull = rawDataInput.readBoolean();
    if (isNotNull) {
        SerializationV1Dataserializable dataserializable = new SerializationV1Dataserializable();
        dataserializable.readData(rawDataInput);
        this.dataSerializable = dataserializable;
    }
}
Also used : ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 50 with ObjectDataInput

use of com.hazelcast.nio.ObjectDataInput in project hazelcast by hazelcast.

the class SerializationTest method testGlobalSerializer_withoutOverrideJavaSerializable.

@Test
public void testGlobalSerializer_withoutOverrideJavaSerializable() {
    GlobalSerializerConfig globalSerializerConfig = new GlobalSerializerConfig();
    globalSerializerConfig.setOverrideJavaSerialization(false);
    final AtomicInteger writeCounter = new AtomicInteger();
    final AtomicInteger readCounter = new AtomicInteger();
    SerializationConfig serializationConfig = new SerializationConfig().setGlobalSerializerConfig(globalSerializerConfig.setImplementation(new StreamSerializer<Object>() {

        @Override
        public void write(ObjectDataOutput out, Object v) throws IOException {
            writeCounter.incrementAndGet();
            out.writeUTF(((DummyValue) v).s);
            out.writeInt(((DummyValue) v).k);
        }

        @Override
        public Object read(ObjectDataInput in) throws IOException {
            readCounter.incrementAndGet();
            return new DummyValue(in.readUTF(), in.readInt());
        }

        public int getTypeId() {
            return 123;
        }

        public void destroy() {
        }
    }));
    SerializationService ss1 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
    DummyValue value = new DummyValue("test", 111);
    Data data1 = ss1.toData(value);
    Data data2 = ss1.toData(new Foo());
    Assert.assertNotNull(data1);
    Assert.assertNotNull(data2);
    assertEquals(1, writeCounter.get());
    SerializationService ss2 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
    Object o1 = ss2.toObject(data1);
    Object o2 = ss2.toObject(data2);
    Assert.assertEquals(value, o1);
    Assert.assertNotNull(o2);
    assertEquals(1, readCounter.get());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SerializationConfig(com.hazelcast.config.SerializationConfig) SerializationService(com.hazelcast.spi.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ObjectDataInput (com.hazelcast.nio.ObjectDataInput)81 Test (org.junit.Test)35 QuickTest (com.hazelcast.test.annotation.QuickTest)32 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)24 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)17 FieldKind (com.hazelcast.nio.serialization.FieldKind)16 IOException (java.io.IOException)13 ObjectDataOutput (com.hazelcast.nio.ObjectDataOutput)12 Nullable (javax.annotation.Nullable)9 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)7 SerializationConfig (com.hazelcast.config.SerializationConfig)6 StreamSerializer (com.hazelcast.nio.serialization.StreamSerializer)6 Data (com.hazelcast.nio.serialization.Data)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Data (com.hazelcast.internal.serialization.Data)3 SerializationService (com.hazelcast.internal.serialization.SerializationService)3 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)3 HeapData (com.hazelcast.internal.serialization.impl.HeapData)3 SerializationService (com.hazelcast.spi.serialization.SerializationService)3 SerializerConfig (com.hazelcast.config.SerializerConfig)2