use of com.hazelcast.spi.merge.SplitBrainMergeTypes.CollectionMergeTypes in project hazelcast by hazelcast.
the class CollectionMergeOperation method merge.
private Collection<CollectionItem> merge(CollectionContainer container, CollectionMergeTypes<Object> mergingValue, SplitBrainMergePolicy<Collection<Object>, CollectionMergeTypes<Object>, Collection<Object>> mergePolicy) {
SerializationService serializationService = getNodeEngine().getSerializationService();
mergingValue = (CollectionMergeTypes<Object>) serializationService.getManagedContext().initialize(mergingValue);
mergePolicy = (SplitBrainMergePolicy<Collection<Object>, CollectionMergeTypes<Object>, Collection<Object>>) serializationService.getManagedContext().initialize(mergePolicy);
Collection<CollectionItem> existingItems = container.getCollection();
CollectionMergeTypes<Object> existingValue = createMergingValueOrNull(serializationService, existingItems);
Collection<Object> newValues = mergePolicy.merge(mergingValue, existingValue);
if (isEmpty(newValues)) {
RemoteService service = getService();
service.destroyDistributedObject(name);
} else if (existingValue == null) {
createNewCollectionItems(container, existingItems, newValues, serializationService);
} else if (!newValues.equals(existingValue.getRawValue())) {
container.clear(false);
createNewCollectionItems(container, existingItems, newValues, serializationService);
}
return existingItems;
}
Aggregations