use of org.apache.apex.malhar.lib.window.WindowState in project apex-malhar by apache.
the class AbstractWindowedOperator method fireTimeTriggers.
private void fireTimeTriggers() {
if (earlyTriggerMillis > 0 || lateTriggerMillis > 0) {
for (Map.Entry<Window, WindowState> entry : windowStateMap.entries()) {
Window window = entry.getKey();
WindowState windowState = entry.getValue();
if (windowState.watermarkArrivalTime == -1) {
if (earlyTriggerMillis > 0 && windowState.lastTriggerFiredTime + earlyTriggerMillis <= currentDerivedTimestamp) {
// fire early time triggers
fireTrigger(window, windowState);
}
} else {
if (lateTriggerMillis > 0 && windowState.lastTriggerFiredTime + lateTriggerMillis <= currentDerivedTimestamp) {
// fire late time triggers
fireTrigger(window, windowState);
}
}
}
}
}
use of org.apache.apex.malhar.lib.window.WindowState in project apex-malhar by apache.
the class AbstractWindowedOperator method processWatermarkAtEndWindow.
protected void processWatermarkAtEndWindow() {
long implicitWatermark = -1;
if (implicitWatermarkGenerator != null) {
implicitWatermark = implicitWatermarkGenerator.getWatermarkTuple(currentDerivedTimestamp).getTimestamp();
}
if (implicitWatermark > nextWatermark) {
nextWatermark = implicitWatermark;
}
if (nextWatermark > 0 && currentWatermark < nextWatermark) {
long horizon = nextWatermark - allowedLatenessMillis;
for (Iterator<Map.Entry<Window, WindowState>> it = windowStateMap.entries().iterator(); it.hasNext(); ) {
Map.Entry<Window, WindowState> entry = it.next();
Window window = entry.getKey();
WindowState windowState = entry.getValue();
if (window.getBeginTimestamp() + window.getDurationMillis() < nextWatermark) {
// watermark has not arrived for this window before, marking this window late
if (windowState.watermarkArrivalTime == -1) {
windowState.watermarkArrivalTime = currentDerivedTimestamp;
if (triggerAtWatermark) {
// fire trigger at watermark if applicable
fireTrigger(window, windowState);
}
}
if (allowedLatenessMillis >= 0 && window.getBeginTimestamp() + window.getDurationMillis() < horizon) {
// discard this window because it's too late now
it.remove();
dataStorage.remove(window);
if (retractionStorage != null) {
retractionStorage.remove(window);
}
}
}
}
streamingWindowToLatenessHorizon.put(streamingWindowId, horizon);
controlOutput.emit(new WatermarkImpl(nextWatermark));
this.currentWatermark = nextWatermark;
}
}
use of org.apache.apex.malhar.lib.window.WindowState in project apex-malhar by apache.
the class AbstractWindowedOperator method processWindowState.
protected void processWindowState(Tuple.WindowedTuple<? extends Object> windowedTuple) {
for (Window window : windowedTuple.getWindows()) {
WindowState windowState = windowStateMap.get(window);
windowState.tupleCount++;
// process any count based triggers
if (windowState.watermarkArrivalTime == -1) {
// watermark has not arrived yet, check for early count based trigger
if (earlyTriggerCount > 0 && (windowState.tupleCount % earlyTriggerCount) == 0) {
fireTrigger(window, windowState);
}
} else {
// watermark has arrived, check for late count based trigger
if (lateTriggerCount > 0 && (windowState.tupleCount % lateTriggerCount) == 0) {
fireTrigger(window, windowState);
}
}
}
}
use of org.apache.apex.malhar.lib.window.WindowState in project apex-malhar by apache.
the class AbstractWindowedOperator method setup.
@Override
@SuppressWarnings("unchecked")
public void setup(Context.OperatorContext context) {
this.timeIncrement = context.getValue(Context.OperatorContext.APPLICATION_WINDOW_COUNT) * context.getValue(Context.DAGContext.STREAMING_WINDOW_SIZE_MILLIS);
validate();
windowStateMap.setup(context);
dataStorage.setup(context);
if (retractionStorage != null) {
retractionStorage.setup(context);
}
if (implicitWatermarkGenerator != null) {
implicitWatermarkGenerator.setup(context);
}
for (Component component : components.values()) {
component.setup(context);
}
if (this.windowOption instanceof WindowOption.GlobalWindow) {
windowStateMap.put(Window.GlobalWindow.INSTANCE, new WindowState());
}
}
use of org.apache.apex.malhar.lib.window.WindowState in project apex-malhar by apache.
the class KeyedWindowedMergeOperatorTestApplication method assignTestWindow.
public static Window.TimeWindow assignTestWindow(long timestamp) {
long beginTimestamp = timestamp - timestamp % windowDuration;
Window.TimeWindow window = new Window.TimeWindow(beginTimestamp, windowDuration);
if (!windowStateMap.containsWindow(window)) {
windowStateMap.put(window, new WindowState());
}
return window;
}
Aggregations