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


Java Flow类代码示例

本文整理汇总了Java中akka.stream.javadsl.Flow的典型用法代码示例。如果您正苦于以下问题:Java Flow类的具体用法?Java Flow怎么用?Java Flow使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Flow类属于akka.stream.javadsl包,在下文中一共展示了Flow类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import akka.stream.javadsl.Flow; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    ActorSystem system = ActorSystem.create("ServiceB");
    final Http http = Http.get(system);
    final ActorMaterializer materializer = ActorMaterializer.create(system);
    final Main app = new Main();
    final ActorRef serviceBackendActor = system.actorOf(BackendActor.props(), "backendActor");
    final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow =  app.createRoute(serviceBackendActor).flow(system, materializer);

    final CompletionStage<ServerBinding> binding =
            http.bindAndHandle(
                    routeFlow,
                    ConnectHttp.toHost("localhost", 8081),
                    materializer);

    System.out.println("Server online at http://localhost:8081/\nPress RETURN to stop...");
    System.in.read(); // let it run until user presses return
    binding
            .thenCompose(ServerBinding::unbind) // trigger unbinding from the port
            .thenAccept(unbound -> system.terminate()); // and shutdown when done

}
 
开发者ID:henrikengstrom,项目名称:ujug2017,代码行数:22,代码来源:Main.java

示例2: main

import akka.stream.javadsl.Flow; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
    final ActorSystem system = ActorSystem.create("ServiceA");
    final Http http = Http.get(system);
    final ActorMaterializer materializer = ActorMaterializer.create(system);
    final StreamMain app = new StreamMain();
    final ActorRef streamActor = system.actorOf(StreamActor.props());
    final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = app.createRoute(streamActor).flow(system, materializer);
    final CompletionStage<ServerBinding> binding =
            http.bindAndHandle(
                    routeFlow,
                    ConnectHttp.toHost("localhost", 8080),
                    materializer);

    System.out.println("Server online at http://localhost:8080/\nPress RETURN to stop...");
    System.in.read(); // let it run until user presses return
    System.in.read(); // let it run until user presses return
    binding
            .thenCompose(ServerBinding::unbind) // trigger unbinding from the port
            .thenAccept(unbound -> system.terminate()); // and shutdown when done

}
 
开发者ID:henrikengstrom,项目名称:ujug2017,代码行数:22,代码来源:StreamMain.java

示例3: run

import akka.stream.javadsl.Flow; //导入依赖的package包/类
public void run() {
  final Config conf = parseString("akka.remote.netty.tcp.hostname=" + config.hostname())
          .withFallback(parseString("akka.remote.netty.tcp.port=" + config.actorPort()))
          .withFallback(ConfigFactory.load("remote"));

  final ActorSystem system = ActorSystem.create("concierge", conf);
  kv = system.actorOf(LinearizableStorage.props(new Cluster(config.cluster().paths(), "kv")), "kv");

  final ActorMaterializer materializer = ActorMaterializer.create(system);

  final Flow<HttpRequest, HttpResponse, NotUsed> theFlow = createRoute().flow(system, materializer);

  final ConnectHttp host = ConnectHttp.toHost(config.hostname(), config.clientPort());
  Http.get(system).bindAndHandle(theFlow, host, materializer);

  LOG.info("Ama up");
}
 
开发者ID:marnikitta,项目名称:Concierge,代码行数:18,代码来源:ConciergeApplication.java

示例4: main

import akka.stream.javadsl.Flow; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
    final ActorSystem system = ActorSystem.create();
    final ActorMaterializer materializer = ActorMaterializer.create(system);

    final Route route = InfillionRoutes.routes();
    final Flow<HttpRequest, HttpResponse, NotUsed> flow = route.flow(system, materializer);

    final Http http = Http.get(system);
    final CompletionStage<ServerBinding> bindings = http.bindAndHandle(flow, ConnectHttp.toHost("127.0.0.1", 8080), materializer);

    System.out.println("Type RETURN to exit");
    System.in.read();

    bindings
            .thenCompose(ServerBinding::unbind)
            .thenAccept(unbound -> system.terminate());

}
 
