• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Keep类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: AkkaHubProxy

import akka.stream.javadsl.Keep; //导入依赖的package包/类
public AkkaHubProxy(ActorMaterializer mat) {
    this.mat = mat;
    //  Obtain a Sink and Source which will publish and receive from the "bus" respectively.
    Pair<Sink<Object, NotUsed>, Source<Object, NotUsed>> sinkAndSource =
            MergeHub.of(Object.class, 16)
                    .toMat(BroadcastHub.of(Object.class, 256), Keep.both())
                    .run(mat);

    Sink<Object, NotUsed> sink = sinkAndSource.first();
    source = sinkAndSource.second().takeWhile((Predicate<Object>) o -> o != Done.getInstance());
    //source.runWith(Sink.ignore(), mat);
    busFlow = Flow.fromSinkAndSource(sink, source)
            .joinMat(KillSwitches.singleBidi(), Keep.right());
}
 
开发者ID:apptik,项目名称:RHub,代码行数:15,代码来源:AkkaHubProxy.java


示例2: addUpstream

import akka.stream.javadsl.Keep; //导入依赖的package包/类
@Override
public Removable addUpstream(Source<Object, NotUsed> publisher) {
    UniqueKillSwitch killSwitch =
            publisher.viaMat(busFlow, Keep.right())
                    .to(Sink.ignore())
                    .run(mat);
    subscriptions.put(publisher, killSwitch);
    return () -> AkkaHubProxy.this.removeUpstream(publisher);
}
 
开发者ID:apptik,项目名称:RHub,代码行数:10,代码来源:AkkaHubProxy.java


示例3: createReceive

import akka.stream.javadsl.Keep; //导入依赖的package包/类
@Override
public Receive createReceive() {
    return receiveBuilder()
            .match(RequestReply.class, requestReply -> {
                // TODO(barp): Fix the ugly HttpRequest cast here due to java vs scala dsl
                akka.stream.javadsl.Source.single(requestReply.getRequest())
                        .via(_processGraph)
                        .toMat(_sink, Keep.right())
                        .run(_materializer)
                        .whenComplete((done, err) -> {
                            final CompletableFuture<HttpResponse> responseFuture = requestReply.getResponse();
                            if (err == null) {
                                responseFuture.complete(HttpResponse.create().withStatus(200));
                            } else {
                                BAD_REQUEST_LOGGER.warn()
                                        .setMessage("Error handling http post")
                                        .setThrowable(err)
                                        .log();
                                if (err instanceof ParsingException) {
                                    responseFuture.complete(HttpResponse.create().withStatus(400));
                                } else {
                                    responseFuture.complete(HttpResponse.create().withStatus(500));
                                }
                            }
                        });
            })
            .build();
}
 
开发者ID:ArpNetworking,项目名称:metrics-aggregator-daemon,代码行数:29,代码来源:HttpSource.java


示例4: createFlow

import akka.stream.javadsl.Keep; //导入依赖的package包/类
private Flow<ByteString, ByteString, CompletionStage<HttpResponse>> createFlow(HttpMethod method, Uri uri, Option<ContentType> contentType, Predicate<HttpResponse> isSuccess, HttpHeader... headers) {
    Sink<ByteString, Publisher<ByteString>> in = Sink.asPublisher(AsPublisher.WITH_FANOUT); // akka internally recreates this twice, on some errors...
    Source<ByteString, Subscriber<ByteString>> out = Source.asSubscriber();
    
    return Flow.fromSinkAndSourceMat(in, out, Keep.both()).mapMaterializedValue(pair -> {
        RequestEntity entity;
        if (contentType.isDefined()) {
            Source<ByteString, NotUsed> inReader = Source.fromPublisher(pair.first());
            entity = HttpEntities.createChunked(contentType.get(), inReader);
        } else {
            entity = HttpEntities.EMPTY;
        }
        HttpRequest rq = HttpRequest.create().withMethod(method).withUri(uri).addHeaders(Arrays.asList(headers)).withEntity(entity);
        
        return http.singleRequest(rq, materializer).thenApply(resp -> {
            if (isSuccess.test(resp)) {
                resp.entity().getDataBytes()
                    .runWith(Sink.fromSubscriber(pair.second()), materializer);
            } else {
                log.info("Http responded error: {} for request {}", resp, rq);
                resp.discardEntityBytes(materializer);
                pair.second().onError(new IllegalStateException("Unsuccessful HTTP response: " + resp + " for " + rq));
            }
            return resp;
        }).exceptionally(x -> {
            Throwable cause = (x instanceof CompletionException) ? x.getCause() : x;
            if (!(cause instanceof IllegalStateException)) {
                log.info("Could not make http request " + rq, cause);
            }
            pair.second().onError(cause);
            throw (cause instanceof RuntimeException) ? (RuntimeException) x : new RuntimeException(cause);
        });
    });
}
 
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:35,代码来源:HttpFlow.java


