/*
*
* 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.engineblock.activityimpl.marker;
import io.engineblock.activityapi.Activity;
import io.engineblock.activityapi.cycletracking.buffers.results.CycleResult;
import io.engineblock.activityapi.cycletracking.buffers.results.CycleResultsIntervalSegment;
import io.engineblock.activityapi.cycletracking.buffers.results.CycleResultsSegment;
import io.engineblock.activityapi.input.ContiguousInput;
import io.engineblock.activityapi.output.Output;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 marker implementation for EngineBlock.
*
* 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 handle early exit of either
* marker or tracker threads with no deadlock.
*/
public class ReorderingContiguousOutputChunker implements Output {
private final static Logger logger = LoggerFactory.getLogger(ReorderingContiguousOutputChunker.class);
private final int extentSize;
private final int maxExtents;
private List