Search in sources :

Example 1 with QueueMergeTypes

use of com.hazelcast.spi.merge.SplitBrainMergeTypes.QueueMergeTypes 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)

Aggregations

QueueItem (com.hazelcast.collection.impl.queue.QueueItem)1 SerializationService (com.hazelcast.internal.serialization.SerializationService)1 QueueMergeTypes (com.hazelcast.spi.merge.SplitBrainMergeTypes.QueueMergeTypes)1 Collection (java.util.Collection)1