Java Code Examples for com.amazonaws.services.kinesis.model.ShardIteratorType#fromValue()
The following examples show how to use
com.amazonaws.services.kinesis.model.ShardIteratorType#fromValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StartingPointShardsFinder.java From beam with Apache License 2.0 | 6 votes |
/** * 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. */ 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; }
Example 2
Source File: KinesisProxy.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public String getShardIterator(StreamShardHandle 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); }
Example 3
Source File: KinesisProxy.java From flink with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public String getShardIterator(StreamShardHandle 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); }
Example 4
Source File: ShardCheckpoint.java From beam with Apache License 2.0 | 5 votes |
public ShardCheckpoint(String streamName, String shardId, StartingPoint startingPoint) { this( streamName, shardId, ShardIteratorType.fromValue(startingPoint.getPositionName()), startingPoint.getTimestamp()); }
Example 5
Source File: AmazonKinesisMock.java From beam with Apache License 2.0 | 5 votes |
@Override public GetShardIteratorResult getShardIterator(GetShardIteratorRequest getShardIteratorRequest) { ShardIteratorType shardIteratorType = ShardIteratorType.fromValue(getShardIteratorRequest.getShardIteratorType()); String shardIterator; if (shardIteratorType == ShardIteratorType.TRIM_HORIZON) { shardIterator = String.format("%s:%s", getShardIteratorRequest.getShardId(), 0); } else { throw new RuntimeException("Not implemented"); } return new GetShardIteratorResult().withShardIterator(shardIterator); }
Example 6
Source File: KinesisProxy.java From flink with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public String getShardIterator(StreamShardHandle 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); }