Class WordCount.Counter

java.lang.Object
org.apache.flink.streaming.examples.dsv2.wordcount.WordCount.Counter
All Implemented Interfaces:
Serializable, org.apache.flink.api.common.functions.Function, org.apache.flink.datastream.api.function.OneInputStreamProcessFunction<org.apache.flink.api.java.tuple.Tuple2<String,Integer>,org.apache.flink.api.java.tuple.Tuple2<String,Integer>>, org.apache.flink.datastream.api.function.ProcessFunction
Enclosing class:
WordCount

public static final class WordCount.Counter extends Object implements org.apache.flink.datastream.api.function.OneInputStreamProcessFunction<org.apache.flink.api.java.tuple.Tuple2<String,Integer>,org.apache.flink.api.java.tuple.Tuple2<String,Integer>>
Implements a word counter as a user-defined ProcessFunction that counts received words in streaming mode. The function uses a ValueState to store the count of each word, it will update the count of word and output the result when receive a record "(word,1)".

Note that this is just an example of how to code a streaming job using the DataStream API V2. It currently involves some complexity. In the future, we will provide more user-friendly APIs and extensions to simplify the process.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    processRecord(org.apache.flink.api.java.tuple.Tuple2<String,Integer> record, org.apache.flink.datastream.api.common.Collector<org.apache.flink.api.java.tuple.Tuple2<String,Integer>> output, org.apache.flink.datastream.api.context.PartitionedContext<org.apache.flink.api.java.tuple.Tuple2<String,Integer>> 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, wait

    Methods inherited from interface org.apache.flink.datastream.api.function.OneInputStreamProcessFunction

    endInput, onProcessingTimer, onWatermark, open

    Methods inherited from interface org.apache.flink.datastream.api.function.ProcessFunction

    close, declareWatermarks
  • Constructor Details

    • Counter

      public Counter()
  • Method Details

    • 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(org.apache.flink.api.java.tuple.Tuple2<String,Integer> record, org.apache.flink.datastream.api.common.Collector<org.apache.flink.api.java.tuple.Tuple2<String,Integer>> output, org.apache.flink.datastream.api.context.PartitionedContext<org.apache.flink.api.java.tuple.Tuple2<String,Integer>> ctx) throws Exception
      Specified by:
      processRecord in interface org.apache.flink.datastream.api.function.OneInputStreamProcessFunction<org.apache.flink.api.java.tuple.Tuple2<String,Integer>,org.apache.flink.api.java.tuple.Tuple2<String,Integer>>
      Throws:
      Exception