当前位置: 首页>>代码示例>>Java>>正文


Java JavaStreamingContext.close方法代码示例

本文整理汇总了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);
}
 
开发者ID:Logimethods,项目名称:nats-connector-spark,代码行数:16,代码来源:AbstractNatsToSparkTest.java

示例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();
    }
  }
 
开发者ID:inbravo,项目名称:java-feature-set,代码行数:52,代码来源:NetworkWordCount.java


注:本文中的org.apache.spark.streaming.api.java.JavaStreamingContext.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。