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