Search in sources :

Example 1 with ScheduledExecutorMergeTypes

use of com.hazelcast.spi.merge.SplitBrainMergeTypes.ScheduledExecutorMergeTypes in project hazelcast by hazelcast.

the class ScheduledExecutorContainer method merge.

/**
 * Merges the given {@link ScheduledExecutorMergeTypes} via the given {@link SplitBrainMergePolicy}.
 *
 * @param mergingEntry the {@link ScheduledExecutorMergeTypes} instance to merge
 * @param mergePolicy  the {@link SplitBrainMergePolicy} instance to apply
 * @return the used {@link ScheduledTaskDescriptor} if merge is applied, otherwise {@code null}
 */
public ScheduledTaskDescriptor merge(ScheduledExecutorMergeTypes mergingEntry, SplitBrainMergePolicy<ScheduledTaskDescriptor, ScheduledExecutorMergeTypes, ScheduledTaskDescriptor> mergePolicy) {
    SerializationService serializationService = nodeEngine.getSerializationService();
    mergingEntry = (ScheduledExecutorMergeTypes) serializationService.getManagedContext().initialize(mergingEntry);
    mergePolicy = (SplitBrainMergePolicy<ScheduledTaskDescriptor, ScheduledExecutorMergeTypes, ScheduledTaskDescriptor>) serializationService.getManagedContext().initialize(mergePolicy);
    // try to find an existing task with the same definition
    ScheduledTaskDescriptor mergingTask = ((ScheduledExecutorMergingEntryImpl) mergingEntry).getRawValue();
    ScheduledTaskDescriptor existingTask = null;
    for (ScheduledTaskDescriptor task : tasks.values()) {
        if (mergingTask.equals(task)) {
            existingTask = task;
            break;
        }
    }
    if (existingTask == null) {
        ScheduledTaskDescriptor newTask = mergePolicy.merge(mergingEntry, null);
        if (newTask != null) {
            enqueueSuspended(newTask, false);
            return newTask;
        }
    } else {
        ScheduledExecutorMergeTypes existingEntry = createMergingEntry(serializationService, existingTask);
        ScheduledTaskDescriptor newTask = mergePolicy.merge(mergingEntry, existingEntry);
        // but we still want to be able to choose which one is merged (e.g. PassThroughMergePolicy)
        if (newTask != null && newTask != existingTask) {
            // cancel the existing task, before replacing it
            existingTask.cancel(true);
            enqueueSuspended(newTask, true);
            return newTask;
        }
    }
    // the merging task was already suspended on the original node, so we don't have to cancel it here
    return null;
}
Also used : ScheduledExecutorMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes.ScheduledExecutorMergeTypes) SerializationService(com.hazelcast.internal.serialization.SerializationService) ScheduledExecutorMergingEntryImpl(com.hazelcast.spi.impl.merge.ScheduledExecutorMergingEntryImpl)

Example 2 with ScheduledExecutorMergeTypes

use of com.hazelcast.spi.merge.SplitBrainMergeTypes.ScheduledExecutorMergeTypes in project hazelcast by hazelcast.

the class MergeOperation method run.

@Override
public void run() throws Exception {
    ScheduledExecutorContainer container = getContainer();
    mergedTasks = new ArrayList<ScheduledTaskDescriptor>();
    for (ScheduledExecutorMergeTypes mergingEntry : mergingEntries) {
        ScheduledTaskDescriptor merged = container.merge(mergingEntry, mergePolicy);
        if (merged != null) {
            mergedTasks.add(merged);
        }
    }
    container.promoteSuspended();
}
Also used : ScheduledExecutorMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes.ScheduledExecutorMergeTypes) ScheduledTaskDescriptor(com.hazelcast.scheduledexecutor.impl.ScheduledTaskDescriptor) ScheduledExecutorContainer(com.hazelcast.scheduledexecutor.impl.ScheduledExecutorContainer)

Example 3 with ScheduledExecutorMergeTypes

use of com.hazelcast.spi.merge.SplitBrainMergeTypes.ScheduledExecutorMergeTypes in project hazelcast by hazelcast.

the class MergeOperation method readInternal.

@Override
protected void readInternal(ObjectDataInput in) throws IOException {
    super.readInternal(in);
    mergePolicy = in.readObject();
    int size = in.readInt();
    mergingEntries = new ArrayList<ScheduledExecutorMergeTypes>(size);
    for (int i = 0; i < size; i++) {
        ScheduledExecutorMergeTypes mergingEntry = in.readObject();
        mergingEntries.add(mergingEntry);
    }
}
Also used : ScheduledExecutorMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes.ScheduledExecutorMergeTypes)

Example 4 with ScheduledExecutorMergeTypes

use of com.hazelcast.spi.merge.SplitBrainMergeTypes.ScheduledExecutorMergeTypes in project hazelcast by hazelcast.

the class MergeOperation method writeInternal.

@Override
protected void writeInternal(ObjectDataOutput out) throws IOException {
    super.writeInternal(out);
    out.writeObject(mergePolicy);
    out.writeInt(mergingEntries.size());
    for (ScheduledExecutorMergeTypes mergingEntry : mergingEntries) {
        out.writeObject(mergingEntry);
    }
}
Also used : ScheduledExecutorMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes.ScheduledExecutorMergeTypes)

Aggregations

ScheduledExecutorMergeTypes (com.hazelcast.spi.merge.SplitBrainMergeTypes.ScheduledExecutorMergeTypes)4 SerializationService (com.hazelcast.internal.serialization.SerializationService)1 ScheduledExecutorContainer (com.hazelcast.scheduledexecutor.impl.ScheduledExecutorContainer)1 ScheduledTaskDescriptor (com.hazelcast.scheduledexecutor.impl.ScheduledTaskDescriptor)1 ScheduledExecutorMergingEntryImpl (com.hazelcast.spi.impl.merge.ScheduledExecutorMergingEntryImpl)1