Search in sources :

Example 1 with WindowManager

use of org.apache.storm.windowing.WindowManager in project storm by apache.

the class WindowedBoltExecutor method initWindowManager.

private WindowManager<Tuple> initWindowManager(WindowLifecycleListener<Tuple> lifecycleListener, Map stormConf, TopologyContext context) {
    WindowManager<Tuple> manager = new WindowManager<>(lifecycleListener);
    Duration windowLengthDuration = null;
    Count windowLengthCount = null;
    Duration slidingIntervalDuration = null;
    Count slidingIntervalCount = null;
    // window length
    if (stormConf.containsKey(Config.TOPOLOGY_BOLTS_WINDOW_LENGTH_COUNT)) {
        windowLengthCount = new Count(((Number) stormConf.get(Config.TOPOLOGY_BOLTS_WINDOW_LENGTH_COUNT)).intValue());
    } else if (stormConf.containsKey(Config.TOPOLOGY_BOLTS_WINDOW_LENGTH_DURATION_MS)) {
        windowLengthDuration = new Duration(((Number) stormConf.get(Config.TOPOLOGY_BOLTS_WINDOW_LENGTH_DURATION_MS)).intValue(), TimeUnit.MILLISECONDS);
    }
    // sliding interval
    if (stormConf.containsKey(Config.TOPOLOGY_BOLTS_SLIDING_INTERVAL_COUNT)) {
        slidingIntervalCount = new Count(((Number) stormConf.get(Config.TOPOLOGY_BOLTS_SLIDING_INTERVAL_COUNT)).intValue());
    } else if (stormConf.containsKey(Config.TOPOLOGY_BOLTS_SLIDING_INTERVAL_DURATION_MS)) {
        slidingIntervalDuration = new Duration(((Number) stormConf.get(Config.TOPOLOGY_BOLTS_SLIDING_INTERVAL_DURATION_MS)).intValue(), TimeUnit.MILLISECONDS);
    } else {
        // default is a sliding window of count 1
        slidingIntervalCount = new Count(1);
    }
    // tuple ts
    if (timestampExtractor != null) {
        // late tuple stream
        lateTupleStream = (String) stormConf.get(Config.TOPOLOGY_BOLTS_LATE_TUPLE_STREAM);
        if (lateTupleStream != null) {
            if (!context.getThisStreams().contains(lateTupleStream)) {
                throw new IllegalArgumentException("Stream for late tuples must be defined with the builder method withLateTupleStream");
            }
        }
        // max lag
        if (stormConf.containsKey(Config.TOPOLOGY_BOLTS_TUPLE_TIMESTAMP_MAX_LAG_MS)) {
            maxLagMs = ((Number) stormConf.get(Config.TOPOLOGY_BOLTS_TUPLE_TIMESTAMP_MAX_LAG_MS)).intValue();
        } else {
            maxLagMs = DEFAULT_MAX_LAG_MS;
        }
        // watermark interval
        int watermarkInterval;
        if (stormConf.containsKey(Config.TOPOLOGY_BOLTS_WATERMARK_EVENT_INTERVAL_MS)) {
            watermarkInterval = ((Number) stormConf.get(Config.TOPOLOGY_BOLTS_WATERMARK_EVENT_INTERVAL_MS)).intValue();
        } else {
            watermarkInterval = DEFAULT_WATERMARK_EVENT_INTERVAL_MS;
        }
        waterMarkEventGenerator = new WaterMarkEventGenerator<>(manager, watermarkInterval, maxLagMs, getComponentStreams(context));
    } else {
        if (stormConf.containsKey(Config.TOPOLOGY_BOLTS_LATE_TUPLE_STREAM)) {
            throw new IllegalArgumentException("Late tuple stream can be defined only when specifying a timestamp field");
        }
    }
    // validate
    validate(stormConf, windowLengthCount, windowLengthDuration, slidingIntervalCount, slidingIntervalDuration);
    evictionPolicy = getEvictionPolicy(windowLengthCount, windowLengthDuration, manager);
    triggerPolicy = getTriggerPolicy(slidingIntervalCount, slidingIntervalDuration, manager, evictionPolicy);
    manager.setEvictionPolicy(evictionPolicy);
    manager.setTriggerPolicy(triggerPolicy);
    return manager;
}
Also used : Duration(org.apache.storm.topology.base.BaseWindowedBolt.Duration) Count(org.apache.storm.topology.base.BaseWindowedBolt.Count) Tuple(org.apache.storm.tuple.Tuple) WindowManager(org.apache.storm.windowing.WindowManager)

Aggregations

Count (org.apache.storm.topology.base.BaseWindowedBolt.Count)1 Duration (org.apache.storm.topology.base.BaseWindowedBolt.Duration)1 Tuple (org.apache.storm.tuple.Tuple)1 WindowManager (org.apache.storm.windowing.WindowManager)1