本文整理汇总了Java中akka.stream.javadsl.Source.range方法的典型用法代码示例。如果您正苦于以下问题:Java Source.range方法的具体用法?Java Source.range怎么用?Java Source.range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类akka.stream.javadsl.Source
的用法示例。
在下文中一共展示了Source.range方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReactiveStream
import akka.stream.javadsl.Source; //导入方法依赖的package包/类
@Test
public void testReactiveStream() throws InterruptedException, TimeoutException {
final ActorSystem system =
ActorSystem.create("MySystem");
final Materializer mat =
ActorMaterializer.create(system);
Source<Integer, NotUsed> source = Source.range(1, 5);
Flow<Integer, Integer, NotUsed> flow = Flow
.fromFunction(x -> x + 1);
Source<Integer, NotUsed> source2 = source.via(flow);
Sink<Integer, CompletionStage<Integer>> fold =
Sink.<Integer, Integer>fold(0, (next, total) -> total + next);
CompletionStage<Integer> integerCompletionStage = source2.runWith(fold, mat);
integerCompletionStage.thenAccept(System.out::println);
Thread.sleep(3000);
Await.ready(system.terminate(), Duration.apply(10, TimeUnit.SECONDS));
}
示例2: run1
import akka.stream.javadsl.Source; //导入方法依赖的package包/类
private void run1() {
final ActorSystem actorSystem = ActorSystem.create();
final Materializer materializer = ActorMaterializer.create(actorSystem);
final Source<Integer, NotUsed> source = Source.range(0, 10);
final Flow<Integer, String, NotUsed> flow = Flow.fromFunction((Integer i) -> i.toString());
final Sink<String, CompletionStage<Done>> sink = Sink.foreach(s -> System.out.println("Example1 - Number: " + s));
final RunnableGraph runnable = source.via(flow).to(sink);
runnable.run(materializer);
actorSystem.terminate();
}