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 Details

    • CountNewsClicksProcessFunction

      public CountNewsClicksProcessFunction()
  • Method Details

    • initEventTimeProcessFunction

      public void initEventTimeProcessFunction(org.apache.flink.datastream.api.extension.eventtime.timer.EventTimeManager eventTimeManager)
      Specified by:
      initEventTimeProcessFunction in interface org.apache.flink.datastream.api.extension.eventtime.function.EventTimeProcessFunction
    • usesStates

      public Set<org.apache.flink.api.common.state.StateDeclaration> usesStates()
      Specified by:
      usesStates in interface org.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:
      processRecord in interface org.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:
      onEventTimer in interface org.apache.flink.datastream.api.extension.eventtime.function.OneInputEventTimeStreamProcessFunction<CountNewsClicks.NewsEvent,CountNewsClicks.NewsClicks>
      Throws:
      Exception