开发者ID:knoldus,项目名称:Infillion,代码行数:19,代码来源:PingPongApiLauncher.java

示例5: testReactiveStream

import akka.stream.javadsl.Flow; //导入依赖的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

示例6: flow

import akka.stream.javadsl.Flow; //导入依赖的package包/类
private Flow<Message,Message,?> flow() {
    return Flow.<Message>create()
        .map(msg -> {
            if (msg.isText()) {
                log.warn("Ignoring unexpected text-kind web socket message {}", msg);
                return Option.<Query.EventEnvelope>none();
            } else {
                return Option.<Query.EventEnvelope>some(Query.EventEnvelope.parseFrom(msg.asBinaryMessage().getStrictData().toArray()));
            }
        })
        .filter(o -> o.isDefined())
        .map(o -> o.get())
        .mapAsync(maxInFlight, e -> ask(shardRegion, e, timeout))
        .map(resp -> (Long) resp)
        .map(l -> BinaryMessage.create(ByteString.fromArray(EventsPersisted.newBuilder().setOffset(l).build().toByteArray())));
}
 
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:17,代码来源:WebSocketDataCenterServer.java

示例7: uploadFlow

import akka.stream.javadsl.Flow; //导入依赖的package包/类
@Override
public Flow<EventEnvelope,Long,?> uploadFlow() {
    ClientConnectionSettings settings = ClientConnectionSettings.create(system.settings().config());
    
    return Flow.<EventEnvelope>create()
        .map(e -> (Message) BinaryMessage.create(serialize(e)))
        .via(Http.get(system).webSocketClientFlow(WebSocketRequest.create(uri), connectionContext, Optional.empty(), settings, system.log()))
        .map(msg -> {
            if (msg.isText()) {
                log.warn("Ignoring unexpected text-type WS message {}", msg);
                return 0l;
            } else {
                EventsPersisted applied = EventsPersisted.parseFrom(
                    msg.asBinaryMessage().getStrictData().iterator().asInputStream());
                return applied.hasOffset() ? applied.getOffset() : 0l;
            }})
        .filter(l -> l > 0);
}
 
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:19,代码来源:WebSocketDataCenterClient.java

示例8: importAll

import akka.stream.javadsl.Flow; //导入依赖的package包/类
public CompletableFuture<Done> importAll() {
    
    AtomicLong batch = new AtomicLong(0);
    long start = System.currentTimeMillis();
    
    final Materializer materializer = ActorMaterializer.create(ActorSystem.create("actor-system", ConfigFactory.load()));
    Source<Page, NotUsed> channelSource = Source.fromIterator(() -> reader);
    
    Flow<Page, List<Page>, NotUsed> processing = Flow.of(Page.class)
                                                     .filter(x -> x != null && x.getNamespace() == 0)
                                                     .buffer(cores * 100, OverflowStrategy.backpressure())
                                                     .mapAsyncUnordered(cores, x -> cleaner.clean(x))
                                                     .groupedWithin(BATCH_SIZE,
                                                                    FiniteDuration.apply(1, TimeUnit.SECONDS))
                                                     .mapAsyncUnordered(cores, x -> datastore.save(x));
    
    final CompletionStage<Done> promise = channelSource.via(processing).runForeach(x -> {
        
        System.out.printf("Inserted: %d, Time: %d sec\n",
                          batch.incrementAndGet() * BATCH_SIZE,
                          (System.currentTimeMillis() - start) / 1000);
    }, materializer);
    
    return promise.toCompletableFuture();
    
}
 
开发者ID:crtomirmajer,项目名称:wiki2mongo,代码行数:27,代码来源:Wiki2MongoImporter.java

