System wide materializer (#27491)
Introduces a materializer started through an extension and then an implicit conversion for Scala turning an implicitly available ActorSystem into a materializer. The Java APIs has been ammended with run-methods accepting an ActorSystem.
This commit is contained in:
parent
77d1d33dbc
commit
45c826a218
196 changed files with 1148 additions and 1129 deletions
|
|
@ -34,17 +34,14 @@ public class QuickStartDocTest extends AbstractJavaTest {
|
|||
|
||||
@Test
|
||||
public void demonstrateSource() throws InterruptedException, ExecutionException {
|
||||
// #create-materializer
|
||||
final ActorSystem system = ActorSystem.create("QuickStart");
|
||||
final Materializer materializer = ActorMaterializer.create(system);
|
||||
// #create-materializer
|
||||
|
||||
// #create-source
|
||||
final Source<Integer, NotUsed> source = Source.range(1, 100);
|
||||
// #create-source
|
||||
|
||||
// #run-source
|
||||
source.runForeach(i -> System.out.println(i), materializer);
|
||||
source.runForeach(i -> System.out.println(i), system);
|
||||
// #run-source
|
||||
|
||||
// #transform-source
|
||||
|
|
@ -54,11 +51,11 @@ public class QuickStartDocTest extends AbstractJavaTest {
|
|||
final CompletionStage<IOResult> result =
|
||||
factorials
|
||||
.map(num -> ByteString.fromString(num.toString() + "\n"))
|
||||
.runWith(FileIO.toPath(Paths.get("factorials.txt")), materializer);
|
||||
.runWith(FileIO.toPath(Paths.get("factorials.txt")), system);
|
||||
// #transform-source
|
||||
|
||||
// #use-transformed-sink
|
||||
factorials.map(BigInteger::toString).runWith(lineSink("factorial2.txt"), materializer);
|
||||
factorials.map(BigInteger::toString).runWith(lineSink("factorial2.txt"), system);
|
||||
// #use-transformed-sink
|
||||
|
||||
// #add-streams
|
||||
|
|
@ -68,11 +65,11 @@ public class QuickStartDocTest extends AbstractJavaTest {
|
|||
// #add-streams
|
||||
.take(2)
|
||||
// #add-streams
|
||||
.runForeach(s -> System.out.println(s), materializer);
|
||||
.runForeach(s -> System.out.println(s), system);
|
||||
// #add-streams
|
||||
|
||||
// #run-source-and-terminate
|
||||
final CompletionStage<Done> done = source.runForeach(i -> System.out.println(i), materializer);
|
||||
final CompletionStage<Done> done = source.runForeach(i -> System.out.println(i), system);
|
||||
|
||||
done.thenRun(() -> system.terminate());
|
||||
// #run-source-and-terminate
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue