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 consumeCountNewsClicks.NewsEventand count the number of clicks within 1 hour of the news publication and send the resultsCountNewsClicks.NewsClicksto 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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CountNewsClicksProcessFunction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidinitEventTimeProcessFunction(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>usesStates()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.flink.datastream.api.extension.eventtime.function.OneInputEventTimeStreamProcessFunction
onEventTimeWatermark
-
-
-
-
Method Detail
-
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
public Set<org.apache.flink.api.common.state.StateDeclaration> 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
-
-