diff --git a/flink-addons/flink-streaming/flink-streaming-examples/src/main/java/org/apache/flink/streaming/examples/socket/SocketTextStreamWordCount.java b/flink-addons/flink-streaming/flink-streaming-examples/src/main/java/org/apache/flink/streaming/examples/socket/SocketTextStreamWordCount.java
index ec32e9f41517a831def4557c6129e2e735f2e0be..e9b60f48b3cf60589185708a8b3f37870e216efa 100644
--- a/flink-addons/flink-streaming/flink-streaming-examples/src/main/java/org/apache/flink/streaming/examples/socket/SocketTextStreamWordCount.java
+++ b/flink-addons/flink-streaming/flink-streaming-examples/src/main/java/org/apache/flink/streaming/examples/socket/SocketTextStreamWordCount.java
@@ -23,11 +23,21 @@ import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.examples.wordcount.WordCount.Tokenizer;
/**
- * This example shows an implementation of WordCount with data from socket.
- *
+ * This example shows an implementation of WordCount with data from a text
+ * socket. To run the example make sure that the service providing the text data
+ * is already up and running.
+ *
*
- * Usage: SocketTextStreamWordCount <hostname> <port > <result path>
- *
+ * To start an example socket text stream on your local machine run netcat from
+ * a command line: nc -lk 9999
, where the parameter specifies the
+ * port number.
+ *
+ *
+ *
+ * Usage:
+ * SocketTextStreamWordCount <hostname> <port> <result path>
+ *
+ *
*
* This example shows how to:
*
@@ -35,6 +45,8 @@ import org.apache.flink.streaming.examples.wordcount.WordCount.Tokenizer;
* - write a simple Flink program,
*
- write and use user-defined functions.
*
+ *
+ * @see netcat
*/
public class SocketTextStreamWordCount {
public static void main(String[] args) throws Exception {
@@ -44,16 +56,18 @@ public class SocketTextStreamWordCount {
}
// set up the execution environment
- final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
+ final StreamExecutionEnvironment env = StreamExecutionEnvironment
+ .getExecutionEnvironment();
// get input data
- DataStream text = env.socketTextStream(hostname, port);
+ DataStream text = env.socketTextStream(hostName, port);
DataStream> counts =
// split up the lines in pairs (2-tuples) containing: (word,1)
text.flatMap(new Tokenizer())
// group by the tuple field "0" and sum up tuple field "1"
- .groupBy(0).sum(1);
+ .groupBy(0)
+ .sum(1);
if (fileOutput) {
counts.writeAsText(outputPath, 1);
@@ -62,7 +76,7 @@ public class SocketTextStreamWordCount {
}
// execute program
- env.execute("WordCount with SocketTextStream Example");
+ env.execute("WordCount from SocketTextStream Example");
}
// *************************************************************************
@@ -70,30 +84,23 @@ public class SocketTextStreamWordCount {
// *************************************************************************
private static boolean fileOutput = false;
- private static String hostname;
+ private static String hostName;
private static int port;
private static String outputPath;
private static boolean parseParameters(String[] args) {
- if (args.length > 0) {
- // parse input arguments
- if (args.length == 3) {
- fileOutput = true;
- hostname = args[0];
- port = Integer.valueOf(args[1]);
- outputPath = args[2];
- } else if (args.length == 2) {
- hostname = args[0];
- port = Integer.valueOf(args[1]);
- } else {
- System.err.println("Usage: SocketTextStreamWordCount