Class CountNewsClicks.CountNewsClicksProcessFunction
java.lang.Object
org.apache.flink.streaming.examples.dsv2.eventtime.CountNewsClicks.CountNewsClicksProcessFunction
- All Implemented Interfaces:
Serializable,org.apache.flink.api.common.functions.Function,org.apache.flink.datastream.api.extension.eventtime.function.EventTimeProcessFunction,org.apache.flink.datastream.api.extension.eventtime.function.OneInputEventTimeStreamProcessFunction<CountNewsClicks.NewsEvent,,CountNewsClicks.NewsClicks> org.apache.flink.datastream.api.function.OneInputStreamProcessFunction<CountNewsClicks.NewsEvent,,CountNewsClicks.NewsClicks> org.apache.flink.datastream.api.function.ProcessFunction
- Enclosing class:
- CountNewsClicks
public static class CountNewsClicks.CountNewsClicksProcessFunction
extends Object
implements org.apache.flink.datastream.api.extension.eventtime.function.OneInputEventTimeStreamProcessFunction<CountNewsClicks.NewsEvent,CountNewsClicks.NewsClicks>
This process function will consume
CountNewsClicks.NewsEvent and count the number of clicks within 1
hour of the news publication and send the results CountNewsClicks.NewsClicks to the output.
To achieve the goal, we will register an event timer for each news, which will be
triggered at the time of the news's release time + 1 hour, and record a click count of each
news. In the timer callback onEventTimer, we will output the number of clicks.
To handle the potential disorder between news publication event and click events, we will use a ListState to store the timestamps of click events that occur prior to their corresponding publication events.
To handle the potential missing news publication event, we will register an event timer for the click event and set the timer to the timestamp of the click event plus one hour.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidinitEventTimeProcessFunction(org.apache.flink.datastream.api.extension.eventtime.timer.EventTimeManager eventTimeManager) voidonEventTimer(long timestamp, org.apache.flink.datastream.api.common.Collector<CountNewsClicks.NewsClicks> output, org.apache.flink.datastream.api.context.PartitionedContext<CountNewsClicks.NewsClicks> ctx) voidprocessRecord(CountNewsClicks.NewsEvent record, org.apache.flink.datastream.api.common.Collector<CountNewsClicks.NewsClicks> output, org.apache.flink.datastream.api.context.PartitionedContext<CountNewsClicks.NewsClicks> ctx) Set<org.apache.flink.api.common.state.StateDeclaration>Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.flink.datastream.api.extension.eventtime.function.OneInputEventTimeStreamProcessFunction
onEventTimeWatermarkMethods inherited from interface org.apache.flink.datastream.api.function.OneInputStreamProcessFunction
endInput, onProcessingTimer, onWatermark, openMethods inherited from interface org.apache.flink.datastream.api.function.ProcessFunction
close, declareWatermarks
-
Constructor Details
-
CountNewsClicksProcessFunction
public CountNewsClicksProcessFunction()
-
-
Method Details
-
initEventTimeProcessFunction
public void initEventTimeProcessFunction(org.apache.flink.datastream.api.extension.eventtime.timer.EventTimeManager eventTimeManager) - Specified by:
initEventTimeProcessFunctionin interfaceorg.apache.flink.datastream.api.extension.eventtime.function.EventTimeProcessFunction
-
usesStates
- Specified by:
usesStatesin interfaceorg.apache.flink.datastream.api.function.ProcessFunction
-
processRecord
public void processRecord(CountNewsClicks.NewsEvent record, org.apache.flink.datastream.api.common.Collector<CountNewsClicks.NewsClicks> output, org.apache.flink.datastream.api.context.PartitionedContext<CountNewsClicks.NewsClicks> ctx) throws Exception - Specified by:
processRecordin interfaceorg.apache.flink.datastream.api.function.OneInputStreamProcessFunction<CountNewsClicks.NewsEvent,CountNewsClicks.NewsClicks> - Throws:
Exception
-
onEventTimer
public void onEventTimer(long timestamp, org.apache.flink.datastream.api.common.Collector<CountNewsClicks.NewsClicks> output, org.apache.flink.datastream.api.context.PartitionedContext<CountNewsClicks.NewsClicks> ctx) throws Exception - Specified by:
onEventTimerin interfaceorg.apache.flink.datastream.api.extension.eventtime.function.OneInputEventTimeStreamProcessFunction<CountNewsClicks.NewsEvent,CountNewsClicks.NewsClicks> - Throws:
Exception
-