首页 > 解决方案 > 从 Flink 中的 ProcessWindowFunction 的上下文中获取 Collector 对象

问题描述

我在 ProcessWindowFunction 的clear步骤中模仿 TTL 缓存失效,并尝试以 clear 方法访问进程中使用的收集器对象。是否可以使用ContextgetRuntimeContext获得它。

public class TimedProcess extends ProcessWindowFunction<Map<String, List<String>>, Map<String, List<String>>, String , TimeWindow> {

    Map<String, List<String>> cachedValue;

    @Override
    public void clear(Context context) throws Exception {
        // How to get output used in process function here

        // Collector<Map<String, List<String>>> output = ?

        // Map<String, List<String> recentCacheValue;
        // output.collect(recentCacheValue)

    }

    @Override
    public void process(String visitorId, Context context, Iterable<Map<String, List<String>>> input, Collector<Map<String, List<String>>> output) throws Exception {

         // cache store logic
         // output.collect(cachedValue);
    }

}

标签: javastreamingapache-flink

解决方案


推荐阅读