Example usage for com.amazonaws.services.kinesis.model ShardIteratorType fromValue

List of usage examples for com.amazonaws.services.kinesis.model ShardIteratorType fromValue

Introduction

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

Prototype

public static ShardIteratorType fromValue(String value) 

Source Link

Document

Use this in place of valueOf.

Usage

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

License:Apache License

@Override
public GetShardIteratorResult getShardIterator(GetShardIteratorRequest getShardIteratorRequest) {
    ShardIteratorType shardIteratorType = ShardIteratorType
            .fromValue(getShardIteratorRequest.getShardIteratorType());

    String shardIterator;/*from   ww w.j av  a 2s. c o m*/
    if (shardIteratorType == ShardIteratorType.TRIM_HORIZON) {
        shardIterator = String.format("%s:%s", getShardIteratorRequest.getShardId(), 0);
    } else {
        throw new RuntimeException("Not implemented");
    }

    return new GetShardIteratorResult().withShardIterator(shardIterator);
}

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

License:Apache License

public ShardCheckpoint(String streamName, String shardId, StartingPoint startingPoint) {
    this(streamName, shardId, ShardIteratorType.fromValue(startingPoint.getPositionName()),
            startingPoint.getTimestamp());
}

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

License:Apache License

public PositionInShard(String streamName, String shardId, InitialPositionInStream initialPositionInStream) {

    this(streamName, shardId, ShardIteratorType.fromValue(initialPositionInStream.name()), null);
}

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

License:Apache License

/**
 * Validates the shards at the given startingPoint. Validity is checked by getting an iterator at
 * the startingPoint and then trying to read some records. This action does not affect the records
 * at all. If the shard is valid then it will get read from exactly the same point and these
 * records will be read again.// w w w . j  av  a 2  s.  c o  m
 */
private Set<Shard> validateShards(SimplifiedKinesisClient kinesis, Iterable<Shard> rootShards,
        String streamName, StartingPoint startingPoint) throws TransientKinesisException {
    Set<Shard> validShards = new HashSet<>();
    ShardIteratorType shardIteratorType = ShardIteratorType.fromValue(startingPoint.getPositionName());
    for (Shard shard : rootShards) {
        String shardIterator = kinesis.getShardIterator(streamName, shard.getShardId(), shardIteratorType, null,
                startingPoint.getTimestamp());
        GetKinesisRecordsResult records = kinesis.getRecords(shardIterator, streamName, shard.getShardId());
        if (records.getNextShardIterator() != null || !records.getRecords().isEmpty()) {
            validShards.add(shard);
        }
    }
    return validShards;
}

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

License:Apache License

/**
 * {@inheritDoc}//from   ww w .  ja  va2 s .c  o 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);
}