Java Code Examples for org.apache.spark.streaming.api.java.JavaStreamingContext.ssc()

The following are Jave code examples for showing how to use ssc() of the org.apache.spark.streaming.api.java.JavaStreamingContext class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: beam   File: SparkUnboundedSource.java   Source Code and License Vote up 4 votes
public static <T, CheckpointMarkT extends CheckpointMark> UnboundedDataset<T> read(
    JavaStreamingContext jssc,
    SerializablePipelineOptions rc,
    UnboundedSource<T, CheckpointMarkT> source,
    String stepName) {

  SparkPipelineOptions options = rc.get().as(SparkPipelineOptions.class);
  Long maxRecordsPerBatch = options.getMaxRecordsPerBatch();
  SourceDStream<T, CheckpointMarkT> sourceDStream =
      new SourceDStream<>(jssc.ssc(), source, rc, maxRecordsPerBatch);

  JavaPairInputDStream<Source<T>, CheckpointMarkT> inputDStream =
      JavaPairInputDStream$.MODULE$.fromInputDStream(sourceDStream,
          JavaSparkContext$.MODULE$.<Source<T>>fakeClassTag(),
              JavaSparkContext$.MODULE$.<CheckpointMarkT>fakeClassTag());

  // call mapWithState to read from a checkpointable sources.
  JavaMapWithStateDStream<Source<T>, CheckpointMarkT, Tuple2<byte[], Instant>,
      Tuple2<Iterable<byte[]>, Metadata>> mapWithStateDStream =
      inputDStream.mapWithState(
          StateSpec
              .function(StateSpecFunctions.<T, CheckpointMarkT>mapSourceFunction(rc, stepName))
              .numPartitions(sourceDStream.getNumPartitions()));

  // set checkpoint duration for read stream, if set.
  checkpointStream(mapWithStateDStream, options);

  // report the number of input elements for this InputDStream to the InputInfoTracker.
  int id = inputDStream.inputDStream().id();
  JavaDStream<Metadata> metadataDStream = mapWithStateDStream.map(new Tuple2MetadataFunction());

  // register ReadReportDStream to report information related to this read.
  new ReadReportDStream(metadataDStream.dstream(), id, getSourceName(source, id), stepName)
      .register();

  // output the actual (deserialized) stream.
  WindowedValue.FullWindowedValueCoder<T> coder =
      WindowedValue.FullWindowedValueCoder.of(
          source.getOutputCoder(),
          GlobalWindow.Coder.INSTANCE);
  JavaDStream<WindowedValue<T>> readUnboundedStream =
      mapWithStateDStream
          .flatMap(new Tuple2byteFlatMapFunction())
          .map(CoderHelpers.fromByteFunction(coder));
  return new UnboundedDataset<>(readUnboundedStream, Collections.singletonList(id));
}
 
Example 2
Project: Spark-PubSub   File: PubsubInputDStream.java   Source Code and License Vote up 4 votes
public PubsubInputDStream(final JavaStreamingContext _jssc, final String _subscription, final Integer _batchSize,
		final boolean _decodeData) {
	super(_jssc.ssc(), new PubsubReceiver(_subscription, _batchSize, _decodeData), STRING_CLASS_TAG);
}
 
Example 3
Project: laughing-octo-sansa   File: FacebookUtils.java   Source Code and License Vote up 4 votes
public static ReceiverInputDStream<String> createStream(JavaStreamingContext jssc, String accessToken,
        BatchRequestBuilder[] batchRequestBuilders) {
    return new FacebookInputDStream(jssc.ssc(), accessToken, batchRequestBuilders, StorageLevel.MEMORY_AND_DISK_2());
}