Java Code Examples for org.apache.flink.streaming.api.windowing.windows.TimeWindow#getEnd()

The following examples show how to use org.apache.flink.streaming.api.windowing.windows.TimeWindow#getEnd() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PopularPlacesSolution.java    From flink-training-exercises with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void apply(
		Tuple key,
		TimeWindow window,
		Iterable<Tuple2<Integer, Boolean>> values,
		Collector<Tuple4<Integer, Long, Boolean, Integer>> out) throws Exception {

	int cellId = ((Tuple2<Integer, Boolean>)key).f0;
	boolean isStart = ((Tuple2<Integer, Boolean>)key).f1;
	long windowTime = window.getEnd();

	int cnt = 0;
	for(Tuple2<Integer, Boolean> v : values) {
		cnt += 1;
	}

	out.collect(new Tuple4<>(cellId, windowTime, isStart, cnt));
}
 
Example 2
Source File: CustomWindow.java    From examples-java with Apache License 2.0 5 votes vote down vote up
@Override
public TriggerResult onEventTime(long ts, TimeWindow w, TriggerContext ctx) throws Exception {
    if (ts == w.getEnd()) {
        // final evaluation and purge window state
        return TriggerResult.FIRE_AND_PURGE;
    } else {
        // register next early firing timer
        long t = ctx.getCurrentWatermark() + (1000 - (ctx.getCurrentWatermark() % 1000));
        if (t < w.getEnd()) {
            ctx.registerEventTimeTimer(t);
        }
        // fire trigger to early evaluate window
        return TriggerResult.FIRE;
    }
}