示例5: testCreateWebSocketFlow

import akka.stream.javadsl.Keep; //导入依赖的package包/类
@Test
public void testCreateWebSocketFlow() {
    // Injected dependencies to create the controller...
    final TestProbe stocksActorProbe = new TestProbe(system, "stocksActor");
    final TestProbe userParentActorProbe = new TestProbe(system, "userParentActor");

    // Create the controller without having to create a play app...
    final HomeController controller = new HomeController(system,
            materializer,
            webJarAssets,
            stocksActorProbe.ref(),
            userParentActorProbe.ref());

    // input for creating a flow...
    final TestProbe userActorProbe = new TestProbe(system, "userActor");
    TestPublisher.Probe<JsonNode> publisher = TestPublisher.probe(0, system);

    // method under test
    final Flow<JsonNode, JsonNode, NotUsed> flowUnderTest = controller.createWebSocketFlow(publisher, userActorProbe.ref());

    Source<JsonNode, TestPublisher.Probe<JsonNode>> sourceProbe = TestSource.probe(system);

    // create a test source and sink around the flow
    final Pair<TestPublisher.Probe<JsonNode>, TestSubscriber.Probe<JsonNode>> pair = sourceProbe
            .via(flowUnderTest)
            .toMat(TestSink.probe(system), Keep.both())
            .run(materializer);

    final TestPublisher.Probe<JsonNode> pub = pair.first();
    final TestSubscriber.Probe<JsonNode> sub = pair.second();

    // check that a message sent in will come out the other end
    final ObjectNode jsvalue = Json.newObject().put("herp", "derp");
    sub.request(1);
    publisher.sendNext(jsvalue);
    sub.expectNext(jsvalue);
}
 
开发者ID:play2-maven-plugin,项目名称:play2-maven-test-projects,代码行数:38,代码来源:HomeControllerTest.java


示例6: testCreateWebSocketFlow

import akka.stream.javadsl.Keep; //导入依赖的package包/类
@Test
public void testCreateWebSocketFlow() {
    // Injected dependencies to create the controller...
    final TestProbe stocksActorProbe = new TestProbe(system, "stocksActor");
    final TestProbe userParentActorProbe = new TestProbe(system, "userParentActor");

    // Create the controller without having to create a play app...
    final HomeController controller = new HomeController(system,
            materializer,
            stocksActorProbe.ref(),
            userParentActorProbe.ref());

    // input for creating a flow...
    final TestProbe userActorProbe = new TestProbe(system, "userActor");
    TestPublisher.Probe<JsonNode> publisher = TestPublisher.probe(0, system);

    // method under test
    final Flow<JsonNode, JsonNode, NotUsed> flowUnderTest = controller.createWebSocketFlow(publisher, userActorProbe.ref());

    Source<JsonNode, TestPublisher.Probe<JsonNode>> sourceProbe = TestSource.probe(system);

    // create a test source and sink around the flow
    final Pair<TestPublisher.Probe<JsonNode>, TestSubscriber.Probe<JsonNode>> pair = sourceProbe
            .via(flowUnderTest)
            .toMat(TestSink.probe(system), Keep.both())
            .run(materializer);

    final TestPublisher.Probe<JsonNode> pub = pair.first();
    final TestSubscriber.Probe<JsonNode> sub = pair.second();

    // check that a message sent in will come out the other end
    final ObjectNode jsvalue = Json.newObject().put("herp", "derp");
    sub.request(1);
    publisher.sendNext(jsvalue);
    sub.expectNext(jsvalue);
}
 
开发者ID:play2-maven-plugin,项目名称:play2-maven-test-projects,代码行数:37,代码来源:HomeControllerTest.java


示例7: emit

import akka.stream.javadsl.Keep; //导入依赖的package包/类
@Override
public void emit(Object event) {
    Source.single(event).viaMat(busFlow, Keep.right())
            .to(Sink.ignore())
            .run(mat);
}
 
开发者ID:apptik,项目名称:RHub,代码行数:7,代码来源:AkkaHubProxy.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PlainCstInsn类代码示例发布时间:2022-05-22
下一篇:
Java BorderData类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap