/* Populate the appropriate variables from the given args */
String streamName = args[0];
String endpointUrl = args[1];
/* Set the batch interval to a fixed 2000 millis (2 seconds) */
Duration batchInterval = new Duration(2000);
/* Create a Kinesis client in order to determine the number of shards for the given stream */
AmazonKinesisClient kinesisClient = new AmazonKinesisClient(
new DefaultAWSCredentialsProviderChain());
kinesisClient.setEndpoint(endpointUrl);
/* Determine the number of shards from the stream */
int numShards = kinesisClient.describeStream(streamName)
.getStreamDescription().getShards().size();
/* In this example, we're going to create 1 Kinesis Worker/Receiver/DStream for each shard */
int numStreams = numShards;
/* Setup the Spark config. */
SparkConf sparkConfig = new SparkConf().setAppName("KinesisWordCount");
/* Kinesis checkpoint interval. Same as batchInterval for this example. */
Duration checkpointInterval = batchInterval;
/* Setup the StreamingContext */
JavaStreamingContext jssc = new JavaStreamingContext(sparkConfig, batchInterval);
/* Create the same number of Kinesis DStreams/Receivers as Kinesis stream's shards */