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;
}
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;
});
}
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);
}
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);
}
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);
}
}
Aggregations