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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Counter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidprocessRecord(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>usesStates()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Method Detail
-
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(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
-
-