format source with scalafmt

This commit is contained in:
Auto Format 2019-03-11 10:38:24 +01:00 committed by Patrik Nordwall
parent 0f40491d42
commit ce404e4f53
1669 changed files with 43208 additions and 35404 deletions

View file

@ -30,7 +30,8 @@ import scala.concurrent.{ Future, Promise }
/**
* INTERNAL API
*/
@InternalApi private[akka] final class QueueSource[T](maxBuffer: Int, overflowStrategy: OverflowStrategy) extends GraphStageWithMaterializedValue[SourceShape[T], SourceQueueWithComplete[T]] {
@InternalApi private[akka] final class QueueSource[T](maxBuffer: Int, overflowStrategy: OverflowStrategy)
extends GraphStageWithMaterializedValue[SourceShape[T], SourceQueueWithComplete[T]] {
import QueueSource._
val out = Outlet[T]("queueSource.out")
@ -62,37 +63,43 @@ import scala.concurrent.{ Future, Promise }
private def bufferElem(offer: Offer[T]): Unit = {
if (!buffer.isFull) {
enqueueAndSuccess(offer)
} else overflowStrategy match {
case s: DropHead =>
log.log(s.logLevel, "Dropping the head element because buffer is full and overflowStrategy is: [DropHead]")
buffer.dropHead()
enqueueAndSuccess(offer)
case s: DropTail =>
log.log(s.logLevel, "Dropping the tail element because buffer is full and overflowStrategy is: [DropTail]")
buffer.dropTail()
enqueueAndSuccess(offer)
case s: DropBuffer =>
log.log(s.logLevel, "Dropping all the buffered elements because buffer is full and overflowStrategy is: [DropBuffer]")
buffer.clear()
enqueueAndSuccess(offer)
case s: DropNew =>
log.log(s.logLevel, "Dropping the new element because buffer is full and overflowStrategy is: [DropNew]")
offer.promise.success(QueueOfferResult.Dropped)
case s: Fail =>
log.log(s.logLevel, "Failing because buffer is full and overflowStrategy is: [Fail]")
val bufferOverflowException = BufferOverflowException(s"Buffer overflow (max capacity was: $maxBuffer)!")
offer.promise.success(QueueOfferResult.Failure(bufferOverflowException))
completion.failure(bufferOverflowException)
failStage(bufferOverflowException)
case s: Backpressure =>
log.log(s.logLevel, "Backpressuring because buffer is full and overflowStrategy is: [Backpressure]")
pendingOffer match {
case Some(_) =>
offer.promise.failure(new IllegalStateException("You have to wait for previous offer to be resolved to send another request"))
case None =>
pendingOffer = Some(offer)
}
}
} else
overflowStrategy match {
case s: DropHead =>
log.log(s.logLevel,
"Dropping the head element because buffer is full and overflowStrategy is: [DropHead]")
buffer.dropHead()
enqueueAndSuccess(offer)
case s: DropTail =>
log.log(s.logLevel,
"Dropping the tail element because buffer is full and overflowStrategy is: [DropTail]")
buffer.dropTail()
enqueueAndSuccess(offer)
case s: DropBuffer =>
log.log(s.logLevel,
"Dropping all the buffered elements because buffer is full and overflowStrategy is: [DropBuffer]")
buffer.clear()
enqueueAndSuccess(offer)
case s: DropNew =>
log.log(s.logLevel, "Dropping the new element because buffer is full and overflowStrategy is: [DropNew]")
offer.promise.success(QueueOfferResult.Dropped)
case s: Fail =>
log.log(s.logLevel, "Failing because buffer is full and overflowStrategy is: [Fail]")
val bufferOverflowException = BufferOverflowException(s"Buffer overflow (max capacity was: $maxBuffer)!")
offer.promise.success(QueueOfferResult.Failure(bufferOverflowException))
completion.failure(bufferOverflowException)
failStage(bufferOverflowException)
case s: Backpressure =>
log.log(s.logLevel, "Backpressuring because buffer is full and overflowStrategy is: [Backpressure]")
pendingOffer match {
case Some(_) =>
offer.promise.failure(
new IllegalStateException(
"You have to wait for previous offer to be resolved to send another request"))
case None =>
pendingOffer = Some(offer)
}
}
}
private val callback = getAsyncCallback[Input[T]] {
@ -108,24 +115,28 @@ import scala.concurrent.{ Future, Promise }
promise.success(QueueOfferResult.Enqueued)
} else if (pendingOffer.isEmpty)
pendingOffer = Some(offer)
else overflowStrategy match {
case s @ (_: DropHead | _: DropBuffer) =>
log.log(s.logLevel, "Dropping element because buffer is full and overflowStrategy is: [{}]", s)
pendingOffer.get.promise.success(QueueOfferResult.Dropped)
pendingOffer = Some(offer)
case s @ (_: DropTail | _: DropNew) =>
log.log(s.logLevel, "Dropping element because buffer is full and overflowStrategy is: [{}]", s)
promise.success(QueueOfferResult.Dropped)
case s: Fail =>
log.log(s.logLevel, "Failing because buffer is full and overflowStrategy is: [Fail]")
val bufferOverflowException = BufferOverflowException(s"Buffer overflow (max capacity was: $maxBuffer)!")
promise.success(QueueOfferResult.Failure(bufferOverflowException))
completion.failure(bufferOverflowException)
failStage(bufferOverflowException)
case s: Backpressure =>
log.log(s.logLevel, "Failing because buffer is full and overflowStrategy is: [Backpressure]")
promise.failure(new IllegalStateException("You have to wait for previous offer to be resolved to send another request"))
}
else
overflowStrategy match {
case s @ (_: DropHead | _: DropBuffer) =>
log.log(s.logLevel, "Dropping element because buffer is full and overflowStrategy is: [{}]", s)
pendingOffer.get.promise.success(QueueOfferResult.Dropped)
pendingOffer = Some(offer)
case s @ (_: DropTail | _: DropNew) =>
log.log(s.logLevel, "Dropping element because buffer is full and overflowStrategy is: [{}]", s)
promise.success(QueueOfferResult.Dropped)
case s: Fail =>
log.log(s.logLevel, "Failing because buffer is full and overflowStrategy is: [Fail]")
val bufferOverflowException =
BufferOverflowException(s"Buffer overflow (max capacity was: $maxBuffer)!")
promise.success(QueueOfferResult.Failure(bufferOverflowException))
completion.failure(bufferOverflowException)
failStage(bufferOverflowException)
case s: Backpressure =>
log.log(s.logLevel, "Failing because buffer is full and overflowStrategy is: [Backpressure]")
promise.failure(
new IllegalStateException(
"You have to wait for previous offer to be resolved to send another request"))
}
case Completion =>
if (maxBuffer != 0 && buffer.nonEmpty || pendingOffer.nonEmpty) terminating = true
@ -183,7 +194,8 @@ import scala.concurrent.{ Future, Promise }
override def watchCompletion() = completion.future
override def offer(element: T): Future[QueueOfferResult] = {
val p = Promise[QueueOfferResult]
callback.invokeWithFeedback(Offer(element, p))
callback
.invokeWithFeedback(Offer(element, p))
.onComplete {
case scala.util.Success(_) =>
case scala.util.Failure(e) => p.tryFailure(e)
@ -203,7 +215,8 @@ import scala.concurrent.{ Future, Promise }
/**
* INTERNAL API
*/
@InternalApi private[akka] final class SourceQueueAdapter[T](delegate: SourceQueueWithComplete[T]) extends akka.stream.javadsl.SourceQueueWithComplete[T] {
@InternalApi private[akka] final class SourceQueueAdapter[T](delegate: SourceQueueWithComplete[T])
extends akka.stream.javadsl.SourceQueueWithComplete[T] {
def offer(elem: T): CompletionStage[QueueOfferResult] = delegate.offer(elem).toJava
def watchCompletion(): CompletionStage[Done] = delegate.watchCompletion().toJava
def complete(): Unit = delegate.complete()