Example usage for com.amazonaws.services.kinesis.model GetRecordsRequest getShardIterator

List of usage examples for com.amazonaws.services.kinesis.model GetRecordsRequest getShardIterator

Introduction

In this page you can find the example usage for com.amazonaws.services.kinesis.model GetRecordsRequest getShardIterator.

Prototype


public String getShardIterator() 

Source Link

Document

The position in the shard from which you want to start sequentially reading data records.

Usage

From source file:com.facebook.presto.kinesis.util.MockKinesisClient.java

License:Apache License

@Override
public GetRecordsResult getRecords(GetRecordsRequest getRecordsRequest)
        throws AmazonServiceException, AmazonClientException {
    ShardIterator iter = ShardIterator.fromString(getRecordsRequest.getShardIterator());
    if (iter == null) {
        throw new AmazonClientException("Bad shard iterator.");
    }/*w  w  w . j a  v  a2  s  .c om*/

    // TODO: incorporate maximum batch size (getRecordsRequest.getLimit)
    GetRecordsResult result = null;
    InternalStream stream = this.getStream(iter.streamId);
    if (stream != null) {
        InternalShard shard = stream.getShards().get(iter.shardIndex);

        if (iter.recordIndex == 100) {
            result = new GetRecordsResult();
            ArrayList<Record> recs = shard.getRecords();
            result.setRecords(recs); // NOTE: getting all for now
            result.setNextShardIterator(getNextShardIterator(iter, recs).makeString());
            result.setMillisBehindLatest(100L);
        } else {
            result = new GetRecordsResult();
            ArrayList<Record> recs = shard.getRecordsFrom(iter);
            result.setRecords(recs); // may be empty
            result.setNextShardIterator(getNextShardIterator(iter, recs).makeString());
            result.setMillisBehindLatest(100L);
        }
    } else {
        throw new AmazonClientException("Unknown stream or bad shard iterator.");
    }

    return result;
}

From source file:org.apache.beam.sdk.io.kinesis.AmazonKinesisMock.java

License:Apache License

@Override
public GetRecordsResult getRecords(GetRecordsRequest getRecordsRequest) {
    List<String> shardIteratorParts = Splitter.on(':').splitToList(getRecordsRequest.getShardIterator());
    int shardId = parseInt(shardIteratorParts.get(0));
    int startingRecord = parseInt(shardIteratorParts.get(1));
    List<Record> shardData = shardedData.get(shardId);

    int toIndex = min(startingRecord + numberOfRecordsPerGet, shardData.size());
    int fromIndex = min(startingRecord, toIndex);
    return new GetRecordsResult().withRecords(shardData.subList(fromIndex, toIndex))
            .withNextShardIterator(String.format("%s:%s", shardId, toIndex)).withMillisBehindLatest(0L);
}