KeyedProcessFunction 继承 AbstractRichFunction 函数
Function为基础函数接口,为纯接口里面没有方法
RichFunction 继承基础接口Function
里面封装了到了运行环境函数,open和close 方法
还有得到迭代运行时间内容
public abstract class KeyedProcessFunction<K, I, O> extends AbstractRichFunction {
private static final long serialVersionUID = 1L;
/**
* Process one element from the input stream.
*
* <p>This function can output zero or more elements using the {@link Collector} parameter
* and also update internal state or set timers using the {@link Context} parameter.
*
* @param value The input value.
* @param ctx A {@link Context} that allows querying the timestamp of the element and getting
* a {@link TimerService} for registering timers and querying the time. The
* context is only valid during the invocation of this method, do not store it.
* @param out The collector for returning result values.
*
* @throws Exception This method may throw exceptions. Throwing an exception will cause the operation
* to fail and may trigger recovery.
*/
/*
Value 为输入的数据
Context 可以查询元素的时间戳,并获得一个定时器服务用来注册定时器和查询时间。
Collector 为收集输出数据
*/
public abstract void processElement(I value, Context ctx, Collector<O> out) throws Exception;
/**
* Called when a timer set using {@link TimerService} fires.
*
* @param timestamp The timestamp of the firing timer.
* @param ctx An {@link OnTimerContext} that allows querying the timestamp, the {@link TimeDomain}, and the key
* of the firing timer and getting a {@link TimerService} for registering timers and querying the time.
* The context is only valid during the invocation of this method, do not store it.
* @param out The collector for returning result values.
*
* @throws Exception This method may throw exceptions. Throwing an exception will cause the operation
* to fail and may trigger recovery.
*/
/*
当一个定时器被设置开启时候调用
timestamp 开启的定时器的时间戳
ctx 这个对象允许查询时间戳 和得到一个定时器服务来注册timers 来查询时间 和上面的processElement 的ctx一样
out 输出结果
*/
public void onTimer(long timestamp, OnTimerContext ctx, Collector<O> out) throws Exception {}
/**
* Information available in an invocation of {@link #processElement(Object, Context, Collector)}
* or {@link #onTimer(long, OnTimerContext, Collector)}.
*/
/**
*
在调用processElement和onTimer时会用到
*/
public abstract class Context {
/**
* Timestamp of the element currently being processed or timestamp of a firing timer.
*
* <p>This might be {@code null}, for example if the time characteristic of your program
* is set to {@link org.apache.flink.streaming.api.TimeCharacteristic#ProcessingTime}.
*/
/*
当前被处理的元素元素的时间戳或者一个开启timer的时间戳
例如你的时间特性可以设置为TimeCharacteristic.ProcessingTime
*/
public abstract Long timestamp();
/**
* A {@link TimerService} for querying time and registering timers.
*/
/*定时服务器用来查询时间和注册timers
*/
public abstract TimerService timerService();
/*定时服务器用来查询时间和注册timers
*/
public abstract <X> void output(OutputTag<X> outputTag, X value);
/**
* Get key of the element being processed.
*/
/*得到元素正在被处理的key
*/
public abstract K getCurrentKey();
}
/**
* Information available in an invocation of {@link #onTimer(long, OnTimerContext, Collector)}.
*/
/*
调用onTimer时可以用
*/
public abstract class OnTimerContext extends Context {
/**
* The {@link TimeDomain} of the firing timer.
*/
/*
触发计时器的TimeDomain*/
public abstract TimeDomain timeDomain();
/**
* Get key of the firing timer.
*/
@Override
/*
得到触发计时器的key
*/
public abstract K getCurrentKey();
}
}