我正在为我的信息流创建全局窗口,并尝试在 n 分钟内收集数据。我所做的是在自定义触发器的 onElement 函数中通过自己的逻辑实现的,因此它将在n分钟后触发窗口。但是,如果我在 t 分钟( t
代码
主要:
DataStream<EventData> dataStream =
keyedEvents.window(GlobalWindows.create())
.trigger(new ServiceWindowTrigger())
.process(new ProcessEventWindow(configData))
.name("Collection Window")
.setParallelism(25);
触发:
public class ServiceWindowTrigger extends Trigger< MonitoringConsoleData, GlobalWindow> {
@Override
public TriggerResult onElement(MonitoringConsoleData element, long timestamp, GlobalWindow window,
org.apache.flink.streaming.api.windowing.triggers.Trigger.TriggerContext ctx) throws Exception {
String key = element.getKey();
Long firstEventTime = Main.MainMap.get(key);
// Find difference between first event timestamp and current timestamp
Long diff = GlobalUtilities.getCurrentEpoch() - firstEventTime;
long diffMinutes = diff / (60 * 1000) % 60;
if(diffMinutes == 3) // Trigger after 3 minutes
{
System.out.println(diff);
System.out.println(diffMinutes);
return TriggerResult.FIRE;
}
else
{
return TriggerResult.CONTINUE;
}
}
@Override
public TriggerResult onProcessingTime(long time, GlobalWindow window,
org.apache.flink.streaming.api.windowing.triggers.Trigger.TriggerContext ctx) throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public TriggerResult onEventTime(long time, GlobalWindow window,
org.apache.flink.streaming.api.windowing.triggers.Trigger.TriggerContext ctx) throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
public void clear(GlobalWindow window, org.apache.flink.streaming.api.windowing.triggers.Trigger.TriggerContext ctx)
throws Exception {
// TODO Auto-generated method stub
}
}