I'm working with Apache Flink 1.16.0 and I'm trying to trigger my window with a latency. I tried to use a Custom Trigger for that, but it doesn't work. Here is my custom trigger:
public class TriggerWithLatency extends Trigger<Object, TimeWindow> {
//delay 20 seconds
private long DELAY = 1000*60*60;
private TriggerWithLatency(long delay) {
this.DELAY = delay;
}
@Override
public TriggerResult onElement(Object o, long time, TimeWindow window, TriggerContext triggerContext) throws Exception {
long triggerTime = window.getEnd() + this.DELAY;
triggerContext.registerProcessingTimeTimer(triggerTime);
return TriggerResult.CONTINUE;
}
@Override
public TriggerResult onEventTime(long time, TimeWindow window, TriggerContext triggerContext) throws Exception {
// I don't use TumblingEventTimeWindows so I continue
return TriggerResult.CONTINUE;
}
@Override
public TriggerResult onProcessingTime(long time, TimeWindow window, TriggerContext triggerContext) throws Exception {
//It should come here with 1 hour latency, but it comes with window end time
return TriggerResult.FIRE;
}
@Override
public void clear(TimeWindow timeWindow, TriggerContext triggerContext) throws Exception {
//I clear timer
long triggerTime = timeWindow.getEnd() + this.DELAY;
triggerContext.deleteProcessingTimeTimer(triggerTime);
}
public static TriggerWithLatency create(long delay) {
return new TriggerWithLatency(delay);
}
}
Here is how I create my window
SingleOutputStreamOperator<Result> results = keyedStream
.window(TumblingProcessingTimeWindows.of(Time.hours(3)))
.trigger(TriggerWithLatency.create(1000*60*60));
After that I'm trying to use ProcessWindowFunction, there is no latency on triggering. It is triggered at the and of window. Where is the problem? Could someone help me with that?