示例9: main

import akka.stream.javadsl.Flow; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

        final ActorSystem system = ActorSystem.create("example");
        final ActorMaterializer materializer = ActorMaterializer.create(system);
        final Http http = Http.get(system);

        final MessageDispatcher dispatcher = system.dispatchers().lookup("akka.actor.default-dispatcher");
        final SetSessionJava app = new SetSessionJava(dispatcher);

        final Flow<HttpRequest, HttpResponse, NotUsed> routes = app.createRoutes().flow(system, materializer);
        final CompletionStage<ServerBinding> binding = http.bindAndHandle(routes, ConnectHttp.toHost("localhost", 8080), materializer);

        System.out.println("Server started, press enter to stop");
        System.in.read();

        binding
            .thenCompose(ServerBinding::unbind)
            .thenAccept(unbound -> system.terminate());
    }
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:20,代码来源:SetSessionJava.java

示例10: main

import akka.stream.javadsl.Flow; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

        final ActorSystem system = ActorSystem.create("example");
        final ActorMaterializer materializer = ActorMaterializer.create(system);
        final Http http = Http.get(system);

        final MessageDispatcher dispatcher = system.dispatchers().lookup("akka.actor.default-dispatcher");
        final VariousSessionsJava app = new VariousSessionsJava(dispatcher);

        final Flow<HttpRequest, HttpResponse, NotUsed> routes = app.createRoutes().flow(system, materializer);
        final CompletionStage<ServerBinding> binding = http.bindAndHandle(routes, ConnectHttp.toHost("localhost", 8080), materializer);

        System.out.println("Server started, press enter to stop");
        System.in.read();

        binding
            .thenCompose(ServerBinding::unbind)
            .thenAccept(unbound -> system.terminate());
    }
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:20,代码来源:VariousSessionsJava.java

示例11: main

import akka.stream.javadsl.Flow; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

        // ** akka-http boiler plate **
        ActorSystem system = ActorSystem.create("example");
        final ActorMaterializer materializer = ActorMaterializer.create(system);
        final Http http = Http.get(system);

        // ** akka-http-session setup **
        MessageDispatcher dispatcher = system.dispatchers().lookup("akka.actor.default-dispatcher");
        final SessionInvalidationJava app = new SessionInvalidationJava(dispatcher);

        // ** akka-http boiler plate continued **
        final Flow<HttpRequest, HttpResponse, NotUsed> routes = app.createRoutes().flow(system, materializer);
        final CompletionStage<ServerBinding> binding = http.bindAndHandle(routes, ConnectHttp.toHost("localhost", 8080), materializer);

        System.out.println("Server started, press enter to stop");
        System.in.read();

        binding
            .thenCompose(ServerBinding::unbind)
            .thenAccept(unbound -> system.terminate());
    }
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:23,代码来源:SessionInvalidationJava.java

示例12: main

import akka.stream.javadsl.Flow; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

        // ** akka-http boiler plate **
        ActorSystem system = ActorSystem.create("example");
        final ActorMaterializer materializer = ActorMaterializer.create(system);
        final Http http = Http.get(system);

        // ** akka-http-session setup **
        MessageDispatcher dispatcher = system.dispatchers().lookup("akka.actor.default-dispatcher");
        final JavaJwtExample app = new JavaJwtExample(dispatcher);

        // ** akka-http boiler plate continued **
        final Flow<HttpRequest, HttpResponse, NotUsed> routes = app.createRoutes().flow(system, materializer);
        final CompletionStage<ServerBinding> binding = http.bindAndHandle(routes, ConnectHttp.toHost("localhost", 8080), materializer);

        System.out.println("Server started, press enter to stop");
        System.in.read();

        binding
            .thenCompose(ServerBinding::unbind)
            .thenAccept(unbound -> system.terminate());
    }
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:23,代码来源:JavaJwtExample.java

示例13: main

