com.amazonaws.services.kinesis.clientlibrary.types.ExtendedSequenceNumber Java Examples

The following examples show how to use com.amazonaws.services.kinesis.clientlibrary.types.ExtendedSequenceNumber. 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: KinesisShardCheckpointer.java    From presto with Apache License 2.0 6 votes vote down vote up
public void checkpoint(String lastReadSequenceNumber)
{
    log.info("Trying to checkpoint at " + lastReadSequenceNumber);
    try {
        ExtendedSequenceNumber esn = new ExtendedSequenceNumber(lastReadSequenceNumber);
        kinesisClientLease.setCheckpoint(esn);
        leaseManager.createLeaseIfNotExists(kinesisClientLease);
        if (!leaseManager.updateLease(kinesisClientLease)) {
            log.warn("Checkpointing unsuccessful");
        }
    }
    catch (DependencyException | InvalidStateException | ProvisionedThroughputException e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
    resetNextCheckpointTime();
}
 
Example #2
Source File: TestKinesisSystemConsumer.java    From samza with Apache License 2.0 6 votes vote down vote up
private Map<String, KinesisRecordProcessor> createAndInitProcessors(IRecordProcessorFactory factory, int numShards) {
  Map<String, KinesisRecordProcessor> processorMap = new HashMap<>();
  IntStream.range(0, numShards)
      .forEach(p -> {
        String shardId = String.format("shard-%05d", p);
        // Create Kinesis processor
        KinesisRecordProcessor processor = (KinesisRecordProcessor) factory.createProcessor();

        // Initialize the shard
        ExtendedSequenceNumber seqNum = new ExtendedSequenceNumber("0000");
        InitializationInput initializationInput =
            new InitializationInput().withShardId(shardId).withExtendedSequenceNumber(seqNum);
        processor.initialize(initializationInput);
        processorMap.put(shardId, processor);
      });
  return processorMap;
}
 
Example #3
Source File: ShardCheckpoint.java    From beam with Apache License 2.0 5 votes vote down vote up
private ExtendedSequenceNumber extendedSequenceNumber() {
  String fullSequenceNumber = sequenceNumber;
  if (fullSequenceNumber == null) {
    fullSequenceNumber = shardIteratorType.toString();
  }
  return new ExtendedSequenceNumber(fullSequenceNumber, subSequenceNumber);
}
 
Example #4
Source File: ShardCheckpointTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testComparisonWithExtendedSequenceNumber() {
  assertThat(
          new ShardCheckpoint("", "", new StartingPoint(LATEST))
              .isBeforeOrAt(recordWith(new ExtendedSequenceNumber("100", 0L))))
      .isTrue();

  assertThat(
          new ShardCheckpoint("", "", new StartingPoint(TRIM_HORIZON))
              .isBeforeOrAt(recordWith(new ExtendedSequenceNumber("100", 0L))))
      .isTrue();

  assertThat(
          checkpoint(AFTER_SEQUENCE_NUMBER, "10", 1L)
              .isBeforeOrAt(recordWith(new ExtendedSequenceNumber("100", 0L))))
      .isTrue();

  assertThat(
          checkpoint(AT_SEQUENCE_NUMBER, "100", 0L)
              .isBeforeOrAt(recordWith(new ExtendedSequenceNumber("100", 0L))))
      .isTrue();

  assertThat(
          checkpoint(AFTER_SEQUENCE_NUMBER, "100", 0L)
              .isBeforeOrAt(recordWith(new ExtendedSequenceNumber("100", 0L))))
      .isFalse();

  assertThat(
          checkpoint(AT_SEQUENCE_NUMBER, "100", 1L)
              .isBeforeOrAt(recordWith(new ExtendedSequenceNumber("100", 0L))))
      .isFalse();

  assertThat(
          checkpoint(AFTER_SEQUENCE_NUMBER, "100", 0L)
              .isBeforeOrAt(recordWith(new ExtendedSequenceNumber("99", 1L))))
      .isFalse();
}
 
Example #5
Source File: KinesisRecordProcessor.java    From samza with Apache License 2.0 5 votes vote down vote up
/**
 * Process data records. The Amazon Kinesis Client Library will invoke this method to deliver data records to the
 * application. Upon fail over, the new instance will get records with sequence number greater than the checkpoint
 * position for each partition key.
 *
 * @param processRecordsInput Provides the records to be processed as well as information and capabilities related
 *        to them (eg checkpointing).
 */
@Override
public void processRecords(ProcessRecordsInput processRecordsInput) {
  // KCL does not send any records to the processor that was shutdown.
  Validate.isTrue(!shutdownRequested,
      String.format("KCL returned records after shutdown is called on the processor %s.", this));
  // KCL aways gives reference to the same checkpointer instance for a given processor instance.
  checkpointer = processRecordsInput.getCheckpointer();
  List<Record> records = processRecordsInput.getRecords();
  // Empty records are expected when KCL config has CallProcessRecordsEvenForEmptyRecordList set to true.
  if (!records.isEmpty()) {
    lastProcessedRecordSeqNumber = new ExtendedSequenceNumber(records.get(records.size() - 1).getSequenceNumber());
    listener.onReceiveRecords(ssp, records, processRecordsInput.getMillisBehindLatest());
  }
}
 
Example #6
Source File: KinesisRecord.java    From beam with Apache License 2.0 4 votes vote down vote up
public ExtendedSequenceNumber getExtendedSequenceNumber() {
  return new ExtendedSequenceNumber(getSequenceNumber(), getSubSequenceNumber());
}
 
Example #7
Source File: ShardCheckpointTest.java    From beam with Apache License 2.0 4 votes vote down vote up
private KinesisRecord recordWith(ExtendedSequenceNumber extendedSequenceNumber) {
  KinesisRecord record = mock(KinesisRecord.class);
  when(record.getExtendedSequenceNumber()).thenReturn(extendedSequenceNumber);
  return record;
}