Java Code Examples for org.apache.flink.streaming.connectors.kinesis.proxy.GetShardListResult#hasRetrievedShards()

The following examples show how to use org.apache.flink.streaming.connectors.kinesis.proxy.GetShardListResult#hasRetrievedShards() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KinesisDataFetcher.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * A utility function that does the following:
 *
 * <p>1. Find new shards for each stream that we haven't seen before
 * 2. For each new shard, determine whether this consumer subtask should subscribe to them;
 * 	  if yes, it is added to the returned list of shards
 * 3. Update the subscribedStreamsToLastDiscoveredShardIds state so that we won't get shards
 *    that we have already seen before the next time this function is called
 */
public List<StreamShardHandle> discoverNewShardsToSubscribe() throws InterruptedException {

	List<StreamShardHandle> newShardsToSubscribe = new LinkedList<>();

	GetShardListResult shardListResult = kinesis.getShardList(subscribedStreamsToLastDiscoveredShardIds);
	if (shardListResult.hasRetrievedShards()) {
		Set<String> streamsWithNewShards = shardListResult.getStreamsWithRetrievedShards();

		for (String stream : streamsWithNewShards) {
			List<StreamShardHandle> newShardsOfStream = shardListResult.getRetrievedShardListOfStream(stream);
			for (StreamShardHandle newShard : newShardsOfStream) {
				int hashCode = shardAssigner.assign(newShard, totalNumberOfConsumerSubtasks);
				if (isThisSubtaskShouldSubscribeTo(hashCode, totalNumberOfConsumerSubtasks, indexOfThisConsumerSubtask)) {
					newShardsToSubscribe.add(newShard);
				}
			}

			advanceLastDiscoveredShardOfStream(
				stream, shardListResult.getLastSeenShardOfStream(stream).getShard().getShardId());
		}
	}

	return newShardsToSubscribe;
}
 
Example 2
Source File: KinesisDataFetcher.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * A utility function that does the following:
 *
 * <p>1. Find new shards for each stream that we haven't seen before
 * 2. For each new shard, determine whether this consumer subtask should subscribe to them;
 * 	  if yes, it is added to the returned list of shards
 * 3. Update the subscribedStreamsToLastDiscoveredShardIds state so that we won't get shards
 *    that we have already seen before the next time this function is called
 */
public List<StreamShardHandle> discoverNewShardsToSubscribe() throws InterruptedException {

	List<StreamShardHandle> newShardsToSubscribe = new LinkedList<>();

	GetShardListResult shardListResult = kinesis.getShardList(subscribedStreamsToLastDiscoveredShardIds);
	if (shardListResult.hasRetrievedShards()) {
		Set<String> streamsWithNewShards = shardListResult.getStreamsWithRetrievedShards();

		for (String stream : streamsWithNewShards) {
			List<StreamShardHandle> newShardsOfStream = shardListResult.getRetrievedShardListOfStream(stream);
			for (StreamShardHandle newShard : newShardsOfStream) {
				int hashCode = shardAssigner.assign(newShard, totalNumberOfConsumerSubtasks);
				if (isThisSubtaskShouldSubscribeTo(hashCode, totalNumberOfConsumerSubtasks, indexOfThisConsumerSubtask)) {
					newShardsToSubscribe.add(newShard);
				}
			}

			advanceLastDiscoveredShardOfStream(
				stream, shardListResult.getLastSeenShardOfStream(stream).getShard().getShardId());
		}
	}

	return newShardsToSubscribe;
}
 
Example 3
Source File: KinesisDataFetcher.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * A utility function that does the following:
 *
 * <p>1. Find new shards for each stream that we haven't seen before
 * 2. For each new shard, determine whether this consumer subtask should subscribe to them;
 * 	  if yes, it is added to the returned list of shards
 * 3. Update the subscribedStreamsToLastDiscoveredShardIds state so that we won't get shards
 *    that we have already seen before the next time this function is called
 */
public List<StreamShardHandle> discoverNewShardsToSubscribe() throws InterruptedException {

	List<StreamShardHandle> newShardsToSubscribe = new LinkedList<>();

	GetShardListResult shardListResult = kinesis.getShardList(subscribedStreamsToLastDiscoveredShardIds);
	if (shardListResult.hasRetrievedShards()) {
		Set<String> streamsWithNewShards = shardListResult.getStreamsWithRetrievedShards();

		for (String stream : streamsWithNewShards) {
			List<StreamShardHandle> newShardsOfStream = shardListResult.getRetrievedShardListOfStream(stream);
			for (StreamShardHandle newShard : newShardsOfStream) {
				int hashCode = shardAssigner.assign(newShard, totalNumberOfConsumerSubtasks);
				if (isThisSubtaskShouldSubscribeTo(hashCode, totalNumberOfConsumerSubtasks, indexOfThisConsumerSubtask)) {
					newShardsToSubscribe.add(newShard);
				}
			}

			advanceLastDiscoveredShardOfStream(
				stream, shardListResult.getLastSeenShardOfStream(stream).getShard().getShardId());
		}
	}

	return newShardsToSubscribe;
}