Search in sources :

Example 1 with CollectionMergeTypes

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;
}
Also used : RemoteService(com.hazelcast.internal.services.RemoteService) SerializationService(com.hazelcast.internal.serialization.SerializationService) Collection(java.util.Collection) CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem) CollectionMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes.CollectionMergeTypes)

Aggregations

CollectionItem (com.hazelcast.collection.impl.collection.CollectionItem)1 SerializationService (com.hazelcast.internal.serialization.SerializationService)1 RemoteService (com.hazelcast.internal.services.RemoteService)1 CollectionMergeTypes (com.hazelcast.spi.merge.SplitBrainMergeTypes.CollectionMergeTypes)1 Collection (java.util.Collection)1