package concurrent
Functions for concurrency
Transform a Java Guava ListenableFuture into a Scala Future
val sessCloseF = cassandraSession.closeAsync() val scalaSessF = listenableFutureToScala[Unit](sessCloseF.asInstanceOf[ListenableFuture[Unit]]) scalaSessF onComplete { case Success(x) => logger.debug("session closed") case Failure(t) => logger.error(t, "session closed failed {}", t.getMessage()) }
Calculate exponential backoff delay Constant params can be passed to first argument list on startup
val min = config getInt("dendrites.timer.min-backoff") val minDuration = FiniteDuration(min, MILLISECONDS) val max = config getInt("dendrites.timer.max-backoff") val maxDuration = FiniteDuration(max, MILLISECONDS) val randomFactor = config getDouble("dendrites.timer.randomFactor") val curriedDelay = calculateDelay(minDuration, maxDuration, randomFactor) _ //Second arg list can be curried val curriedDelay = consumerConfig.curriedDelay val duration = curriedDelay(retries) if(duration < maxDuration) { waitForTimer = true scheduleOnce(None, duration) } else { failStage(e) // too many retries }
- Alphabetic
- By Inheritance
- concurrent
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
def
calculateDelay(minBackoff: FiniteDuration, maxBackoff: FiniteDuration, randomFactor: Double)(retryCount: Int): FiniteDuration
Calculate delay, used for exponential backoff.
Calculate delay, used for exponential backoff. This is copied from Akka BackoffSupervisor Used here in Akka Streams for the same purpose
- minBackoff
minimum (initial) duration
- maxBackoff
the exponential back-off is capped to this duration
- randomFactor
after calculation of the exponential back-off an additional random delay based on this factor is added, e.g.
0.2
adds up to20%
delay. In order to skip this additional delay pass in0
.- retryCount
in 2nd arg list for currying
- See also
-
def
listenableFutureToScala[T](lf: ListenableFuture[T])(implicit ec: ExecutionContextExecutor): Future[T]
Calls to Java libraries that return a Guava ListenableFuture can use this to transform it to a Scala future
Calls to Java libraries that return a Guava ListenableFuture can use this to transform it to a Scala future
- lf
ListenableFuture
- returns
completed Scala Future
- See also