本文整理汇总了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();
}
}