diff --git a/akka-docs-dev/rst/java/code/docs/MigrationsJava.java b/akka-docs-dev/rst/java/code/docs/MigrationsJava.java new file mode 100644 index 0000000000..1a61b92a3b --- /dev/null +++ b/akka-docs-dev/rst/java/code/docs/MigrationsJava.java @@ -0,0 +1,125 @@ +package docs; + +import akka.japi.Pair; +import akka.stream.*; +import akka.stream.javadsl.*; +import scala.Option; +import scala.concurrent.Promise; +import scala.runtime.BoxedUnit; + +public class MigrationsJava { + + // This is compile-only code, no need for actually running anything. + public static ActorMaterializer mat = null; + + public static void main(String[] args) { + + Outlet outlet = null; + + Outlet outlet1 = null; + Outlet outlet2 = null; + + Inlet inlet = null; + + Inlet inlet1 = null; + Inlet inlet2 = null; + + Flow flow = Flow.of(Integer.class); + Flow flow1 = Flow.of(Integer.class); + Flow flow2 = Flow.of(Integer.class); + + Promise> promise = null; + + + { + Graph, BoxedUnit> graphSource = null; + Graph, BoxedUnit> graphSink = null; + Graph, BoxedUnit> graphFlow = null; + + //#flow-wrap + Source source = Source.fromGraph(graphSource); + Sink sink = Sink.fromGraph(graphSink); + Flow aflow = Flow.fromGraph(graphFlow); + Flow.fromSinkAndSource(Sink.head(), Source.single(0)); + Flow.fromSinkAndSourceMat(Sink.head(), Source.single(0), Keep.left()); + //#flow-wrap + + Graph, BoxedUnit> bidiGraph = null; + + //#bidi-wrap + BidiFlow bidiFlow = + BidiFlow.fromGraph(bidiGraph); + BidiFlow.fromFlows(flow1, flow2); + BidiFlow.fromFlowsMat(flow1, flow2, Keep.both()); + //#bidi-wrap + + } + + { + //#graph-create + FlowGraph.create(builder -> { + //... + return ClosedShape.getInstance(); + }); + + FlowGraph.create(builder -> { + //... + return new FlowShape(inlet, outlet); + }); + //#graph-create + } + + { + //#graph-create-2 + FlowGraph.create(builder -> { + //... + return new SourceShape<>(outlet); + }); + + FlowGraph.create(builder -> { + //... + return new SinkShape<>(inlet); + }); + + FlowGraph.create(builder -> { + //... + return new FlowShape<>(inlet, outlet); + }); + + FlowGraph.create(builder -> { + //... + return new BidiShape<>(inlet1, outlet1, inlet2, outlet2); + }); + //#graph-create-2 + } + + { + //#graph-builder + FlowGraph.create(builder -> { + builder.from(outlet).toInlet(inlet); + builder.from(outlet).via(builder.add(flow)).toInlet(inlet); + builder.from(builder.add(Source.single(0))).to(builder.add(Sink.head())); + //... + return ClosedShape.getInstance(); + }); + //#graph-builder + } + + //#source-creators + Source>> src = Source.maybe(); + // Complete the promise with an empty option to emulate the old lazyEmpty + promise.trySuccess(scala.Option.empty()); + //#source-creators + + //#empty-flow + Flow emptyFlow = Flow.create(); + // or + Flow emptyFlow2 = Flow.of(Integer.class); + //#empty-flow + + //#flattenConcat + Flow.>create().flattenConcat(); + //#flattenConcat + } + +} diff --git a/akka-docs-dev/rst/java/migration-guide-1.0-2.x-java.rst b/akka-docs-dev/rst/java/migration-guide-1.0-2.x-java.rst index bc86a6bce1..c83b7e565c 100644 --- a/akka-docs-dev/rst/java/migration-guide-1.0-2.x-java.rst +++ b/akka-docs-dev/rst/java/migration-guide-1.0-2.x-java.rst @@ -1,4 +1,4 @@ -.. _migration-2.0: +.. _migration-2.0-java: ############################ Migration Guide 1.0 to 2.x @@ -51,15 +51,15 @@ Example :: - Graph, BoxedUnit> graphSource = null; + Graph, BoxedUnit> graphSource = ...; // This no longer works! Source source = Source.wrap(graphSource); - Graph, BoxedUnit> graphSink = null; + Graph, BoxedUnit> graphSink = ...; // This no longer works! Sink sink = Sink.wrap(graphSink); - Graph, BoxedUnit> graphFlow = null; + Graph, BoxedUnit> graphFlow = ...; // This no longer works! Flow flow = Flow.wrap(graphFlow); @@ -68,13 +68,13 @@ Example should be replaced by -TODO +.. includecode:: code/docs/MigrationsJava.java#flow-wrap and :: - Graph, BoxedUnit> bidiGraph = null; + Graph, BoxedUnit> bidiGraph = ...; // This no longer works! BidiFlow bidiFlow = BidiFlow.wrap(bidiGraph); @@ -84,7 +84,7 @@ and Should be replaced by -TODO +.. includecode:: code/docs/MigrationsJava.java#bidi-wrap FlowGraph builder methods have been renamed =========================================== @@ -117,7 +117,7 @@ Example should be replaced by -TODO +.. includecode:: code/docs/MigrationsJava.java#graph-create Methods that create Source, Sink, Flow from Graphs have been removed ==================================================================== @@ -174,24 +174,37 @@ Example should be replaced by -TODO +.. includecode:: code/docs/MigrationsJava.java#graph-create-2 Some graph Builder methods have been removed ============================================ Due to the high number of overloads Java 8 type inference suffered, and it was also hard to figure out which time -to use which method. Therefore various redundant methods have been removed. +to use which method. Therefore various redundant methods have been removed. As a consequence, every ``Sink``, ``Source`` +and ``Flow`` needs to be explicitly added via ``builder.add()``. Update procedure ---------------- -1. All uses of ``builder.addEdge(Outlet, Inlet)`` should be replaced by the alternative ``builder.from(…).to(…)`` -2. All uses of ``builder.addEdge(Outlet, FlowShape, Inlet)`` should be replaced by ``builder.from(…).via(…).to(…)`` -3. All uses of ``builder.source`` should be replaced by ``builder.from(…).via(…).to(…)`` -4. All uses of ``builder.flow`` should be replaced by ``builder.from(…).via(…).to(…)`` -5. All uses of ``builder.sink`` should be replaced by ``builder.from(…).via(…).to(…)`` +1. All uses of ``builder.edge(outlet,inlet)`` should be replaced by the alternative ``builder.from(outlet).toInlet(inlet)`` +3. All uses of ``builder.source`` should be replaced by ``builder.from(builder.add(source))`` +4. All uses of ``builder.flow`` should be replaced by ``builder.….via(builder.add(flow))`` +5. All uses of ``builder.sink`` should be replaced by ``builder.….to(builder.add(sink)))`` -TODO: code example +:: + + FlowGraph.factory().closed(builder -> { + // These no longer work + builder.edge(outlet, inlet); + builder.flow(outlet, flow, inlet); + builder.source(Source.single(0)); + builder.sink(Sink.head()); + //... + }); + +should be replaced by + +.. includecode:: code/docs/MigrationsJava.java#graph-builder Source constructor name changes =============================== @@ -215,7 +228,16 @@ Update procedure Example ^^^^^^^ -TODO +:: + + // This no longer works! + Source> src = Source.lazyEmpty(); + //... + promise.trySuccess(BoxedUnit.UNIT); + +should be replaced by + +.. includecode:: code/docs/MigrationsJava.java#source-creators ``Flow.empty()`` have been removed ================================== @@ -228,7 +250,14 @@ Update procedure 1. Replace all uses of ``Flow.empty()`` with ``Flow.create``. -TODO: code example +:: + + // This no longer works! + Flow emptyFlow = Flow.empty(); + +should be replaced by + +.. includecode:: code/docs/MigrationsJava.java#empty-flow ``flatten(FlattenStrategy)`` has been replaced by named counterparts ==================================================================== @@ -244,7 +273,13 @@ Update procedure Example ^^^^^^^ -TODO +:: + + Flow.>create().flatten(FlattenStrategy.concat()); + +should be replaced by + +.. includecode:: code/docs/MigrationsJava.java#flattenConcat FlexiMerge an FlexiRoute has been replaced by GraphStage ======================================================== diff --git a/akka-docs-dev/rst/scala/migration-guide-1.0-2.x-scala.rst b/akka-docs-dev/rst/scala/migration-guide-1.0-2.x-scala.rst index f1897f7ed5..4758055cbe 100644 --- a/akka-docs-dev/rst/scala/migration-guide-1.0-2.x-scala.rst +++ b/akka-docs-dev/rst/scala/migration-guide-1.0-2.x-scala.rst @@ -1,4 +1,4 @@ -.. _migration-2.0: +.. _migration-2.0-scala: ############################ Migration Guide 1.0 to 2.x @@ -71,7 +71,7 @@ Example should be replaced by -.. includecode:: /scala/code/docs/Migrations.scala#flow-wrap +.. includecode:: code/docs/Migrations.scala#flow-wrap and @@ -90,7 +90,7 @@ and Should be replaced by -.. includecode:: /scala/code/docs/Migrations.scala#bidiflow-wrap +.. includecode:: code/docs/Migrations.scala#bidiflow-wrap FlowGraph builder methods have been renamed =========================================== @@ -123,7 +123,7 @@ Example should be replaced by -.. includecode:: /scala/code/docs/Migrations.scala#graph-create +.. includecode:: code/docs/Migrations.scala#graph-create Methods that create Source, Sink, Flow from Graphs have been removed ==================================================================== @@ -180,7 +180,7 @@ Example should be replaced by -.. includecode:: /scala/code/docs/Migrations.scala#graph-create-2 +.. includecode:: code/docs/Migrations.scala#graph-create-2 Several Graph builder methods have been removed =============================================== @@ -213,7 +213,7 @@ Example should be replaced by -.. includecode:: /scala/code/docs/Migrations.scala#graph-edges +.. includecode:: code/docs/Migrations.scala#graph-edges Source constructor name changes =============================== @@ -249,7 +249,7 @@ Example should be replaced by -.. includecode:: /scala/code/docs/Migrations.scala#source-creators +.. includecode:: code/docs/Migrations.scala#source-creators ``flatten(FlattenStrategy)`` has been replaced by named counterparts ==================================================================== @@ -272,7 +272,7 @@ Example should be replaced by -.. includecode:: /scala/code/docs/Migrations.scala#flatten +.. includecode:: code/docs/Migrations.scala#flatten FlexiMerge an FlexiRoute has been replaced by GraphStage ======================================================== @@ -408,4 +408,4 @@ Example should be replaced by -.. includecode:: /scala/code/docs/Migrations.scala#port-async \ No newline at end of file +.. includecode:: code/docs/Migrations.scala#port-async \ No newline at end of file