Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Flink中禁用onTimer on KeyedProcessFunction_Java_Apache Flink_Flink Streaming_Flink Cep - Fatal编程技术网

Java 在Flink中禁用onTimer on KeyedProcessFunction

Java 在Flink中禁用onTimer on KeyedProcessFunction,java,apache-flink,flink-streaming,flink-cep,Java,Apache Flink,Flink Streaming,Flink Cep,以此为例: 我在KeyedProcessFunction中被称为onTimer函数,基于以下概念: (当a==“start”->ctx.timerService().RegisterProcessingTimer(长时间内的某个时间)时) 但随着这一概念的出现,一项新的记录也随之诞生,这意味着旅程的结束: (当a==“end”->ctx.timerService().RegisterProcessingTimer(ctx.timerService().currentProcessingTime(

以此为例:

我在
KeyedProcessFunction
中被称为
onTimer
函数,基于以下概念:

(当a==“start”->ctx.timerService().RegisterProcessingTimer(长时间内的某个时间)时)

但随着这一概念的出现,一项新的记录也随之诞生,这意味着旅程的结束:

(当a==“end”->ctx.timerService().RegisterProcessingTimer(ctx.timerService().currentProcessingTime();)时)

第二个计时器立即触发动作,其目的是清理之前设置的计时器,因为我感觉不到前一个计时器保持活动状态

关键是,如果动作二没有在一小时内发生,例如,我需要做一些事情
(ctx.timerService().registerProcessingTimer(一段时间内))
,但是,如果预期值在该小时内到达,则无需立即触发计时器或触发计时器并忘记在
(ctx.timerService().registerProcessingTimer(ctx.timerService().currentProcessingTime();)
)之前编程的另一个计时器,但我遇到了问题,因为无论发生什么情况,计时器都会被触发,上一个计时器也已触发

我会尝试使用
ctx.timerService().deleteProcessingTimer(很长一段时间)但它似乎不起作用

请参见示例:

事件顺序:事件A总是在事件B之前到达。 说明:事件B必须在事件a到达后一小时内到达,否则计时器将在a到达后一小时触发,但如果B在计时器设置为一小时后到达,则计时器应立即触发,并且决不能调用(删除)定义的前一个计时器

SingleOutputStreamOperator放弃=stream.keyBy(e->e.id)
.process(新的KeyedProcessFunctionName());
公共类keyedProcessFunctionName扩展KeyedProcessFunction{
@凌驾
公共void processElement(事件e、上下文ctx、收集器输出)引发异常{
如果(例如,值相等信号情况(“B”)){
{
ctx.timerService().RegisterProcessingTimer(ctx.timerService().currentProcessingTime());
}
if(stateTow2.value()==null&&e.value.equalsIgnoreCase(“A”)){
ctx.timerService().RegisterProcessingTimer(ctx.timerService().currentProcessingTime()+一些固定的时间长度);
}
}
}
@凌驾
public void onTimer(长时间戳、OnTimerContext ctx、收集器输出)引发异常{
/*当由于B而调用此计时器时,不得因为a而设置的前一个计时器而调用此计时器*/
}
}
有什么想法吗?

计时器总是(隐式)绑定到一个键。创建计时器时,它与正在处理的事件的键(或当前触发的计时器的键)相关联。类似地,您只能删除与当前上下文中的键关联的计时器。如果删除计时器似乎不起作用,也许这就是原因

另一个需要记住的事实是计时器是重复数据消除的。换句话说,对于任何给定的(键、时间戳)对,最多可以有一个事件时间计时器和一个处理时间计时器。随后为同一密钥和时间戳注册另一个计时器的尝试将被忽略


有时,使用keyed state来记住当计时器(针对同一个键)触发时应该做什么是很有帮助的。如果每个键有多个计时器,可以使用时间戳索引的
MapState
为每个计时器保留一些状态。

我在这一行之后为问题添加了一个示例:参见示例:请让我知道我现在是否更清楚我需要做什么。福林克训练练习中有一个涵盖了这个用例。看见提供了一种解决方案。
 SingleOutputStreamOperator<Events> abandonment = stream.keyBy(e -> e.id)
.process(new KeyedProcessFunctionName());


public class KeyedProcessFunctionNameextends KeyedProcessFunction<String, Event, Event> {

@Override
    public void processElement(Event e, Context ctx, Collector<Event> out) throws Exception {
        if (e.value.equalsIgnoreCase("B")) {
{
ctx.timerService().registerProcessingTimeTimer(ctx.timerService().currentProcessingTime());
        }

        if (stateTwo.value() == null && e.value.equalsIgnoreCase("A")) {
ctx.timerService().registerProcessingTimeTimer(ctx.timerService().currentProcessingTime() + SOME_FIXED_TIME_IN_LONG);
        }
}

}


@Override
    public void onTimer(long timestamp, OnTimerContext ctx, Collector<Event> out) throws Exception {

/*when this timer is been called because of B it must not been called because of a previous timer set because of A*/
}
}