Headers and formats

This commit is contained in:
Ignasi Marimon-Clos 2020-07-07 14:58:56 +02:00
parent 0e3b4605ad
commit 024710a6e0
2 changed files with 61 additions and 63 deletions

View file

@ -1,3 +1,7 @@
/*
* Copyright (C) 2020 Lightbend Inc. <https://www.lightbend.com>
*/
package jdocs.stream.operators.sourceorflow;
import akka.Done;
@ -16,9 +20,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
*
*/
/** */
public class Monitor {
// #monitor
@ -37,20 +39,18 @@ public class Monitor {
}
// #monitor
public static void main(String[] args) throws InterruptedException, TimeoutException, ExecutionException {
public static void main(String[] args)
throws InterruptedException, TimeoutException, ExecutionException {
ActorSystem actorSystem = ActorSystem.create("25fps-stream");
// #monitor
Source<Integer, FlowMonitor<Integer>> monitoredSource =
Source
.fromIterator(() -> Arrays.asList(0, 1, 2, 3, 4, 5).iterator())
Source.fromIterator(() -> Arrays.asList(0, 1, 2, 3, 4, 5).iterator())
.throttle(5, Duration.ofSeconds(1))
.monitorMat(Keep.right());
Pair<FlowMonitor<Integer>, CompletionStage<Done>> run = monitoredSource
.toMat(Sink.foreach(System.out::println), Keep.both()).run(actorSystem);
Pair<FlowMonitor<Integer>, CompletionStage<Done>> run =
monitoredSource.toMat(Sink.foreach(System.out::println), Keep.both()).run(actorSystem);
FlowMonitor<Integer> monitor = run.first();
@ -76,6 +76,5 @@ public class Monitor {
// #monitor
run.second().toCompletableFuture().whenComplete((x, t) -> actorSystem.terminate());
}
}

View file

@ -1,3 +1,7 @@
/*
* Copyright (C) 2020 Lightbend Inc. <https://www.lightbend.com>
*/
package docs.stream.operators.sourceorflow
import akka.Done
@ -38,14 +42,9 @@ class Monitor {
}
}
val monitoredSource: Source[Int, FlowMonitor[Int]] = source
.take(6)
.throttle(5, 1.second)
.monitorMat(Keep.right)
val monitoredSource: Source[Int, FlowMonitor[Int]] = source.take(6).throttle(5, 1.second).monitorMat(Keep.right)
val monitoredStream: (FlowMonitor[Int], Future[Done]) =
monitoredSource
.toMat(Sink.foreach(println))(Keep.both)
.run()
monitoredSource.toMat(Sink.foreach(println))(Keep.both).run()
val flowMonitor = monitoredStream._1