Commit c257a5dc authored by efikalti's avatar efikalti
Browse files

LAM-21 added comments explaining the process

parent a54ff743
...@@ -16,17 +16,21 @@ public class TagCount { ...@@ -16,17 +16,21 @@ public class TagCount {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
//read input message from port 9999 of host and send it to the splitter class
DataStream<Tuple2<String, Integer>> dataStream = env DataStream<Tuple2<String, Integer>> dataStream = env
.socketTextStream("0.0.0.0", 9999) .socketTextStream("0.0.0.0", 9999)
.flatMap(new Splitter()) .flatMap(new Splitter())
.groupBy(0) .groupBy(0)
.sum(1); .sum(1);
//dataStream.writeAsText("/tmp/streaming_output"); //write results to this file
dataStream.print(); dataStream.writeAsText("/root/streaming_output");
//run the process
env.execute("Socket Stream WordCount"); env.execute("Socket Stream WordCount");
} }
//receives the messages, splits it between the words and the hashtags and then emits each hashtag and number of appearence
public static class Splitter implements FlatMapFunction<String, Tuple2<String, Integer>> { public static class Splitter implements FlatMapFunction<String, Tuple2<String, Integer>> {
public void flatMap(String sentence, Collector<Tuple2<String, Integer>> out) throws Exception { public void flatMap(String sentence, Collector<Tuple2<String, Integer>> out) throws Exception {
String words[] = sentence.split(","); String words[] = sentence.split(",");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment