!str #18692 javadsl.FlowGraph.Builder.add()

* also make factories more consistent by only offering
  FlowGraph.create()
* also remove secondary (edge-based) FlowGraph.Builder DSL
* also improve naming for conversions from Graph to
  Source/Flow/BidiFlow/Sink
This commit is contained in:
Viktor Klang 2015-10-21 22:45:39 +02:00 committed by Roland Kuhn
parent 0f99a42df9
commit f29d7affbd
120 changed files with 1535 additions and 1897 deletions

View file

@ -77,7 +77,7 @@ class CompositionDocSpec extends AkkaSpec {
// format: OFF
//#complex-graph
import FlowGraph.Implicits._
FlowGraph.closed() { implicit builder =>
RunnableGraph.fromGraph(FlowGraph.create() { implicit builder =>
val A: Outlet[Int] = builder.add(Source.single(0))
val B: UniformFanOutShape[Int, Int] = builder.add(Broadcast[Int](2))
val C: UniformFanInShape[Int, Int] = builder.add(Merge[Int](2))
@ -90,12 +90,14 @@ class CompositionDocSpec extends AkkaSpec {
A ~> B ~> C ~> F
B ~> D ~> E ~> F
E ~> G
}
ClosedShape
})
//#complex-graph
//#complex-graph-alt
import FlowGraph.Implicits._
FlowGraph.closed() { implicit builder =>
RunnableGraph.fromGraph(FlowGraph.create() { implicit builder =>
val B = builder.add(Broadcast[Int](2))
val C = builder.add(Merge[Int](2))
val E = builder.add(Balance[Int](2))
@ -106,7 +108,8 @@ class CompositionDocSpec extends AkkaSpec {
B.out(1).map(_ + 1) ~> E.in; E.out(0) ~> F.in(1)
E.out(1) ~> Sink.foreach(println)
}
ClosedShape
})
//#complex-graph-alt
// format: ON
}
@ -115,7 +118,7 @@ class CompositionDocSpec extends AkkaSpec {
// format: OFF
//#partial-graph
import FlowGraph.Implicits._
val partial = FlowGraph.partial() { implicit builder =>
val partial = FlowGraph.create() { implicit builder =>
val B = builder.add(Broadcast[Int](2))
val C = builder.add(Merge[Int](2))
val E = builder.add(Balance[Int](2))
@ -137,17 +140,17 @@ class CompositionDocSpec extends AkkaSpec {
//#partial-flow-dsl
// Convert the partial graph of FlowShape to a Flow to get
// access to the fluid DSL (for example to be able to call .filter())
val flow = Flow.wrap(partial)
val flow = Flow.fromGraph(partial)
// Simple way to create a graph backed Source
val source = Source() { implicit builder =>
val source = Source.fromGraph( FlowGraph.create() { implicit builder =>
val merge = builder.add(Merge[Int](2))
Source.single(0) ~> merge
Source(List(2, 3, 4)) ~> merge
// Exposing exactly one output port
merge.out
}
SourceShape(merge.out)
})
// Building a Sink with a nested Flow, using the fluid DSL
val sink = {
@ -164,22 +167,24 @@ class CompositionDocSpec extends AkkaSpec {
"closed graph" in {
//#embed-closed
val closed1 = Source.single(0).to(Sink.foreach(println))
val closed2 = FlowGraph.closed() { implicit builder =>
val closed2 = RunnableGraph.fromGraph(FlowGraph.create() { implicit builder =>
val embeddedClosed: ClosedShape = builder.add(closed1)
}
//
embeddedClosed
})
//#embed-closed
}
"materialized values" in {
//#mat-combine-1
// Materializes to Promise[Unit] (red)
val source: Source[Int, Promise[Unit]] = Source.lazyEmpty[Int]
// Materializes to Promise[Option[Int]] (red)
val source: Source[Int, Promise[Option[Int]]] = Source.maybe[Int]
// Materializes to Unit (black)
val flow1: Flow[Int, Int, Unit] = Flow[Int].take(100)
// Materializes to Promise[Unit] (red)
val nestedSource: Source[Int, Promise[Unit]] =
// Materializes to Promise[Int] (red)
val nestedSource: Source[Int, Promise[Option[Int]]] =
source.viaMat(flow1)(Keep.left).named("nestedSource")
//#mat-combine-1
@ -206,11 +211,11 @@ class CompositionDocSpec extends AkkaSpec {
//#mat-combine-3
//#mat-combine-4
case class MyClass(private val p: Promise[Unit], conn: OutgoingConnection) {
def close() = p.success(())
case class MyClass(private val p: Promise[Option[Int]], conn: OutgoingConnection) {
def close() = p.trySuccess(None)
}
def f(p: Promise[Unit],
def f(p: Promise[Option[Int]],
rest: (Future[OutgoingConnection], Future[String])): Future[MyClass] = {
val connFuture = rest._1