2014-05-20 16:02:09 +02:00
|
|
|
/**
|
2016-02-23 12:58:39 +01:00
|
|
|
* Copyright (C) 2009-2016 Lightbend Inc. <http://www.lightbend.com>
|
2014-05-20 16:02:09 +02:00
|
|
|
*/
|
|
|
|
|
package akka.stream
|
|
|
|
|
|
2016-01-16 12:17:19 -05:00
|
|
|
import OverflowStrategies._
|
|
|
|
|
|
2014-05-20 16:02:09 +02:00
|
|
|
/**
|
2016-01-16 12:17:19 -05:00
|
|
|
* Represents a strategy that decides how to deal with a buffer of time based stage
|
|
|
|
|
* that is full but is about to receive a new element.
|
2014-05-20 16:02:09 +02:00
|
|
|
*/
|
2016-01-16 12:17:19 -05:00
|
|
|
sealed abstract class DelayOverflowStrategy extends Serializable
|
2014-05-20 16:02:09 +02:00
|
|
|
|
2016-01-16 12:17:19 -05:00
|
|
|
final case class BufferOverflowException(msg: String) extends RuntimeException(msg)
|
|
|
|
|
/**
|
|
|
|
|
* Represents a strategy that decides how to deal with a buffer that is full but is
|
|
|
|
|
* about to receive a new element.
|
|
|
|
|
*/
|
|
|
|
|
sealed abstract class OverflowStrategy extends DelayOverflowStrategy
|
2014-05-20 16:02:09 +02:00
|
|
|
|
2016-01-16 12:17:19 -05:00
|
|
|
private[akka] object OverflowStrategies {
|
2014-05-20 16:02:09 +02:00
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
*/
|
2016-01-16 12:17:19 -05:00
|
|
|
private[akka] case object DropHead extends OverflowStrategy
|
2014-05-20 16:02:09 +02:00
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
*/
|
2016-01-16 12:17:19 -05:00
|
|
|
private[akka] case object DropTail extends OverflowStrategy
|
2014-05-20 16:02:09 +02:00
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
*/
|
2016-01-16 12:17:19 -05:00
|
|
|
private[akka] case object DropBuffer extends OverflowStrategy
|
2015-09-22 18:00:19 +01:00
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
*/
|
2016-01-16 12:17:19 -05:00
|
|
|
private[akka] case object DropNew extends OverflowStrategy
|
2014-05-20 16:02:09 +02:00
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
*/
|
2016-01-16 12:17:19 -05:00
|
|
|
private[akka] case object Backpressure extends OverflowStrategy
|
2014-10-22 11:05:38 +02:00
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
*/
|
2016-01-16 12:17:19 -05:00
|
|
|
private[akka] case object Fail extends OverflowStrategy
|
|
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
*/
|
|
|
|
|
private[akka] case object EmitEarly extends DelayOverflowStrategy
|
2015-11-25 21:29:35 -05:00
|
|
|
}
|
2014-10-22 11:05:38 +02:00
|
|
|
|
2016-01-16 12:17:19 -05:00
|
|
|
object OverflowStrategy {
|
2014-05-20 16:02:09 +02:00
|
|
|
/**
|
|
|
|
|
* If the buffer is full when a new element arrives, drops the oldest element from the buffer to make space for
|
|
|
|
|
* the new element.
|
|
|
|
|
*/
|
|
|
|
|
def dropHead: OverflowStrategy = DropHead
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If the buffer is full when a new element arrives, drops the youngest element from the buffer to make space for
|
|
|
|
|
* the new element.
|
|
|
|
|
*/
|
|
|
|
|
def dropTail: OverflowStrategy = DropTail
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If the buffer is full when a new element arrives, drops all the buffered elements to make space for the new element.
|
|
|
|
|
*/
|
|
|
|
|
def dropBuffer: OverflowStrategy = DropBuffer
|
|
|
|
|
|
2015-06-01 18:08:13 +03:00
|
|
|
/**
|
|
|
|
|
* If the buffer is full when a new element arrives, drops the new element.
|
|
|
|
|
*/
|
|
|
|
|
def dropNew: OverflowStrategy = DropNew
|
|
|
|
|
|
2014-05-20 16:02:09 +02:00
|
|
|
/**
|
2014-07-22 12:21:53 +02:00
|
|
|
* If the buffer is full when a new element is available this strategy backpressures the upstream publisher until
|
2014-05-20 16:02:09 +02:00
|
|
|
* space becomes available in the buffer.
|
|
|
|
|
*/
|
|
|
|
|
def backpressure: OverflowStrategy = Backpressure
|
2014-10-22 11:05:38 +02:00
|
|
|
|
|
|
|
|
/**
|
2015-01-30 10:30:56 +01:00
|
|
|
* If the buffer is full when a new element is available this strategy completes the stream with failure.
|
2014-10-22 11:05:38 +02:00
|
|
|
*/
|
2015-01-30 10:30:56 +01:00
|
|
|
def fail: OverflowStrategy = Fail
|
2014-05-20 16:02:09 +02:00
|
|
|
}
|
2015-11-25 21:29:35 -05:00
|
|
|
|
2016-01-16 12:17:19 -05:00
|
|
|
object DelayOverflowStrategy {
|
2015-11-25 21:29:35 -05:00
|
|
|
/**
|
|
|
|
|
* If the buffer is full when a new element is available this strategy send next element downstream without waiting
|
|
|
|
|
*/
|
|
|
|
|
def emitEarly: DelayOverflowStrategy = EmitEarly
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If the buffer is full when a new element arrives, drops the oldest element from the buffer to make space for
|
|
|
|
|
* the new element.
|
|
|
|
|
*/
|
|
|
|
|
def dropHead: DelayOverflowStrategy = DropHead
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If the buffer is full when a new element arrives, drops the youngest element from the buffer to make space for
|
|
|
|
|
* the new element.
|
|
|
|
|
*/
|
|
|
|
|
def dropTail: DelayOverflowStrategy = DropTail
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If the buffer is full when a new element arrives, drops all the buffered elements to make space for the new element.
|
|
|
|
|
*/
|
|
|
|
|
def dropBuffer: DelayOverflowStrategy = DropBuffer
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If the buffer is full when a new element arrives, drops the new element.
|
|
|
|
|
*/
|
|
|
|
|
def dropNew: DelayOverflowStrategy = DropNew
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If the buffer is full when a new element is available this strategy backpressures the upstream publisher until
|
|
|
|
|
* space becomes available in the buffer.
|
|
|
|
|
*/
|
|
|
|
|
def backpressure: DelayOverflowStrategy = Backpressure
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If the buffer is full when a new element is available this strategy completes the stream with failure.
|
|
|
|
|
*/
|
|
|
|
|
def fail: DelayOverflowStrategy = Fail
|
|
|
|
|
}
|