[storage-aws] force upload progress updates to strick sequence

Prevents the situation where a second progress update arrives while
the first is still on the process of being processed. The new update
is blocked until the first is completed.
This commit is contained in:
Paul Campbell 2019-08-14 10:10:23 +01:00
parent e0beef9d73
commit 242804294d

View file

@ -1,5 +1,7 @@
package net.kemitix.thorp.storage.aws
import java.util.concurrent.locks.StampedLock
import com.amazonaws.event.ProgressEventType.RESPONSE_BYTE_TRANSFER_EVENT
import com.amazonaws.event.{ProgressEvent, ProgressListener}
import com.amazonaws.services.s3.model.{ObjectMetadata, PutObjectRequest}
@ -75,8 +77,11 @@ trait Uploader {
listenerSettings =>
new ProgressListener {
private val listener = UploadEventListener.listener(listenerSettings)
private val lock = new StampedLock
override def progressChanged(progressEvent: ProgressEvent): Unit = {
val writeLock = lock.writeLock()
listener(eventHandler(progressEvent))
lock.unlock(writeLock)
}
private def eventHandler: ProgressEvent => UploadEvent =