当前位置: 首页>>代码示例>>Java>>正文


Java Source.runWith方法代码示例

本文整理汇总了Java中akka.stream.javadsl.Source.runWith方法的典型用法代码示例。如果您正苦于以下问题:Java Source.runWith方法的具体用法?Java Source.runWith怎么用?Java Source.runWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在akka.stream.javadsl.Source的用法示例。


在下文中一共展示了Source.runWith方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
 
开发者ID:dhinojosa,项目名称:intro_to_reactive,代码行数:24,代码来源:ReactiveStreamsTest.java

示例2: testReactiveStreamRefined

import akka.stream.javadsl.Source; //导入方法依赖的package包/类
@Test
public void testReactiveStreamRefined() throws InterruptedException, TimeoutException {
    final ActorSystem system =
            ActorSystem.create("MySystem");

    final Materializer mat =
            ActorMaterializer.create(system);

    Source<Integer, NotUsed> source = Source.range(1, 5).map(x -> x + 1)
            .fold(0, (next, total) -> total + next);

    CompletionStage<Integer> integerCompletionStage =
            source.runWith(Sink.head(), mat);

    integerCompletionStage.thenAccept(System.out::println);
    Thread.sleep(3000);
    Await.ready(system.terminate(), Duration.apply(10, TimeUnit.SECONDS));
}
 
开发者ID:dhinojosa,项目名称:intro_to_reactive,代码行数:19,代码来源:ReactiveStreamsTest.java

示例3: shouldIncludeSomeOldChirpsInLiveFeed

import akka.stream.javadsl.Source; //导入方法依赖的package包/类
@Test
public void shouldIncludeSomeOldChirpsInLiveFeed() throws Exception {
  ChirpService chirpService = server.client(ChirpService.class);

  Chirp chirp1 = Chirp.of("usr3", "hi 1");
  chirpService.addChirp("usr3").invoke(chirp1).toCompletableFuture().get(3, SECONDS);

  Chirp chirp2 = Chirp.of("usr4", "hi 2");
  chirpService.addChirp("usr4").invoke(chirp2).toCompletableFuture().get(3, SECONDS);

  LiveChirpsRequest request = LiveChirpsRequest.of(TreePVector.<String>empty().plus("usr3").plus("usr4"));
  Source<Chirp, ?> chirps = chirpService.getLiveChirps("user3").invoke(request).toCompletableFuture().get(3, SECONDS);
  Probe<Chirp> probe = chirps.runWith(TestSink.probe(server.system()), server.materializer());
  probe.request(10);
  probe.expectNextUnordered(chirp1, chirp2);

  Chirp chirp3 = Chirp.of("usr4", "hi 3");
  chirpService.addChirp("usr4").invoke(chirp3).toCompletableFuture().get(3, SECONDS);
  probe.expectNext(chirp3);

  probe.cancel();
}
 
开发者ID:negokaz,项目名称:lagom-hands-on-development,代码行数:23,代码来源:ChirpServiceTest.java

示例4: shouldRetrieveOldChirps

import akka.stream.javadsl.Source; //导入方法依赖的package包/类
@Test
public void shouldRetrieveOldChirps() throws Exception {
  ChirpService chirpService = server.client(ChirpService.class);

  Chirp chirp1 = Chirp.of("usr5", "msg 1");
  chirpService.addChirp("usr5").invoke(chirp1).toCompletableFuture().get(3, SECONDS);

  Chirp chirp2 = Chirp.of("usr6", "msg 2");
  chirpService.addChirp("usr6").invoke(chirp2).toCompletableFuture().get(3, SECONDS);

  HistoricalChirpsRequest request = HistoricalChirpsRequest.of(Instant.now().minusSeconds(20),
      TreePVector.<String>empty().plus("usr5").plus("usr6"));
  Source<Chirp, ?> chirps = chirpService.getHistoricalChirps().invoke(request).toCompletableFuture().get(3, SECONDS);
  Probe<Chirp> probe = chirps.runWith(TestSink.probe(server.system()), server.materializer());
  probe.request(10);
  probe.expectNextUnordered(chirp1, chirp2);
  probe.expectComplete();
}
 
开发者ID:negokaz,项目名称:lagom-hands-on-development,代码行数:19,代码来源:ChirpServiceTest.java

示例5: filter

import akka.stream.javadsl.Source; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected <T> Publisher<T> filter(Processor processor, final Class<T> filterClass) {
    Source src = Source.fromPublisher(processor)
            .filter(o -> filterClass.isAssignableFrom(o.getClass()));
    return (Publisher<T>) src.runWith(Sink.asPublisher(AsPublisher.WITH_FANOUT), mat);
}
 
开发者ID:apptik,项目名称:RHub,代码行数:8,代码来源:AkkaProcProxy.java

示例6: shouldPublishShirpsToSubscribers