import akka.stream.javadsl.Flow; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

        // ** akka-http boiler plate **
        ActorSystem system = ActorSystem.create("example");
        final ActorMaterializer materializer = ActorMaterializer.create(system);
        final Http http = Http.get(system);

        // ** akka-http-session setup **
        MessageDispatcher dispatcher = system.dispatchers().lookup("akka.actor.default-dispatcher");
        final JavaExample app = new JavaExample(dispatcher);

        // ** akka-http boiler plate continued **
        final Flow<HttpRequest, HttpResponse, NotUsed> routes = app.createRoutes().flow(system, materializer);
        final CompletionStage<ServerBinding> binding = http.bindAndHandle(routes, ConnectHttp.toHost("localhost", 8080), materializer);

        System.out.println("Server started, press enter to stop");
        System.in.read();

        binding
            .thenCompose(ServerBinding::unbind)
            .thenAccept(unbound -> system.terminate());
    }
 
开发者ID:softwaremill,项目名称:akka-http-session,代码行数:23,代码来源:JavaExample.java

示例14: server

import akka.stream.javadsl.Flow; //导入依赖的package包/类
public static void server(ActorSystem system, InetSocketAddress serverAddress) {
  final ActorMaterializer materializer = ActorMaterializer.create(system);

  final Sink<IncomingConnection, CompletionStage<Done>> handler = Sink.foreach(conn -> {
    System.out.println("Client connected from: " + conn.remoteAddress());
    conn.handleWith(Flow.<ByteString>create(), materializer);
  });


  final CompletionStage<ServerBinding> bindingFuture =
    Tcp.get(system).bind(serverAddress.getHostString(), serverAddress.getPort()).to(handler).run(materializer);

  bindingFuture.handle((ServerBinding binding, Throwable exception) -> {
    if (binding != null) {
      System.out.println("Server started, listening on: " + binding.localAddress());
    } else {
      System.err.println("Server could not bind to " + serverAddress + " : " + exception.getMessage());
      system.shutdown();
    }
    return NotUsed.getInstance();
  });

}
 
开发者ID:typesafehub,项目名称:activator-akka-stream-java8,代码行数:24,代码来源:TcpEcho.java

示例15: InventoryServiceImpl

import akka.stream.javadsl.Flow; //导入依赖的package包/类
@Inject
public InventoryServiceImpl(PersistentEntityRegistry registry, BasketService basketService) {
    this.registry = registry;
    this.basketService = basketService;
    registry.register(InventoryEntity.class);

    // this solution is naïve on the approach and wrong altogether in the implementation
    //  a) when applying a filter in the akka stream, the message is missaligned with the offset
    //  b) updating the inventory should be handled in a way that if a product is out of stock an event is
    //     raised and the shppoing-user is notified so she can decide what to do. Also, the out-of-stock product
    //     must be reimbursed. All this corrective actions are not implemented, on the contrary: when the
    //     InventoryEntity detects there's not enough stock for a given Deacrease operation an exception is throw.
    //     Instead, an event other downstream services can listen to would be more appropriate.
    // I will try to get (a) fixed on further versions of this workshop.
    //
    basketService.basketEvents().subscribe().atLeastOnce(
            Flow.<BasketEvent>create()
                    .filter(b -> b instanceof BasketEvent.BasketCheckedOut)
                    .mapConcat(basketEvent -> {
                        BasketEvent.BasketCheckedOut event = (BasketEvent.BasketCheckedOut) basketEvent;
                        return event.getBasket().getItems();
                    })
                    .mapAsync(1, basketItem ->
                            refFor(basketItem.getId())
                                    .ask(new DecreaseInventory(basketItem.getId(), basketItem.getCount()))
                    ).map(ignored -> Done.getInstance())
    );

}
 
开发者ID:ignasi35,项目名称:lagom-java-workshop,代码行数:30,代码来源:InventoryServiceImpl.java


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