Search in sources :

Example 26 with ObjectDataOutput

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

the class ReplicatedMapEntries method writePortable.

@Override
public void writePortable(PortableWriter writer) throws IOException {
    int size = size();
    writer.writeInt("size", size);
    ObjectDataOutput out = writer.getRawDataOutput();
    for (int i = 0; i < size; i++) {
        out.writeData(keys.get(i));
        out.writeData(values.get(i));
    }
}
Also used : ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput)

Example 27 with ObjectDataOutput

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

the class ReplicatedMapKeys method writePortable.

@Override
public void writePortable(PortableWriter writer) throws IOException {
    writer.writeInt("size", keys.size());
    ObjectDataOutput out = writer.getRawDataOutput();
    for (Data key : keys) {
        out.writeData(key);
    }
}
Also used : ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) Data(com.hazelcast.nio.serialization.Data)

Example 28 with ObjectDataOutput

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

the class MigrationListenerAdapterTest method test_migrationEvent_serialization.

@Test
public void test_migrationEvent_serialization() throws IOException {
    final MigrationEvent event = new MigrationEvent(0, null, null, STARTED);
    final ObjectDataOutput output = mock(ObjectDataOutput.class);
    event.writeData(output);
    verify(output).writeInt(0);
    verify(output, times(2)).writeObject(null);
    verify(output).writeByte(0);
}
Also used : ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) MigrationEvent(com.hazelcast.core.MigrationEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 29 with ObjectDataOutput

use of com.hazelcast.nio.ObjectDataOutput 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)

Example 30 with ObjectDataOutput

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

the class SerializationV1Portable method writePortable.

@Override
public void writePortable(PortableWriter out) throws IOException {
    out.writeByte("1", aByte);
    out.writeBoolean("2", aBoolean);
    out.writeChar("3", character);
    out.writeShort("4", aShort);
    out.writeInt("5", integer);
    out.writeLong("6", aLong);
    out.writeFloat("7", aFloat);
    out.writeDouble("8", aDouble);
    out.writeUTF("9", string);
    out.writeByteArray("a1", bytes);
    out.writeBooleanArray("a2", booleans);
    out.writeCharArray("a3", chars);
    out.writeShortArray("a4", shorts);
    out.writeIntArray("a5", ints);
    out.writeLongArray("a6", longs);
    out.writeFloatArray("a7", floats);
    out.writeDoubleArray("a8", doubles);
    out.writeUTFArray("a9", strings);
    if (innerPortable == null) {
        out.writeNullPortable("p", INNER_PORTABLE.getFactoryId(), INNER_PORTABLE.getClassId());
    } else {
        out.writePortable("p", innerPortable);
    }
    ObjectDataOutput rawDataOutput = out.getRawDataOutput();
    boolean isNotNull = dataSerializable != null;
    if (isNotNull) {
        rawDataOutput.writeBoolean(isNotNull);
        dataSerializable.writeData(rawDataOutput);
    } else {
        rawDataOutput.writeBoolean(isNotNull);
    }
}
Also used : ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput)

Aggregations

ObjectDataOutput (com.hazelcast.nio.ObjectDataOutput)43 Test (org.junit.Test)15 ObjectDataInput (com.hazelcast.nio.ObjectDataInput)12 QuickTest (com.hazelcast.test.annotation.QuickTest)12 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)7 SerializationConfig (com.hazelcast.config.SerializationConfig)6 StreamSerializer (com.hazelcast.nio.serialization.StreamSerializer)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)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 Data (com.hazelcast.nio.serialization.Data)3 SerializationService (com.hazelcast.spi.serialization.SerializationService)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 SerializerConfig (com.hazelcast.config.SerializerConfig)2 DataWriter (com.hazelcast.internal.nio.DataWriter)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 DataSerializable (com.hazelcast.nio.serialization.DataSerializable)2