Example usage for com.amazonaws.services.kinesis.model GetShardIteratorRequest setStartingSequenceNumber

List of usage examples for com.amazonaws.services.kinesis.model GetShardIteratorRequest setStartingSequenceNumber

Introduction

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

Prototype


public void setStartingSequenceNumber(String startingSequenceNumber) 

Source Link

Document

The sequence number of the data record in the shard from which to start reading.

Usage

From source file:com.datatorrent.contrib.kinesis.KinesisUtil.java

License:Open Source License

/**
 * Get the records from the particular shard
 * @param streamName Name of the stream from where the records to be accessed
 * @param recordsLimit Number of records to return from shard
 * @param shId Shard Id of the shard//from   w ww  . j a v a 2  s .  co m
 * @param iteratorType Shard iterator type
 * @param seqNo Record sequence number
 * @return the list of records from the given shard
 * @throws AmazonClientException
 */
public List<Record> getRecords(String streamName, Integer recordsLimit, Shard shId,
        ShardIteratorType iteratorType, String seqNo) throws AmazonClientException {
    assert client != null : "Illegal client";
    try {
        // Create the GetShardIteratorRequest instance and sets streamName, shardId and iteratorType to it
        GetShardIteratorRequest iteratorRequest = new GetShardIteratorRequest();
        iteratorRequest.setStreamName(streamName);
        iteratorRequest.setShardId(shId.getShardId());
        iteratorRequest.setShardIteratorType(iteratorType);

        // If the iteratorType is AFTER_SEQUENCE_NUMBER, set the sequence No to the iteratorRequest
        if (ShardIteratorType.AFTER_SEQUENCE_NUMBER.equals(iteratorType))
            iteratorRequest.setStartingSequenceNumber(seqNo);

        // Get the Response from the getShardIterator service method & get the shardIterator from that response
        GetShardIteratorResult iteratorResponse = client.getShardIterator(iteratorRequest);
        // getShardIterator() specifies the position in the shard
        String iterator = iteratorResponse.getShardIterator();

        // Create the GetRecordsRequest instance and set the recordsLimit and iterator
        GetRecordsRequest getRequest = new GetRecordsRequest();
        getRequest.setLimit(recordsLimit);
        getRequest.setShardIterator(iterator);

        // Get the Response from the getRecords service method and get the data records from that response.
        GetRecordsResult getResponse = client.getRecords(getRequest);
        return getResponse.getRecords();
    } catch (AmazonClientException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.trulia.stail.Stail.java

License:Apache License

private static String getShardIteratorAtSequenceNumber(AmazonKinesis client, String stream, Shard shard,
        String sequenceNumber) {/*from   www .  j av  a  2 s  .  c om*/
    GetShardIteratorRequest getShardIteratorRequest = new GetShardIteratorRequest();
    getShardIteratorRequest.setStreamName(stream);
    getShardIteratorRequest.setShardId(shard.getShardId());

    getShardIteratorRequest.setShardIteratorType(ShardIteratorType.AT_SEQUENCE_NUMBER);
    getShardIteratorRequest.setStartingSequenceNumber(sequenceNumber);

    GetShardIteratorResult getShardIteratorResult = client.getShardIterator(getShardIteratorRequest);
    return getShardIteratorResult.getShardIterator();
}

From source file:dbtucker.connect.kinesis.KinesisSourceTask.java

License:Apache License

private GetShardIteratorRequest getShardIteratorRequest(String shardId, String streamName, String seqNum) {
    final GetShardIteratorRequest req = new GetShardIteratorRequest();
    req.setShardId(shardId);/*w  w w  .  j  ava 2  s. co m*/
    req.setStreamName(streamName);
    if (seqNum == null) {
        req.setShardIteratorType(ShardIteratorType.TRIM_HORIZON);
    } else {
        req.setShardIteratorType(ShardIteratorType.AFTER_SEQUENCE_NUMBER);
        req.setStartingSequenceNumber(seqNum);
    }
    return req;
}

From source file:org.apache.apex.malhar.contrib.kinesis.KinesisUtil.java

License:Apache License

/**
 * Get the records from the particular shard
 * @param streamName Name of the stream from where the records to be accessed
 * @param recordsLimit Number of records to return from shard
 * @param shId Shard Id of the shard//from  w  w w.ja v a 2  s . com
 * @param iteratorType Shard iterator type
 * @param seqNo Record sequence number
 * @return the list of records from the given shard
 * @throws AmazonClientException
 */
public List<Record> getRecords(String streamName, Integer recordsLimit, String shId,
        ShardIteratorType iteratorType, String seqNo) throws AmazonClientException {
    assert client != null : "Illegal client";
    try {
        // Create the GetShardIteratorRequest instance and sets streamName, shardId and iteratorType to it
        GetShardIteratorRequest iteratorRequest = new GetShardIteratorRequest();
        iteratorRequest.setStreamName(streamName);
        iteratorRequest.setShardId(shId);
        iteratorRequest.setShardIteratorType(iteratorType);

        // If the iteratorType is AFTER_SEQUENCE_NUMBER, set the sequence No to the iteratorRequest
        if (ShardIteratorType.AFTER_SEQUENCE_NUMBER.equals(iteratorType)
                || ShardIteratorType.AT_SEQUENCE_NUMBER.equals(iteratorType)) {
            iteratorRequest.setStartingSequenceNumber(seqNo);
        }
        // Get the Response from the getShardIterator service method & get the shardIterator from that response
        GetShardIteratorResult iteratorResponse = client.getShardIterator(iteratorRequest);
        // getShardIterator() specifies the position in the shard
        String iterator = iteratorResponse.getShardIterator();

        // Create the GetRecordsRequest instance and set the recordsLimit and iterator
        GetRecordsRequest getRequest = new GetRecordsRequest();
        getRequest.setLimit(recordsLimit);
        getRequest.setShardIterator(iterator);

        // Get the Response from the getRecords service method and get the data records from that response.
        GetRecordsResult getResponse = client.getRecords(getRequest);
        return getResponse.getRecords();
    } catch (AmazonClientException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxy.java

License:Apache License

/**
 * {@inheritDoc}//from   w  w w. ja va2s  .co m
 */
@Override
public String getShardIterator(KinesisStreamShard shard, String shardIteratorType,
        @Nullable Object startingMarker) throws InterruptedException {
    GetShardIteratorRequest getShardIteratorRequest = new GetShardIteratorRequest()
            .withStreamName(shard.getStreamName()).withShardId(shard.getShard().getShardId())
            .withShardIteratorType(shardIteratorType);

    switch (ShardIteratorType.fromValue(shardIteratorType)) {
    case TRIM_HORIZON:
    case LATEST:
        break;
    case AT_TIMESTAMP:
        if (startingMarker instanceof Date) {
            getShardIteratorRequest.setTimestamp((Date) startingMarker);
        } else {
            throw new IllegalArgumentException(
                    "Invalid object given for GetShardIteratorRequest() when ShardIteratorType is AT_TIMESTAMP. Must be a Date object.");
        }
        break;
    case AT_SEQUENCE_NUMBER:
    case AFTER_SEQUENCE_NUMBER:
        if (startingMarker instanceof String) {
            getShardIteratorRequest.setStartingSequenceNumber((String) startingMarker);
        } else {
            throw new IllegalArgumentException(
                    "Invalid object given for GetShardIteratorRequest() when ShardIteratorType is AT_SEQUENCE_NUMBER or AFTER_SEQUENCE_NUMBER. Must be a String.");
        }
    }
    return getShardIterator(getShardIteratorRequest);
}

From source file:org.apache.storm.kinesis.spout.KinesisConnection.java

License:Apache License

String getShardIterator(String stream, String shardId, ShardIteratorType shardIteratorType,
        String sequenceNumber, Date timestamp) {
    String shardIterator = "";
    try {//  www.  j av  a 2s.  c o  m
        GetShardIteratorRequest getShardIteratorRequest = new GetShardIteratorRequest();
        getShardIteratorRequest.setStreamName(stream);
        getShardIteratorRequest.setShardId(shardId);
        getShardIteratorRequest.setShardIteratorType(shardIteratorType);
        if (shardIteratorType.equals(ShardIteratorType.AFTER_SEQUENCE_NUMBER)
                || shardIteratorType.equals(ShardIteratorType.AT_SEQUENCE_NUMBER)) {
            getShardIteratorRequest.setStartingSequenceNumber(sequenceNumber);
        } else if (shardIteratorType.equals(ShardIteratorType.AT_TIMESTAMP)) {
            getShardIteratorRequest.setTimestamp(timestamp);
        }
        GetShardIteratorResult getShardIteratorResult = kinesisClient.getShardIterator(getShardIteratorRequest);
        if (getShardIteratorResult != null) {
            shardIterator = getShardIteratorResult.getShardIterator();
        }
    } catch (Exception e) {
        LOG.warn(
                "Exception occured while getting shardIterator for shard " + shardId + " shardIteratorType "
                        + shardIteratorType + " sequence number " + sequenceNumber + " timestamp " + timestamp,
                e);
    }
    LOG.warn("Returning shardIterator " + shardIterator + " for shardId " + shardId + " shardIteratorType "
            + shardIteratorType + " sequenceNumber " + sequenceNumber + " timestamp" + timestamp);
    return shardIterator;
}