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


Java DescribeStreamRequest.setExclusiveStartShardId方法代码示例

本文整理汇总了Java中com.amazonaws.services.kinesis.model.DescribeStreamRequest.setExclusiveStartShardId方法的典型用法代码示例。如果您正苦于以下问题:Java DescribeStreamRequest.setExclusiveStartShardId方法的具体用法?Java DescribeStreamRequest.setExclusiveStartShardId怎么用?Java DescribeStreamRequest.setExclusiveStartShardId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.kinesis.model.DescribeStreamRequest的用法示例。


在下文中一共展示了DescribeStreamRequest.setExclusiveStartShardId方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: refreshShards

import com.amazonaws.services.kinesis.model.DescribeStreamRequest; //导入方法依赖的package包/类
private void refreshShards() {
  DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest();
  describeStreamRequest.setStreamName(streamName);
  String exclusiveStartShardId = null;
  List<Shard> shards = new ArrayList<>();

  do {
    describeStreamRequest.setExclusiveStartShardId(exclusiveStartShardId);
    DescribeStreamResult describeStreamResult = kinesisClient.describeStream(describeStreamRequest);
    shards.addAll(describeStreamResult.getStreamDescription().getShards());

    if (describeStreamResult.getStreamDescription().getHasMoreShards() && shards.size() > 0) {
      exclusiveStartShardId = shards.get(shards.size() - 1).getShardId();
    } else {
      exclusiveStartShardId = null;
    }
  } while (exclusiveStartShardId != null);

  this.shards = shards;
}
 
开发者ID:awslabs,项目名称:flink-stream-processing-refarch,代码行数:21,代码来源:WatermarkTracker.java

示例2: getStreamDescription

import com.amazonaws.services.kinesis.model.DescribeStreamRequest; //导入方法依赖的package包/类
/**
 * Internal method to retrieve the stream description and get the shards from AWS.
 *
 * Gets from the internal cache unless not yet created or too old.
 *
 * @param streamName
 * @return
 */
protected InternalStreamDescription getStreamDescription(String streamName)
{
    InternalStreamDescription desc = this.streamMap.get(streamName);
    if (desc == null || System.currentTimeMillis() - desc.getCreateTimeStamp() >= MAX_CACHE_AGE_MILLIS) {
        desc = new InternalStreamDescription(streamName);

        DescribeStreamRequest describeStreamRequest = clientManager.getDescribeStreamRequest();
        describeStreamRequest.setStreamName(streamName);

        // Collect shards from Kinesis
        String exclusiveStartShardId = null;
        List<Shard> shards = new ArrayList<>();
        do {
            describeStreamRequest.setExclusiveStartShardId(exclusiveStartShardId);
            DescribeStreamResult describeStreamResult = clientManager.getClient().describeStream(describeStreamRequest);

            String streamStatus = describeStreamResult.getStreamDescription().getStreamStatus();
            if (!streamStatus.equals("ACTIVE") && !streamStatus.equals("UPDATING")) {
                throw new ResourceNotFoundException("Stream not Active");
            }

            desc.addAllShards(describeStreamResult.getStreamDescription().getShards());

            if (describeStreamResult.getStreamDescription().getHasMoreShards() && (shards.size() > 0)) {
                exclusiveStartShardId = shards.get(shards.size() - 1).getShardId();
            }
            else {
                exclusiveStartShardId = null;
            }
        } while (exclusiveStartShardId != null);

        this.streamMap.put(streamName, desc);
    }

    return desc;
}
 
开发者ID:qubole,项目名称:presto-kinesis,代码行数:45,代码来源:KinesisSplitManager.java

示例3: describeStream

import com.amazonaws.services.kinesis.model.DescribeStreamRequest; //导入方法依赖的package包/类
/**
 * Get metainfo for a Kinesis stream, which contains information about which shards this Kinesis stream possess.
 *
 * <p>This method is using a "full jitter" approach described in AWS's article,
 * <a href="https://www.awsarchitectureblog.com/2015/03/backoff.html">"Exponential Backoff and Jitter"</a>.
 * This is necessary because concurrent calls will be made by all parallel subtask's fetcher. This
 * jitter backoff approach will help distribute calls across the fetchers over time.
 *
 * @param streamName the stream to describe
 * @param startShardId which shard to start with for this describe operation (earlier shard's infos will not appear in result)
 * @return the result of the describe stream operation
 */
