This repository has been archived by the owner on May 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from DiceTechnology/kcl-2-upgrade
Kcl 2 upgrade
- Loading branch information
Showing
11 changed files
with
369 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version=1.2.4 | ||
sbt.version=1.2.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
src/main/scala/aserralle/akka/stream/kcl/IRecordProcessor.scala
This file was deleted.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
src/main/scala/aserralle/akka/stream/kcl/ShardProcessor.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (C) 2018 Albert Serrallé | ||
*/ | ||
|
||
package aserralle.akka.stream.kcl | ||
|
||
import software.amazon.kinesis.lifecycle.ShutdownReason | ||
import software.amazon.kinesis.lifecycle.events._ | ||
import software.amazon.kinesis.processor.ShardRecordProcessor | ||
import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber | ||
|
||
import scala.collection.JavaConverters._ | ||
import scala.concurrent.ExecutionContext | ||
import scala.concurrent.duration.FiniteDuration | ||
|
||
private[kcl] class ShardProcessor( | ||
callback: CommittableRecord => Unit, | ||
terminateStreamGracePeriod: FiniteDuration | ||
)(implicit executionContext: ExecutionContext) | ||
extends ShardRecordProcessor { | ||
|
||
private var shardId: String = _ | ||
private var extendedSequenceNumber: ExtendedSequenceNumber = _ | ||
|
||
var shutdown: Option[ShutdownReason] = None | ||
|
||
override def initialize(initializationInput: InitializationInput): Unit = { | ||
shardId = initializationInput.shardId() | ||
extendedSequenceNumber = initializationInput.extendedSequenceNumber() | ||
} | ||
|
||
override def processRecords(processRecordsInput: ProcessRecordsInput): Unit = { | ||
processRecordsInput.records().asScala.foreach { record => | ||
callback( | ||
new CommittableRecord( | ||
shardId, | ||
extendedSequenceNumber, | ||
processRecordsInput.millisBehindLatest(), | ||
record, | ||
recordProcessor = this, | ||
processRecordsInput.checkpointer | ||
) | ||
) | ||
} | ||
} | ||
|
||
override def leaseLost(leaseLostInput: LeaseLostInput): Unit = {} | ||
|
||
override def shardEnded(shardEndedInput: ShardEndedInput): Unit = { | ||
// We need to checkpoint, but if we do it immediately any records still | ||
// in flight may get lost, so we wait for the grace period | ||
shutdown = Some(ShutdownReason.SHARD_END) | ||
Thread.sleep(terminateStreamGracePeriod.toMillis) | ||
shardEndedInput.checkpointer.checkpoint() | ||
} | ||
|
||
override def shutdownRequested(shutdownInput: ShutdownRequestedInput): Unit = { | ||
// We don't checkpoint at this point as we assume the | ||
// standard mechanism will checkpoint when required | ||
shutdown = Some(ShutdownReason.REQUESTED) | ||
Thread.sleep(terminateStreamGracePeriod.toMillis) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.