Example usage for org.apache.spark.api.java.function Function0 Function0

List of usage examples for org.apache.spark.api.java.function Function0 Function0

Introduction

In this page you can find the example usage for org.apache.spark.api.java.function Function0 Function0.

Prototype

Function0

Source Link

Usage

From source file:com.andado.spark.examples.streaming.JavaWordBlacklist.java

License:Apache License

public static void main(String[] args) throws Exception {
    if (args.length != 4) {
        System.err.println("You arguments were " + Arrays.asList(args));
        System.err.println("Usage: JavaRecoverableNetworkWordCount <hostname> <port> <checkpoint-directory>\n"
                + "     <output-file>. <hostname> and <port> describe the TCP server that Spark\n"
                + "     Streaming would connect to receive data. <checkpoint-directory> directory to\n"
                + "     HDFS-compatible file system which checkpoint data <output-file> file to which\n"
                + "     the word counts will be appended\n" + "\n"
                + "In local mode, <master> should be 'local[n]' with n > 1\n"
                + "Both <checkpoint-directory> and <output-file> must be absolute paths");
        System.exit(1);//from   www. jav  a 2s .co m
    }

    final String ip = args[0];
    final int port = Integer.parseInt(args[1]);
    final String checkpointDirectory = args[2];
    final String outputPath = args[3];

    // Function to create JavaStreamingContext without any output operations
    // (used to detect the new context)
    Function0<JavaStreamingContext> createContextFunc = new Function0<JavaStreamingContext>() {
        @Override
        public JavaStreamingContext call() {
            return createContext(ip, port, checkpointDirectory, outputPath);
        }
    };

    JavaStreamingContext ssc = JavaStreamingContext.getOrCreate(checkpointDirectory, createContextFunc);
    ssc.start();
    ssc.awaitTermination();
}