Search in sources :

Example 1 with RingbufferMergeData

use of com.hazelcast.spi.merge.RingbufferMergeData in project hazelcast by hazelcast.

the class MergeOperation method setRingbufferData.

/**
 * Sets the ringbuffer data given by the {@code fromMergeData} to the
 * {@code toContainer}.
 *
 * @param fromMergeData the data which needs to be set into the containter
 * @param toContainer   the target ringbuffer container
 */
private void setRingbufferData(RingbufferMergeData fromMergeData, RingbufferContainer<Object, Object> toContainer) {
    boolean storeEnabled = toContainer.getStore().isEnabled();
    Data[] storeItems = storeEnabled ? new Data[fromMergeData.size()] : null;
    toContainer.setHeadSequence(fromMergeData.getHeadSequence());
    toContainer.setTailSequence(fromMergeData.getTailSequence());
    for (long seq = fromMergeData.getHeadSequence(); seq <= fromMergeData.getTailSequence(); seq++) {
        final Object resultValue = fromMergeData.read(seq);
        toContainer.set(seq, resultValue);
        if (storeEnabled) {
            storeItems[(int) (seq - fromMergeData.getHeadSequence())] = serializationService.toData(resultValue);
        }
    }
    if (storeEnabled) {
        toContainer.getStore().storeAll(fromMergeData.getHeadSequence(), storeItems);
    }
}
Also used : RingbufferMergeData(com.hazelcast.spi.merge.RingbufferMergeData) Data(com.hazelcast.internal.serialization.Data) IOUtil.readObject(com.hazelcast.internal.nio.IOUtil.readObject) IOUtil.writeObject(com.hazelcast.internal.nio.IOUtil.writeObject)

Example 2 with RingbufferMergeData

use of com.hazelcast.spi.merge.RingbufferMergeData in project hazelcast by hazelcast.

the class MergeOperation method merge.

/**
 * Merges the provided {@code mergingValue} into the {@code existingContainer}
 * and returns the merged ringbuffer.
 *
 * @param existingContainer the container into which to merge the data
 * @param mergingValue      the data to merge
 * @return the merged ringbuffer
 */
private Ringbuffer<Object> merge(RingbufferContainer<Object, Object> existingContainer, RingbufferMergeTypes mergingValue) {
    RingbufferMergeTypes existingValue = createMergingValueOrNull(existingContainer);
    RingbufferMergeData resultData = mergePolicy.merge(mergingValue, existingValue);
    if (resultData == null) {
        ringbufferService.destroyDistributedObject(namespace.getObjectName());
        return null;
    } else {
        if (existingContainer == null) {
            RingbufferConfig config = getRingbufferConfig(ringbufferService, namespace);
            existingContainer = ringbufferService.getOrCreateContainer(getPartitionId(), namespace, config);
        }
        setRingbufferData(resultData, existingContainer);
        return existingContainer.getRingbuffer();
    }
}
Also used : RingbufferMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes.RingbufferMergeTypes) RingbufferMergeData(com.hazelcast.spi.merge.RingbufferMergeData) RingbufferConfig(com.hazelcast.config.RingbufferConfig)

Example 3 with RingbufferMergeData

use of com.hazelcast.spi.merge.RingbufferMergeData in project hazelcast by hazelcast.

the class RingbufferMergingValueImpl method readData.

@Override
public void readData(ObjectDataInput in) throws IOException {
    final long tailSequence = in.readLong();
    final long headSequence = in.readLong();
    final int capacity = in.readInt();
    value = new RingbufferMergeData(capacity);
    value.setTailSequence(tailSequence);
    value.setHeadSequence(headSequence);
    for (long seq = headSequence; seq <= tailSequence; seq++) {
        value.set(seq, readObject(in));
    }
}
Also used : RingbufferMergeData(com.hazelcast.spi.merge.RingbufferMergeData)

Example 4 with RingbufferMergeData

use of com.hazelcast.spi.merge.RingbufferMergeData in project hazelcast by hazelcast.

the class RingbufferMergingValueImpl method getValue.

@Override
public RingbufferMergeData getValue() {
    final RingbufferMergeData deserializedValues = new RingbufferMergeData(value.getItems().length);
    deserializedValues.setHeadSequence(value.getHeadSequence());
    deserializedValues.setTailSequence(value.getTailSequence());
    for (long seq = value.getHeadSequence(); seq <= value.getTailSequence(); seq++) {
        deserializedValues.set(seq, serializationService.toObject(value.read(seq)));
    }
    return deserializedValues;
}
Also used : RingbufferMergeData(com.hazelcast.spi.merge.RingbufferMergeData)

Example 5 with RingbufferMergeData

use of com.hazelcast.spi.merge.RingbufferMergeData in project hazelcast by hazelcast.

the class MergeOperation method run.

@Override
public void run() throws Exception {
    RingbufferContainer<Object, Object> existingContainer = ringbufferService.getContainerOrNull(getPartitionId(), namespace);
    RingbufferMergeTypes mergingValue = createMergingValue(serializationService, mergingRingbuffer);
    mergePolicy = (SplitBrainMergePolicy<RingbufferMergeData, RingbufferMergeTypes, RingbufferMergeData>) serializationService.getManagedContext().initialize(mergePolicy);
    resultRingbuffer = merge(existingContainer, mergingValue);
}
Also used : RingbufferMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes.RingbufferMergeTypes) RingbufferMergeData(com.hazelcast.spi.merge.RingbufferMergeData) IOUtil.readObject(com.hazelcast.internal.nio.IOUtil.readObject) IOUtil.writeObject(com.hazelcast.internal.nio.IOUtil.writeObject)

Aggregations

RingbufferMergeData (com.hazelcast.spi.merge.RingbufferMergeData)6 IOUtil.readObject (com.hazelcast.internal.nio.IOUtil.readObject)2 IOUtil.writeObject (com.hazelcast.internal.nio.IOUtil.writeObject)2 RingbufferMergeTypes (com.hazelcast.spi.merge.SplitBrainMergeTypes.RingbufferMergeTypes)2 RingbufferConfig (com.hazelcast.config.RingbufferConfig)1 Data (com.hazelcast.internal.serialization.Data)1