|
8 | 8 | import org.apache.flink.streaming.api.windowing.time.Time; |
9 | 9 | import org.apache.flink.util.Collector; |
10 | 10 |
|
11 | | -/** |
12 | | - * @author JavaEdge |
13 | | - * |
14 | | - * @date 2019-07-23 |
15 | | - */ |
16 | 11 | public class JavaWindowsReduceApp { |
17 | 12 |
|
18 | 13 | public static void main(String[] args) throws Exception { |
19 | 14 | StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); |
20 | | - DataStreamSource<String> text = env.socketTextStream("localhost",9999); |
| 15 | + DataStreamSource<String> text = env.socketTextStream("localhost", 9999); |
21 | 16 |
|
22 | | - text.flatMap(new FlatMapFunction<String, Tuple2<Integer,Integer>>() { |
23 | | - @Override |
24 | | - public void flatMap(String value, Collector<Tuple2<Integer, Integer>> out) throws Exception { |
25 | | - String[] tokens = value.toLowerCase().split(","); |
26 | | - for(String token : tokens) { |
27 | | - if(token.length() > 0) { |
28 | | - out.collect(new Tuple2<>(1, Integer.parseInt(token))); |
| 17 | + text.flatMap(new FlatMapFunction<String, Tuple2<Integer, Integer>>() { |
| 18 | + @Override |
| 19 | + public void flatMap(String value, Collector<Tuple2<Integer, Integer>> out) throws Exception { |
| 20 | + String[] tokens = value.toLowerCase().split(","); |
| 21 | + for (String token : tokens) { |
| 22 | + if (token.length() > 0) { |
| 23 | + out.collect(new Tuple2<>(1, Integer.parseInt(token))); |
| 24 | + } |
| 25 | + } |
29 | 26 | } |
30 | | - } |
31 | | - } |
32 | | - }).keyBy(0) |
| 27 | + }).keyBy(0) |
33 | 28 | .timeWindow(Time.seconds(5)) |
34 | 29 | .reduce(new ReduceFunction<Tuple2<Integer, Integer>>() { |
35 | 30 | @Override |
|
0 commit comments