Search in sources :

Example 1 with WindowState

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);
                }
            }
        }
    }
}
Also used : Window(org.apache.apex.malhar.lib.window.Window) WindowState(org.apache.apex.malhar.lib.window.WindowState) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 2 with 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;
    }
}
Also used : Window(org.apache.apex.malhar.lib.window.Window) WindowState(org.apache.apex.malhar.lib.window.WindowState) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 3 with WindowState

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);
            }
        }
    }
}
Also used : Window(org.apache.apex.malhar.lib.window.Window) WindowState(org.apache.apex.malhar.lib.window.WindowState)

Example 4 with 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());
    }
}
Also used : WindowState(org.apache.apex.malhar.lib.window.WindowState) Component(com.datatorrent.api.Component)

Example 5 with 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;
}
Also used : Window(org.apache.apex.malhar.lib.window.Window) WindowState(org.apache.apex.malhar.lib.window.WindowState)

Aggregations

WindowState (org.apache.apex.malhar.lib.window.WindowState)10 Window (org.apache.apex.malhar.lib.window.Window)5 ConsoleOutputOperator (org.apache.apex.malhar.lib.io.ConsoleOutputOperator)3 WindowOption (org.apache.apex.malhar.lib.window.WindowOption)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 KeyedWindowedOperatorImpl (org.apache.apex.malhar.lib.window.impl.KeyedWindowedOperatorImpl)2 Component (com.datatorrent.api.Component)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 List (java.util.List)1 PubSubWebSocketAppDataQuery (org.apache.apex.malhar.lib.io.PubSubWebSocketAppDataQuery)1 PubSubWebSocketAppDataResult (org.apache.apex.malhar.lib.io.PubSubWebSocketAppDataResult)1 SumAccumulation (org.apache.apex.malhar.lib.window.SumAccumulation)1 TriggerOption (org.apache.apex.malhar.lib.window.TriggerOption)1 WindowedStorage (org.apache.apex.malhar.lib.window.WindowedStorage)1 PojoInnerJoin (org.apache.apex.malhar.lib.window.accumulation.PojoInnerJoin)1 SumDouble (org.apache.apex.malhar.lib.window.accumulation.SumDouble)1