Formatting java codes with sbt-java-formatter.
This commit is contained in:
parent
27500001ea
commit
998c5a9285
401 changed files with 19750 additions and 17450 deletions
|
|
@ -42,88 +42,104 @@ public class StreamBuffersRateDocTest extends AbstractJavaTest {
|
|||
|
||||
@Test
|
||||
public void demonstratePipelining() {
|
||||
//#pipelining
|
||||
// #pipelining
|
||||
Source.from(Arrays.asList(1, 2, 3))
|
||||
.map(i -> {System.out.println("A: " + i); return i;}).async()
|
||||
.map(i -> {System.out.println("B: " + i); return i;}).async()
|
||||
.map(i -> {System.out.println("C: " + i); return i;}).async()
|
||||
.runWith(Sink.ignore(), mat);
|
||||
//#pipelining
|
||||
.map(
|
||||
i -> {
|
||||
System.out.println("A: " + i);
|
||||
return i;
|
||||
})
|
||||
.async()
|
||||
.map(
|
||||
i -> {
|
||||
System.out.println("B: " + i);
|
||||
return i;
|
||||
})
|
||||
.async()
|
||||
.map(
|
||||
i -> {
|
||||
System.out.println("C: " + i);
|
||||
return i;
|
||||
})
|
||||
.async()
|
||||
.runWith(Sink.ignore(), mat);
|
||||
// #pipelining
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unused")
|
||||
public void demonstrateBufferSizes() {
|
||||
//#materializer-buffer
|
||||
final Materializer materializer = ActorMaterializer.create(
|
||||
ActorMaterializerSettings.create(system)
|
||||
.withInputBuffer(64, 64), system);
|
||||
//#materializer-buffer
|
||||
// #materializer-buffer
|
||||
final Materializer materializer =
|
||||
ActorMaterializer.create(
|
||||
ActorMaterializerSettings.create(system).withInputBuffer(64, 64), system);
|
||||
// #materializer-buffer
|
||||
|
||||
//#section-buffer
|
||||
// #section-buffer
|
||||
final Flow<Integer, Integer, NotUsed> flow1 =
|
||||
Flow.of(Integer.class)
|
||||
.map(elem -> elem * 2).async()
|
||||
.addAttributes(Attributes.inputBuffer(1, 1)); // the buffer size of this map is 1
|
||||
final Flow<Integer, Integer, NotUsed> flow2 =
|
||||
flow1.via(
|
||||
Flow.of(Integer.class)
|
||||
.map(elem -> elem / 2)).async(); // the buffer size of this map is the default
|
||||
//#section-buffer
|
||||
.map(elem -> elem * 2)
|
||||
.async()
|
||||
.addAttributes(Attributes.inputBuffer(1, 1)); // the buffer size of this map is 1
|
||||
final Flow<Integer, Integer, NotUsed> flow2 =
|
||||
flow1
|
||||
.via(Flow.of(Integer.class).map(elem -> elem / 2))
|
||||
.async(); // the buffer size of this map is the default
|
||||
// #section-buffer
|
||||
}
|
||||
|
||||
@Test
|
||||
public void demonstrateBufferAbstractionLeak() {
|
||||
//#buffering-abstraction-leak
|
||||
// #buffering-abstraction-leak
|
||||
final Duration oneSecond = Duration.ofSeconds(1);
|
||||
final Source<String, Cancellable> msgSource =
|
||||
Source.tick(oneSecond, oneSecond, "message!");
|
||||
final Source<String, Cancellable> msgSource = Source.tick(oneSecond, oneSecond, "message!");
|
||||
final Source<String, Cancellable> tickSource =
|
||||
Source.tick(oneSecond.multipliedBy(3), oneSecond.multipliedBy(3), "tick");
|
||||
final Flow<String, Integer, NotUsed> conflate =
|
||||
Flow.of(String.class).conflateWithSeed(
|
||||
first -> 1, (count, elem) -> count + 1);
|
||||
Flow.of(String.class).conflateWithSeed(first -> 1, (count, elem) -> count + 1);
|
||||
|
||||
RunnableGraph.fromGraph(GraphDSL.create(b -> {
|
||||
// this is the asynchronous stage in this graph
|
||||
final FanInShape2<String, Integer, Integer> zipper =
|
||||
b.add(ZipWith.create((String tick, Integer count) -> count).async());
|
||||
b.from(b.add(msgSource)).via(b.add(conflate)).toInlet(zipper.in1());
|
||||
b.from(b.add(tickSource)).toInlet(zipper.in0());
|
||||
b.from(zipper.out()).to(b.add(Sink.foreach(elem -> System.out.println(elem))));
|
||||
return ClosedShape.getInstance();
|
||||
})).run(mat);
|
||||
//#buffering-abstraction-leak
|
||||
RunnableGraph.fromGraph(
|
||||
GraphDSL.create(
|
||||
b -> {
|
||||
// this is the asynchronous stage in this graph
|
||||
final FanInShape2<String, Integer, Integer> zipper =
|
||||
b.add(ZipWith.create((String tick, Integer count) -> count).async());
|
||||
b.from(b.add(msgSource)).via(b.add(conflate)).toInlet(zipper.in1());
|
||||
b.from(b.add(tickSource)).toInlet(zipper.in0());
|
||||
b.from(zipper.out()).to(b.add(Sink.foreach(elem -> System.out.println(elem))));
|
||||
return ClosedShape.getInstance();
|
||||
}))
|
||||
.run(mat);
|
||||
// #buffering-abstraction-leak
|
||||
}
|
||||
|
||||
@Test
|
||||
public void demonstrateExplicitBuffers() {
|
||||
final Source<Job, NotUsed> inboundJobsConnector = Source.empty();
|
||||
//#explicit-buffers-backpressure
|
||||
// #explicit-buffers-backpressure
|
||||
// Getting a stream of jobs from an imaginary external system as a Source
|
||||
final Source<Job, NotUsed> jobs = inboundJobsConnector;
|
||||
jobs.buffer(1000, OverflowStrategy.backpressure());
|
||||
//#explicit-buffers-backpressure
|
||||
// #explicit-buffers-backpressure
|
||||
|
||||
//#explicit-buffers-droptail
|
||||
// #explicit-buffers-droptail
|
||||
jobs.buffer(1000, OverflowStrategy.dropTail());
|
||||
//#explicit-buffers-droptail
|
||||
// #explicit-buffers-droptail
|
||||
|
||||
//#explicit-buffers-dropnew
|
||||
// #explicit-buffers-dropnew
|
||||
jobs.buffer(1000, OverflowStrategy.dropNew());
|
||||
//#explicit-buffers-dropnew
|
||||
// #explicit-buffers-dropnew
|
||||
|
||||
//#explicit-buffers-drophead
|
||||
// #explicit-buffers-drophead
|
||||
jobs.buffer(1000, OverflowStrategy.dropHead());
|
||||
//#explicit-buffers-drophead
|
||||
// #explicit-buffers-drophead
|
||||
|
||||
//#explicit-buffers-dropbuffer
|
||||
// #explicit-buffers-dropbuffer
|
||||
jobs.buffer(1000, OverflowStrategy.dropBuffer());
|
||||
//#explicit-buffers-dropbuffer
|
||||
// #explicit-buffers-dropbuffer
|
||||
|
||||
//#explicit-buffers-fail
|
||||
// #explicit-buffers-fail
|
||||
jobs.buffer(1000, OverflowStrategy.fail());
|
||||
//#explicit-buffers-fail
|
||||
// #explicit-buffers-fail
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue