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