本文整理匯總了Java中org.apache.spark.streaming.api.java.JavaStreamingContext.close方法的典型用法代碼示例。如果您正苦於以下問題:Java JavaStreamingContext.close方法的具體用法?Java JavaStreamingContext.close怎麽用?Java JavaStreamingContext.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.spark.streaming.api.java.JavaStreamingContext
的用法示例。
在下文中一共展示了JavaStreamingContext.close方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: closeTheValidation
import org.apache.spark.streaming.api.java.JavaStreamingContext; //導入方法依賴的package包/類
protected void closeTheValidation(JavaStreamingContext ssc, ExecutorService executor, final int nbOfMessages,
NatsPublisher np) throws InterruptedException {
ssc.start();
Thread.sleep(1000);
// start the publisher
executor.execute(np);
np.waitUntilReady();
Thread.sleep(500);
ssc.close();
Thread.sleep(500);
assertTrue("Not a single RDD did received messages.", atLeastSomeData);
assertTrue("Not the right number of messages have been received", rightNumber);
assertEquals(nbOfMessages, TOTAL_COUNT.get());
assertNull("'" + payload + " should be '" + NatsPublisher.NATS_PAYLOAD + "'", payload);
}
示例2: networkWordCount
import org.apache.spark.streaming.api.java.JavaStreamingContext; //導入方法依賴的package包/類
private static final void networkWordCount() {
/* StreamingContext with two threads and batch interval of 1 second */
final SparkConf conf = new SparkConf().setMaster("local[2]").setAppName("NetworkWordCount");
final JavaStreamingContext jssc = new JavaStreamingContext(conf, Durations.seconds(1));
/* Create a DStream that will connect to localhost:9999 */
final JavaReceiverInputDStream<String> lines = jssc.socketTextStream("localhost", 9999);
/* Split each line into words */
final JavaDStream<String> words = lines.flatMap(new FlatMapFunction<String, String>() {
private static final long serialVersionUID = 1L;
@Override
public final Iterable<String> call(final String x) {
return Arrays.asList(x.split(" "));
}
});
/* Count each word in each batch */
final JavaPairDStream<String, Integer> pairs = words.mapToPair(new PairFunction<String, String, Integer>() {
private static final long serialVersionUID = 1L;
@Override
public final Tuple2<String, Integer> call(final String s) {
return new Tuple2<String, Integer>(s, 1);
}
});
final JavaPairDStream<String, Integer> wordCounts = pairs.reduceByKey(new Function2<Integer, Integer, Integer>() {
private static final long serialVersionUID = 1L;
@Override
public final Integer call(final Integer i1, final Integer i2) {
return i1 + i2;
}
});
/* Print the first ten elements of each RDD generated in this DStream to the console */
wordCounts.print();
jssc.start(); // Start the computation
jssc.awaitTermination(); // Wait for the computation to terminate
if (jssc != null) {
jssc.close();
}
}