private DescribeStreamResult describeStream(String streamName, @Nullable String startShardId) throws InterruptedException {
	final DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest();
	describeStreamRequest.setStreamName(streamName);
	describeStreamRequest.setExclusiveStartShardId(startShardId);

	DescribeStreamResult describeStreamResult = null;

	// Call DescribeStream, with full-jitter backoff (if we get LimitExceededException).
	int attemptCount = 0;
	while (describeStreamResult == null) { // retry until we get a result
		try {
			describeStreamResult = kinesisClient.describeStream(describeStreamRequest);
		} catch (LimitExceededException le) {
			long backoffMillis = fullJitterBackoff(
				describeStreamBaseBackoffMillis, describeStreamMaxBackoffMillis, describeStreamExpConstant, attemptCount++);
			LOG.warn("Got LimitExceededException when describing stream " + streamName + ". Backing off for "
				+ backoffMillis + " millis.");
			Thread.sleep(backoffMillis);
		} catch (ResourceNotFoundException re) {
			throw new RuntimeException("Error while getting stream details", re);
		}
	}

	String streamStatus = describeStreamResult.getStreamDescription().getStreamStatus();
	if (!(streamStatus.equals(StreamStatus.ACTIVE.toString()) || streamStatus.equals(StreamStatus.UPDATING.toString()))) {
		if (LOG.isWarnEnabled()) {
			LOG.warn("The status of stream " + streamName + " is " + streamStatus + "; result of the current " +
				"describeStream operation will not contain any shard information.");
		}
	}

	// Kinesalite (mock implementation of Kinesis) does not correctly exclude shards before the exclusive
	// start shard id in the returned shards list; check if we need to remove these erroneously returned shards
	if (startShardId != null) {
		List<Shard> shards = describeStreamResult.getStreamDescription().getShards();
		Iterator<Shard> shardItr = shards.iterator();
		while (shardItr.hasNext()) {
			if (StreamShardHandle.compareShardIds(shardItr.next().getShardId(), startShardId) <= 0) {
				shardItr.remove();
			}
		}
	}

	return describeStreamResult;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:58,代码来源:KinesisProxy.java

示例4: describeStream

import com.amazonaws.services.kinesis.model.DescribeStreamRequest; //导入方法依赖的package包/类
/**
 * Get metainfo for a Kinesis stream, which contains information about which shards this Kinesis stream possess.
 *
 * This method is using a "full jitter" approach described in AWS's article,
 * <a href="https://www.awsarchitectureblog.com/2015/03/backoff.html">"Exponential Backoff and Jitter"</a>.
 * This is necessary because concurrent calls will be made by all parallel subtask's fetcher. This
 * jitter backoff approach will help distribute calls across the fetchers over time.
 *
 * @param streamName the stream to describe
 * @param startShardId which shard to start with for this describe operation (earlier shard's infos will not appear in result)
 * @return the result of the describe stream operation
 */
private DescribeStreamResult describeStream(String streamName, @Nullable String startShardId) throws InterruptedException {
	final DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest();
	describeStreamRequest.setStreamName(streamName);
	describeStreamRequest.setExclusiveStartShardId(startShardId);

	DescribeStreamResult describeStreamResult = null;

	// Call DescribeStream, with full-jitter backoff (if we get LimitExceededException).
	int attemptCount = 0;
	while (describeStreamResult == null) { // retry until we get a result
		try {
			describeStreamResult = kinesisClient.describeStream(describeStreamRequest);
		} catch (LimitExceededException le) {
			long backoffMillis = fullJitterBackoff(
				describeStreamBaseBackoffMillis, describeStreamMaxBackoffMillis, describeStreamExpConstant, attemptCount++);
			LOG.warn("Got LimitExceededException when describing stream " + streamName + ". Backing off for "
				+ backoffMillis + " millis.");
			Thread.sleep(backoffMillis);
		} catch (ResourceNotFoundException re) {
			throw new RuntimeException("Error while getting stream details", re);
		}
	}

	String streamStatus = describeStreamResult.getStreamDescription().getStreamStatus();
	if (!(streamStatus.equals(StreamStatus.ACTIVE.toString()) || streamStatus.equals(StreamStatus.UPDATING.toString()))) {
		if (LOG.isWarnEnabled()) {
			LOG.warn("The status of stream " + streamName + " is " + streamStatus + "; result of the current " +
				"describeStream operation will not contain any shard information.");
		}
	}

	// Kinesalite (mock implementation of Kinesis) does not correctly exclude shards before the exclusive
	// start shard id in the returned shards list; check if we need to remove these erroneously returned shards
	if (startShardId != null) {
		List<Shard> shards = describeStreamResult.getStreamDescription().getShards();
		Iterator<Shard> shardItr = shards.iterator();
		while (shardItr.hasNext()) {
			if (KinesisStreamShard.compareShardIds(shardItr.next().getShardId(), startShardId) <= 0) {
				shardItr.remove();
			}
		}
	}

	return describeStreamResult;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:58,代码来源:KinesisProxy.java

示例5: main

import com.amazonaws.services.kinesis.model.DescribeStreamRequest; //导入方法依赖的package包/类
public static void main(String[] args) {
	AmazonKinesisClient kinesisClient = Helper.setupKinesisClient();

	// Retrieve the Shards from a Stream
	DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest();
	describeStreamRequest.setStreamName(Helper.properties().getProperty("kinesisStreamName"));
	DescribeStreamResult describeStreamResult;
	List<Shard> shards = new ArrayList<>();
	String lastShardId = null;

	do {
	    describeStreamRequest.setExclusiveStartShardId(lastShardId);
	    describeStreamResult = kinesisClient.describeStream(describeStreamRequest);
	    shards.addAll(describeStreamResult.getStreamDescription().getShards());
	    if (shards.size() > 0) {
	        lastShardId = shards.get(shards.size() - 1).getShardId();
	    }
	} while (describeStreamResult.getStreamDescription().getHasMoreShards());

	// Get Data from the Shards in a Stream
	// Hard-coded to use only 1 shard
	String shardIterator;
	GetShardIteratorRequest getShardIteratorRequest = new GetShardIteratorRequest();
	getShardIteratorRequest.setStreamName(Helper.properties().getProperty("kinesisStreamName"));
	getShardIteratorRequest.setShardId(shards.get(0).getShardId());
	getShardIteratorRequest.setShardIteratorType("TRIM_HORIZON");

	GetShardIteratorResult getShardIteratorResult = kinesisClient.getShardIterator(getShardIteratorRequest);
	shardIterator = getShardIteratorResult.getShardIterator();

	// Continuously read data records from shard.
	List<Record> records;
	while (true) {
		// Create new GetRecordsRequest with existing shardIterator.
		// Set maximum records to return to 1000.
		GetRecordsRequest getRecordsRequest = new GetRecordsRequest();
		getRecordsRequest.setShardIterator(shardIterator);
		getRecordsRequest.setLimit(1000);

		GetRecordsResult result = kinesisClient.getRecords(getRecordsRequest);

		// Put result into record list. Result may be empty.
		records = result.getRecords();

		// Print records
		for (Record record : records) {
			ByteBuffer byteBuffer = record.getData();
			System.out.println(String.format("Seq No: %s - %s", record.getSequenceNumber(),
					new String(byteBuffer.array())));
		}

		try {
			Thread.sleep(1000);
		} catch (InterruptedException exception) {
			throw new RuntimeException(exception);
		}

		shardIterator = result.getNextShardIterator();
	}
}
 
开发者ID:twitterdev,项目名称:twttr-kinesis,代码行数:61,代码来源:TweetProcessor.java


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