import akka.stream.javadsl.Source; //导入方法依赖的package包/类
@Test
public void shouldPublishShirpsToSubscribers() throws Exception {
    ChirpService chirpService = server.client(ChirpService.class);
    LiveChirpsRequest request = new LiveChirpsRequest(TreePVector.<String>empty().plus("usr1").plus("usr2"));
    Source<Chirp, ?> chirps1 = chirpService.getLiveChirps().invoke(request).toCompletableFuture().get(3, SECONDS);
    Probe<Chirp> probe1 = chirps1.runWith(TestSink.probe(server.system()), server.materializer());
    probe1.request(10);
    Source<Chirp, ?> chirps2 = chirpService.getLiveChirps().invoke(request).toCompletableFuture().get(3, SECONDS);
    Probe<Chirp> probe2 = chirps2.runWith(TestSink.probe(server.system()), server.materializer());
    probe2.request(10);

    Chirp chirp1 = new Chirp("usr1", "hello 1");
    chirpService.addChirp("usr1").invoke(chirp1).toCompletableFuture().get(3, SECONDS);
    probe1.expectNext(chirp1);
    probe2.expectNext(chirp1);

    Chirp chirp2 = new Chirp("usr1", "hello 2");
    chirpService.addChirp("usr1").invoke(chirp2).toCompletableFuture().get(3, SECONDS);
    probe1.expectNext(chirp2);
    probe2.expectNext(chirp2);

    Chirp chirp3 = new Chirp("usr2", "hello 3");
    chirpService.addChirp("usr2").invoke(chirp3).toCompletableFuture().get(3, SECONDS);
    probe1.expectNext(chirp3);
    probe2.expectNext(chirp3);

    probe1.cancel();
    probe2.cancel();
}
 
开发者ID:lagom,项目名称:lagom-java-chirper-example,代码行数:30,代码来源:ChirpServiceTest.java

示例7: shouldPublishShirpsToSubscribers

import akka.stream.javadsl.Source; //导入方法依赖的package包/类
@Test
public void shouldPublishShirpsToSubscribers() throws Exception {
  ChirpService chirpService = server.client(ChirpService.class);
  LiveChirpsRequest request = LiveChirpsRequest.of(TreePVector.<String>empty().plus("usr1").plus("usr2"));
  Source<Chirp, ?> chirps1 = chirpService.getLiveChirps("user1").invoke(request).toCompletableFuture().get(3, SECONDS);
  Probe<Chirp> probe1 = chirps1.runWith(TestSink.probe(server.system()), server.materializer());
  probe1.request(10);
  Source<Chirp, ?> chirps2 = chirpService.getLiveChirps("user1").invoke(request).toCompletableFuture().get(3, SECONDS);
  Probe<Chirp> probe2 = chirps2.runWith(TestSink.probe(server.system()), server.materializer());
  probe2.request(10);

  Chirp chirp1 = Chirp.of("usr1", "hello 1");
  chirpService.addChirp("usr1").invoke(chirp1).toCompletableFuture().get(3, SECONDS);
  probe1.expectNext(chirp1);
  probe2.expectNext(chirp1);

  Chirp chirp2 = Chirp.of("usr1", "hello 2");
  chirpService.addChirp("usr1").invoke(chirp2).toCompletableFuture().get(3, SECONDS);
  probe1.expectNext(chirp2);
  probe2.expectNext(chirp2);

  Chirp chirp3 = Chirp.of("usr2", "hello 3");
  chirpService.addChirp("usr2").invoke(chirp3).toCompletableFuture().get(3, SECONDS);
  probe1.expectNext(chirp3);
  probe2.expectNext(chirp3);

  probe1.cancel();
  probe2.cancel();
}
 
开发者ID:negokaz,项目名称:lagom-hands-on-development,代码行数:30,代码来源:ChirpServiceTest.java

示例8: _RxJavaAndAkkaStreams

import akka.stream.javadsl.Source; //导入方法依赖的package包/类
@Test
public void _RxJavaAndAkkaStreams() {
    new JavaTestKit(system) {
        {
            JavaTestKit probe = new JavaTestKit(system);
            LoggingAdapter log = Logging.getLogger(probe.getSystem(), this);

            long start = System.nanoTime();
            ActorFlowMaterializer mat = ActorFlowMaterializer.create(system);

            Subscriber<Integer> subscriber = RxReactiveStreams.toSubscriber(new rx.Subscriber<Integer>() {
                @Override
                public void onCompleted() {
                }

                @Override
                public void onError(Throwable e) {
                }

                @Override
                public void onNext(Integer integer) {
                    log.info("subscribe:" + integer.toString());
                }
            });

            Observable<Integer> range = Observable.range(1, 10);

            Publisher<Integer> publisher = RxReactiveStreams.toPublisher(range);

            publisher.subscribe(subscriber);

            Source<Integer, BoxedUnit> source = Source
                    .from(publisher)
                    .map(i -> i * 2)
                    .scan(0, (prev, next) -> prev + next);

            Publisher<Integer> akkaPublisher = source.runWith(Sink.fanoutPublisher(1, 1), mat);

            RxReactiveStreams.toObservable(akkaPublisher).map(s -> "result:" + s).toBlocking().forEach(log::info);

            long end = System.nanoTime();

            log.info(TimeUnit.MILLISECONDS.convert((end - start), TimeUnit.NANOSECONDS) + "ms");
        }
    };
}
 
开发者ID:grimrose,项目名称:jjug-2015-reactive-streams,代码行数:47,代码来源:CollaborationTest.java


注:本文中的akka.stream.javadsl.Source.runWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。