=str #18890 Polish Source.queue

This commit is contained in:
Alexander Golubev 2016-01-16 12:17:19 -05:00
parent 7e7a2808f1
commit d5f81e19d1
19 changed files with 565 additions and 332 deletions

View file

@ -6,8 +6,8 @@ package akka.stream.impl.fusing
import akka.event.Logging.LogLevel
import akka.event.{ LogSource, Logging, LoggingAdapter }
import akka.stream.Attributes.{ InputBuffer, LogLevels }
import akka.stream.DelayOverflowStrategy.EmitEarly
import akka.stream.impl.Stages.DefaultAttributes
import akka.stream.OverflowStrategies._
import akka.stream.impl.fusing.GraphStages.SimpleLinearGraphStage
import akka.stream.impl.{ FixedSizeBuffer, BoundedBuffer, ReactiveStreamsCompliance }
import akka.stream.stage._
@ -372,8 +372,6 @@ private[akka] final case class Sliding[T](n: Int, step: Int) extends PushPullSta
*/
private[akka] final case class Buffer[T](size: Int, overflowStrategy: OverflowStrategy) extends DetachedStage[T, T] {
import OverflowStrategy._
private val buffer = FixedSizeBuffer[T](size)
override def onPush(elem: T, ctx: DetachedContext[T]): UpstreamDirective =
@ -394,8 +392,8 @@ private[akka] final case class Buffer[T](size: Int, overflowStrategy: OverflowSt
if (buffer.isEmpty) ctx.finish()
else ctx.absorbTermination()
val enqueueAction: (DetachedContext[T], T) UpstreamDirective = {
(overflowStrategy: @unchecked) match {
val enqueueAction: (DetachedContext[T], T) UpstreamDirective =
overflowStrategy match {
case DropHead (ctx, elem)
if (buffer.isFull) buffer.dropHead()
buffer.enqueue(elem)
@ -416,13 +414,13 @@ private[akka] final case class Buffer[T](size: Int, overflowStrategy: OverflowSt
if (buffer.isFull) ctx.holdUpstream()
else ctx.pull()
case Fail (ctx, elem)
if (buffer.isFull) ctx.fail(new Fail.BufferOverflowException(s"Buffer overflow (max capacity was: $size)!"))
if (buffer.isFull) ctx.fail(new BufferOverflowException(s"Buffer overflow (max capacity was: $size)!"))
else {
buffer.enqueue(elem)
ctx.pull()
}
}
}
}
/**
@ -961,7 +959,7 @@ private[stream] final class Delay[T](d: FiniteDuration, strategy: DelayOverflowS
setHandler(in, handler = new InHandler {
//FIXME rewrite into distinct strategy functions to avoid matching on strategy for every input when full
override def onPush(): Unit = {
if (buffer.isFull) (strategy: @unchecked) match {
if (buffer.isFull) strategy match {
case EmitEarly
if (!isTimerActive(timerName))
push(out, buffer.dequeue()._2)
@ -969,24 +967,24 @@ private[stream] final class Delay[T](d: FiniteDuration, strategy: DelayOverflowS
cancelTimer(timerName)
onTimer(timerName)
}
case DelayOverflowStrategy.DropHead
case DropHead
buffer.dropHead()
grabAndPull(true)
case DelayOverflowStrategy.DropTail
case DropTail
buffer.dropTail()
grabAndPull(true)
case DelayOverflowStrategy.DropNew
case DropNew
grab(in)
if (!isTimerActive(timerName)) scheduleOnce(timerName, d)
case DelayOverflowStrategy.DropBuffer
case DropBuffer
buffer.clear()
grabAndPull(true)
case DelayOverflowStrategy.Fail
failStage(new DelayOverflowStrategy.Fail.BufferOverflowException(s"Buffer overflow for delay combinator (max capacity was: $size)!"))
case DelayOverflowStrategy.Backpressure throw new IllegalStateException("Delay buffer must never overflow in Backpressure mode")
case Fail
failStage(new BufferOverflowException(s"Buffer overflow for delay combinator (max capacity was: $size)!"))
case Backpressure throw new IllegalStateException("Delay buffer must never overflow in Backpressure mode")
}
else {
grabAndPull(strategy != DelayOverflowStrategy.Backpressure || buffer.size < size - 1)
grabAndPull(strategy != Backpressure || buffer.size < size - 1)
if (!isTimerActive(timerName)) scheduleOnce(timerName, d)
}
}