Search in sources :

Example 21 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class QueueMergeOperation method merge.

private Queue<QueueItem> merge(QueueContainer container, QueueMergeTypes<Object> mergingValue, SplitBrainMergePolicy<Collection<Object>, QueueMergeTypes<Object>, Collection<Object>> mergePolicy) {
    SerializationService serializationService = getNodeEngine().getSerializationService();
    mergingValue = (QueueMergeTypes<Object>) serializationService.getManagedContext().initialize(mergingValue);
    mergePolicy = (SplitBrainMergePolicy<Collection<Object>, QueueMergeTypes<Object>, Collection<Object>>) serializationService.getManagedContext().initialize(mergePolicy);
    Queue<QueueItem> existingItems = container.getItemQueue();
    QueueMergeTypes<Object> existingValue = createMergingValueOrNull(serializationService, existingItems);
    Collection<Object> newValues = mergePolicy.merge(mergingValue, existingValue);
    if (isEmpty(newValues)) {
        if (existingValue != null) {
            container.clear();
        }
        getQueueService().destroyDistributedObject(name);
    } else if (existingValue == null) {
        createNewQueueItems(container, newValues, serializationService);
    } else if (!newValues.equals(existingValue.getRawValue())) {
        container.clear();
        createNewQueueItems(container, newValues, serializationService);
    }
    return existingItems;
}
Also used : QueueMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes.QueueMergeTypes) SerializationService(com.hazelcast.internal.serialization.SerializationService) Collection(java.util.Collection) QueueItem(com.hazelcast.collection.impl.queue.QueueItem)

Example 22 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class ClientMapProxy method readFromEventJournal.

@Override
public <T> InternalCompletableFuture<ReadResultSet<T>> readFromEventJournal(long startSequence, int minSize, int maxSize, int partitionId, java.util.function.Predicate<? super EventJournalMapEvent<K, V>> predicate, java.util.function.Function<? super EventJournalMapEvent<K, V>, ? extends T> projection) {
    if (maxSize < minSize) {
        throw new IllegalArgumentException("maxSize " + maxSize + " must be greater or equal to minSize " + minSize);
    }
    final SerializationService ss = getSerializationService();
    final ClientMessage request = MapEventJournalReadCodec.encodeRequest(name, startSequence, minSize, maxSize, ss.toData(predicate), ss.toData(projection));
    final ClientInvocationFuture fut = new ClientInvocation(getClient(), request, getName(), partitionId).invoke();
    return new ClientDelegatingFuture<>(fut, ss, message -> {
        MapEventJournalReadCodec.ResponseParameters params = MapEventJournalReadCodec.decodeResponse(message);
        ReadResultSetImpl resultSet = new ReadResultSetImpl<>(params.readCount, params.items, params.itemSeqs, params.nextSeq);
        resultSet.setSerializationService(getSerializationService());
        return resultSet;
    });
}
Also used : ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) SerializationService(com.hazelcast.internal.serialization.SerializationService) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) MapEventJournalReadCodec(com.hazelcast.client.impl.protocol.codec.MapEventJournalReadCodec) ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

Example 23 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class ExecutionSerializerHooksTest method testSerializerHooks.

@Test
public void testSerializerHooks() {
    if (!(instance instanceof Map.Entry)) {
        assertFalse("Type implements java.io.Serializable", instance instanceof Serializable);
    }
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    Data serialized = serializationService.toData(instance);
    Object deserialized = serializationService.toObject(serialized);
    if (instance instanceof DoneItem) {
        assertSame("deserialized instance not same for type " + instance.getClass(), instance, deserialized);
    } else {
        assertNotSame("deserialized instance same for type " + instance.getClass(), instance, deserialized);
    }
    assertEquals("objects are not equal after serialize/deserialize", instance, deserialized);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) Serializable(java.io.Serializable) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class DataModelSerializerHooksTest method testSerializerHook.

@Test
public void testSerializerHook() {
    if (!(instance instanceof Map.Entry || instance instanceof Tag)) {
        assertFalse(instance.getClass() + " implements java.io.Serializable", instance instanceof Serializable);
    }
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    Data serialized = serializationService.toData(instance);
    Object deserialized = serializationService.toObject(serialized);
    if (!(instance instanceof Tag)) {
        assertNotSame("serialization/deserialization didn't take place", instance, deserialized);
    }
    assertEquals("objects are not equal after serialize/deserialize", instance, deserialized);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) Serializable(java.io.Serializable) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) ItemsByTag.itemsByTag(com.hazelcast.jet.datamodel.ItemsByTag.itemsByTag) Map(java.util.Map) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class SerializerHooksTest method testSerializerHooks.

@Test
public void testSerializerHooks() {
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    Data serialized = serializationService.toData(instance);
    Object deserialized = serializationService.toObject(serialized);
    assertNotSame("serialization/deserialization didn't take place", instance, deserialized);
    if (instance instanceof Object[]) {
        assertArrayEquals("objects are not equal after serialize/deserialize", (Object[]) instance, (Object[]) deserialized);
    } else {
        assertEquals("objects are not equal after serialize/deserialize", instance, deserialized);
    }
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

SerializationService (com.hazelcast.internal.serialization.SerializationService)170 Data (com.hazelcast.internal.serialization.Data)117 Test (org.junit.Test)100 QuickTest (com.hazelcast.test.annotation.QuickTest)99 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)59 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)50 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)43 ArrayList (java.util.ArrayList)15 SerializationConfig (com.hazelcast.config.SerializationConfig)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 Node (com.hazelcast.instance.impl.Node)12 CustomSerializationTest (com.hazelcast.internal.serialization.impl.CustomSerializationTest)12 Accessors.getNode (com.hazelcast.test.Accessors.getNode)12 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)11 EmployeeDTO (example.serialization.EmployeeDTO)11 ExternalizableEmployeeDTO (example.serialization.ExternalizableEmployeeDTO)11 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)8 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8