2018-10-29 17:19:37 +08:00
|
|
|
/*
|
2020-01-02 07:24:59 -05:00
|
|
|
* Copyright (C) 2015-2020 Lightbend Inc. <https://www.lightbend.com>
|
2015-01-28 14:19:50 +01:00
|
|
|
*/
|
2018-03-13 23:45:55 +09:00
|
|
|
|
2015-01-28 14:19:50 +01:00
|
|
|
package akka.stream
|
|
|
|
|
|
2019-01-15 16:53:02 +01:00
|
|
|
import akka.annotation.InternalApi
|
2018-03-16 19:08:29 +08:00
|
|
|
import akka.stream.impl.TraversalBuilder
|
2016-07-27 13:29:23 +02:00
|
|
|
|
2015-02-27 16:33:25 +01:00
|
|
|
import scala.annotation.unchecked.uncheckedVariance
|
2015-01-28 14:19:50 +01:00
|
|
|
|
2017-11-23 10:26:00 +01:00
|
|
|
/**
|
|
|
|
|
* Not intended to be directly extended by user classes
|
|
|
|
|
*
|
|
|
|
|
* @see [[akka.stream.stage.GraphStage]]
|
|
|
|
|
*/
|
2015-01-28 14:19:50 +01:00
|
|
|
trait Graph[+S <: Shape, +M] {
|
2019-03-11 10:38:24 +01:00
|
|
|
|
2015-01-28 14:19:50 +01:00
|
|
|
/**
|
|
|
|
|
* Type-level accessor for the shape parameter of this graph.
|
|
|
|
|
*/
|
2015-02-27 16:33:25 +01:00
|
|
|
type Shape = S @uncheckedVariance
|
2015-01-28 14:19:50 +01:00
|
|
|
/**
|
|
|
|
|
* The shape of a graph is all that is externally visible: its inlets and outlets.
|
|
|
|
|
*/
|
|
|
|
|
def shape: S
|
2019-03-11 10:38:24 +01:00
|
|
|
|
2015-01-28 14:19:50 +01:00
|
|
|
/**
|
|
|
|
|
* INTERNAL API.
|
|
|
|
|
*
|
|
|
|
|
* Every materializable element must be backed by a stream layout module
|
|
|
|
|
*/
|
2016-07-27 13:29:23 +02:00
|
|
|
private[stream] def traversalBuilder: TraversalBuilder
|
2015-04-14 08:59:37 +02:00
|
|
|
|
2015-06-23 17:32:55 +02:00
|
|
|
def withAttributes(attr: Attributes): Graph[S, M]
|
2015-04-14 08:59:37 +02:00
|
|
|
|
2016-08-09 15:11:59 +02:00
|
|
|
def named(name: String): Graph[S, M] = addAttributes(Attributes.name(name))
|
2015-12-14 17:02:00 +01:00
|
|
|
|
2016-02-10 13:56:38 +01:00
|
|
|
/**
|
|
|
|
|
* Put an asynchronous boundary around this `Graph`
|
|
|
|
|
*/
|
|
|
|
|
def async: Graph[S, M] = addAttributes(Attributes.asyncBoundary)
|
|
|
|
|
|
2017-11-23 10:26:00 +01:00
|
|
|
/**
|
|
|
|
|
* Put an asynchronous boundary around this `Graph`
|
|
|
|
|
*
|
|
|
|
|
* @param dispatcher Run the graph on this dispatcher
|
|
|
|
|
*/
|
|
|
|
|
def async(dispatcher: String) =
|
2019-03-11 10:38:24 +01:00
|
|
|
addAttributes(Attributes.asyncBoundary and ActorAttributes.dispatcher(dispatcher))
|
2017-11-23 10:26:00 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Put an asynchronous boundary around this `Graph`
|
|
|
|
|
*
|
|
|
|
|
* @param dispatcher Run the graph on this dispatcher
|
|
|
|
|
* @param inputBufferSize Set the input buffer to this size for the graph
|
|
|
|
|
*/
|
|
|
|
|
def async(dispatcher: String, inputBufferSize: Int) =
|
|
|
|
|
addAttributes(
|
|
|
|
|
Attributes.asyncBoundary and ActorAttributes.dispatcher(dispatcher)
|
2019-03-11 10:38:24 +01:00
|
|
|
and Attributes.inputBuffer(inputBufferSize, inputBufferSize))
|
2017-11-23 10:26:00 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add the given attributes to this [[Graph]]. If the specific attribute was already present
|
|
|
|
|
* on this graph this means the added attribute will be more specific than the existing one.
|
|
|
|
|
* If this Source is a composite of multiple graphs, new attributes on the composite will be
|
|
|
|
|
* less specific than attributes set directly on the individual graphs of the composite.
|
|
|
|
|
*/
|
2016-07-27 13:29:23 +02:00
|
|
|
def addAttributes(attr: Attributes): Graph[S, M] = withAttributes(traversalBuilder.attributes and attr)
|
2015-01-28 14:19:50 +01:00
|
|
|
}
|
2019-01-15 16:53:02 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* INTERNAL API
|
|
|
|
|
*
|
|
|
|
|
* Allows creating additional API on top of an existing Graph by extending from this class and
|
|
|
|
|
* accessing the delegate
|
|
|
|
|
*/
|
|
|
|
|
@InternalApi
|
|
|
|
|
private[stream] abstract class GraphDelegate[+S <: Shape, +Mat](delegate: Graph[S, Mat]) extends Graph[S, Mat] {
|
|
|
|
|
final override def shape: S = delegate.shape
|
|
|
|
|
final override private[stream] def traversalBuilder: TraversalBuilder = delegate.traversalBuilder
|
|
|
|
|
}
|