/*
*
* Copyright 2016 jshook
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* /
*/
package io.nosqlbench.engine.api.activityimpl.marker;
import io.nosqlbench.engine.api.activityapi.core.Activity;
import io.nosqlbench.engine.api.activityapi.cyclelog.buffers.results.CycleResult;
import io.nosqlbench.engine.api.activityapi.cyclelog.buffers.results.CycleResultsIntervalSegment;
import io.nosqlbench.engine.api.activityapi.cyclelog.buffers.results.CycleResultsSegment;
import io.nosqlbench.engine.api.activityapi.output.Output;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
/**
* This is the default cycle output implementation for NB when
* the input cycles are known to be contiguous.
*
* This cycle marker wraps another tracking structure in order to
* allow for flexible buffering methods. The extents are buffer segments
* which can be managed atomically. They are chained here in two chains:
* The marking chain and the tracking chain. When the atomic marking head
* is non-null, then marking is possible, but marking calls block otherwise.
* The same is true for the tracking head element.
*
* The nowMarking and nowTracking conditions are meant to be locked and awaited
* by marking and tracking calls respectively. Conversely, they are expected
* to be signaled by tracking and marking calls.
*
* This implementation needs to be adapted to onAfterOpStop early exit of either
* marker or tracker threads with no deadlock.
*/
public class ContiguousOutputChunker implements Output {
private final static Logger logger = LogManager.getLogger(ContiguousOutputChunker.class);
private final int extentSize;
private final int maxExtents;
private final List