Example usage for com.amazonaws.services.kinesis.model GetRecordsResult setNextShardIterator

List of usage examples for com.amazonaws.services.kinesis.model GetRecordsResult setNextShardIterator

Introduction

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

Prototype


public void setNextShardIterator(String nextShardIterator) 

Source Link

Document

The next position in the shard from which 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.");
    }/*from www.java2  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;
}