2014-12-01 20:07:55 +02:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2014 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
|
|
|
|
package akka.stream.scaladsl
|
|
|
|
|
|
2015-01-28 14:19:50 +01:00
|
|
|
import akka.stream.impl.Stages.StageModule
|
2015-02-04 09:26:32 +01:00
|
|
|
import akka.stream.Supervision
|
2014-12-01 20:07:55 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Holds attributes which can be used to alter [[Flow]] or [[FlowGraph]]
|
|
|
|
|
* materialization.
|
|
|
|
|
*/
|
2015-02-26 22:42:34 +01:00
|
|
|
final case class OperationAttributes private (attributes: List[OperationAttributes.Attribute] = Nil) {
|
2014-12-01 20:07:55 +02:00
|
|
|
|
|
|
|
|
import OperationAttributes._
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds given attributes to the end of these attributes.
|
|
|
|
|
*/
|
2015-02-04 09:26:32 +01:00
|
|
|
def and(other: OperationAttributes): OperationAttributes =
|
|
|
|
|
if (attributes.isEmpty) other
|
|
|
|
|
else if (other.attributes.isEmpty) this
|
|
|
|
|
else OperationAttributes(attributes ::: other.attributes)
|
2014-12-01 20:07:55 +02:00
|
|
|
|
|
|
|
|
private[akka] def nameLifted: Option[String] =
|
|
|
|
|
attributes.collect {
|
|
|
|
|
case Name(name) ⇒ name
|
2014-11-20 21:59:33 +01:00
|
|
|
}.reduceOption(_ + "-" + _) // FIXME don't do a double-traversal, use a fold instead
|
2014-12-01 20:07:55 +02:00
|
|
|
|
|
|
|
|
private[akka] def name: String = nameLifted match {
|
|
|
|
|
case Some(name) ⇒ name
|
|
|
|
|
case _ ⇒ "unknown-operation"
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-28 14:19:50 +01:00
|
|
|
private[akka] def transform(node: StageModule): StageModule =
|
2014-12-01 20:07:55 +02:00
|
|
|
if ((this eq OperationAttributes.none) || (this eq node.attributes)) node
|
|
|
|
|
else node.withAttributes(attributes = this and node.attributes)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object OperationAttributes {
|
|
|
|
|
|
2015-02-26 22:42:34 +01:00
|
|
|
sealed trait Attribute
|
|
|
|
|
final case class Name(n: String) extends Attribute
|
|
|
|
|
final case class InputBuffer(initial: Int, max: Int) extends Attribute
|
|
|
|
|
final case class Dispatcher(dispatcher: String) extends Attribute
|
|
|
|
|
final case class SupervisionStrategy(decider: Supervision.Decider) extends Attribute
|
2014-12-01 20:07:55 +02:00
|
|
|
|
|
|
|
|
private[OperationAttributes] def apply(attribute: Attribute): OperationAttributes =
|
|
|
|
|
apply(List(attribute))
|
|
|
|
|
|
2015-01-28 14:19:50 +01:00
|
|
|
val none: OperationAttributes = OperationAttributes()
|
2014-12-01 20:07:55 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Specifies the name of the operation.
|
|
|
|
|
*/
|
|
|
|
|
def name(name: String): OperationAttributes = OperationAttributes(Name(name))
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Specifies the initial and maximum size of the input buffer.
|
|
|
|
|
*/
|
|
|
|
|
def inputBuffer(initial: Int, max: Int): OperationAttributes = OperationAttributes(InputBuffer(initial, max))
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Specifies the name of the dispatcher.
|
|
|
|
|
*/
|
|
|
|
|
def dispatcher(dispatcher: String): OperationAttributes = OperationAttributes(Dispatcher(dispatcher))
|
2015-02-04 09:26:32 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Decides how exceptions from user are to be handled.
|
|
|
|
|
*/
|
|
|
|
|
def supervisionStrategy(decider: Supervision.Decider): OperationAttributes =
|
|
|
|
|
OperationAttributes(SupervisionStrategy(decider))
|
2014-12-01 20:07:55 +02:00
|
|
|
}
|