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

Java FutureConverters类代码示例

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

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



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

示例1: onProducerRemoved

import scala.compat.java8.FutureConverters; //导入依赖的package包/类
private void onProducerRemoved(final ProducerRemoved message) {
    LOG.debug("Received ProducerRemoved: {}", message);

    final List<CompletableFuture<Object>> futures = new ArrayList<>();

    for (final String address : resolver.getShardingServicePeerActorAddresses()) {
        final ActorSelection selection = actorSystem.actorSelection(address);

        futures.add(FutureConverters.toJava(
                actorContext.executeOperationAsync(selection, new NotifyProducerRemoved(message.getSubtrees())))
                .toCompletableFuture());
    }

    final CompletableFuture<Void> combinedFuture = CompletableFuture.allOf(
            futures.toArray(new CompletableFuture[futures.size()]));

    final ActorRef respondTo = getSender();

    combinedFuture
            .thenRun(() -> respondTo.tell(new Status.Success(null), self()))
            .exceptionally(e -> {
                respondTo.tell(new Status.Failure(null), self());
                return null;
            });

}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:27,代码来源:ShardedDataTreeActor.java


示例2: close

import scala.compat.java8.FutureConverters; //导入依赖的package包/类
@Override
public CompletionStage<Void> close() {
    // first despawn on the local node
    distributedShardedDOMDataTree.despawnShardFrontend(prefix);
    // update the config so the remote nodes are updated
    final Future<Object> ask =
            Patterns.ask(shardedDataTreeActor, new PrefixShardRemovalLookup(prefix), SHARD_FUTURE_TIMEOUT);

    final Future<Void> closeFuture = ask.transform(
            new Mapper<Object, Void>() {
                @Override
                public Void apply(final Object parameter) {
                    return null;
                }
            },
            new Mapper<Throwable, Throwable>() {
                @Override
                public Throwable apply(final Throwable throwable) {
                    return throwable;
                }
            }, actorSystem.dispatcher());

    return FutureConverters.toJava(closeFuture);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:25,代码来源:DistributedShardedDOMDataTree.java


示例3: channelsRegistry

import scala.compat.java8.FutureConverters; //导入依赖的package包/类
@Bean
public ChannelsRegistry channelsRegistry() {
    ChannelsActors channelsActors = channelsActors();
    return tempo -> {
        Future<Object> result = Patterns.ask(channelsActors.get(tempo), ListChannels.instance(), 1000);
        CompletionStage<Object> stage = FutureConverters.toJava(result);
        return stage.thenCompose(o -> {
            if (o instanceof Channels) {
                return CompletableFuture.completedFuture(((Channels) o).getChannels());
            }
            else {
                CompletableFuture<List<Channel>> f = new CompletableFuture<>();
                f.completeExceptionally(new IllegalStateException());
                return f;
            }
        });
    };
}
 
开发者ID:nosceon,项目名称:tenorite,代码行数:19,代码来源:ChannelsConfig.java


示例4: createRoute

import scala.compat.java8.FutureConverters; //导入依赖的package包/类
private Route createRoute(ActorRef streamActor) {
    return route(
            path(segment("services").slash(longSegment()), id ->
                    get(() -> {
                        Promise<HttpResponse> promise = Futures.promise();
                        streamActor.tell(new Pair(id, promise), ActorRef.noSender());
                        return completeWithFuture(FutureConverters.toJava(promise.future()));
                    })));
}
 
开发者ID:henrikengstrom,项目名称:ujug2017,代码行数:10,代码来源:StreamMain.java


示例5: resolveBackendInfo

import scala.compat.java8.FutureConverters; //导入依赖的package包/类
protected final ShardState resolveBackendInfo(final String shardName, final long cookie) {
    LOG.debug("Resolving cookie {} to shard {}", cookie, shardName);

    final CompletableFuture<ShardBackendInfo> future = new CompletableFuture<>();
    FutureConverters.toJava(actorContext.findPrimaryShardAsync(shardName)).whenComplete((info, failure) -> {
        if (failure == null) {
            connectShard(shardName, cookie, info, future);
            return;
        }

        LOG.debug("Shard {} failed to resolve", shardName, failure);
        if (failure instanceof NoShardLeaderException) {
            future.completeExceptionally(wrap("Shard has no current leader", failure));
        } else if (failure instanceof NotInitializedException) {
            // FIXME: this actually is an exception we can retry on
            LOG.info("Shard {} has not initialized yet", shardName);
            future.completeExceptionally(failure);
        } else if (failure instanceof PrimaryNotFoundException) {
            LOG.info("Failed to find primary for shard {}", shardName);
            future.completeExceptionally(failure);
        } else {
            future.completeExceptionally(failure);
        }
    });

    return new ShardState(future);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:28,代码来源:AbstractShardBackendResolver.java


示例6: connectShard

import scala.compat.java8.FutureConverters; //导入依赖的package包/类
private void connectShard(final String shardName, final long cookie, final PrimaryShardInfo info,
        final CompletableFuture<ShardBackendInfo> future) {
    LOG.debug("Shard {} resolved to {}, attempting to connect", shardName, info);

    FutureConverters.toJava(ExplicitAsk.ask(info.getPrimaryShardActor(), connectFunction, CONNECT_TIMEOUT))
        .whenComplete((response, failure) -> {
            onConnectResponse(shardName, cookie, future, response, failure);
        });
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:10,代码来源:AbstractShardBackendResolver.java


示例7: onProducerCreated

import scala.compat.java8.FutureConverters; //导入依赖的package包/类
private void onProducerCreated(final ProducerCreated message) {
    LOG.debug("Received ProducerCreated: {}", message);

    // fastpath if we have no peers
    if (resolver.getShardingServicePeerActorAddresses().isEmpty()) {
        getSender().tell(new Status.Success(null), noSender());
    }

    final ActorRef sender = getSender();
    final Collection<DOMDataTreeIdentifier> subtrees = message.getSubtrees();

    final List<CompletableFuture<Object>> futures = new ArrayList<>();

    for (final String address : resolver.getShardingServicePeerActorAddresses()) {
        final ActorSelection actorSelection = actorSystem.actorSelection(address);
        futures.add(
                FutureConverters.toJava(
                        actorContext.executeOperationAsync(
                                actorSelection, new NotifyProducerCreated(subtrees), DEFAULT_ASK_TIMEOUT))
                .toCompletableFuture());
    }

    final CompletableFuture<Void> combinedFuture = CompletableFuture.allOf(
            futures.toArray(new CompletableFuture[futures.size()]));

    combinedFuture
            .thenRun(() -> sender.tell(new Success(null), noSender()))
            .exceptionally(throwable -> {
                sender.tell(new Status.Failure(throwable), self());
                return null;
            });
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:33,代码来源:ShardedDataTreeActor.java


示例8: dispatchHttpRequest

import scala.compat.java8.FutureConverters; //导入依赖的package包/类
private CompletionStage<HttpResponse> dispatchHttpRequest(final HttpRequest request, final String actorName) {
    final Future<ActorRef> refFuture = _actorSystem.actorSelection(actorName)
            .resolveOne(FiniteDuration.create(1, TimeUnit.SECONDS));
    return FutureConverters.toJava(refFuture).thenCompose(
            ref -> {
                final CompletableFuture<HttpResponse> response = new CompletableFuture<>();
                ref.tell(new RequestReply(request, response), ActorRef.noSender());
                return response;
            })
            // We return 404 here since actor startup is controlled by config and
            // the actors may not be running.
            .exceptionally(err -> HttpResponse.create().withStatus(404));
}
 
开发者ID:ArpNetworking,项目名称:metrics-aggregator-daemon,代码行数:14,代码来源:Routes.java


示例9: ask

import scala.compat.java8.FutureConverters; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T> CompletionStage<T> ask(final String actorPath, final Object request, final T defaultValue) {
    return FutureConverters.toJava(
            (Future<T>) Patterns.ask(
                    _actorSystem.actorSelection(actorPath),
                    request,
                    Timeout.apply(1, TimeUnit.SECONDS)))
            .exceptionally(throwable -> defaultValue);
}
 
开发者ID:ArpNetworking,项目名称:metrics-aggregator-daemon,代码行数:10,代码来源:Routes.java


示例10: createUserActor

import scala.compat.java8.FutureConverters; //导入依赖的package包/类
public CompletionStage<ActorRef> createUserActor(String id, ActorRef webSocketOut) {
    // Use guice assisted injection to instantiate and configure the child actor.
    long timeoutMillis = 100L;
    return FutureConverters.toJava(
            ask(userParentActor, new UserParentActor.Create(id, webSocketOut), timeoutMillis)
    ).thenApply(stageObj -> (ActorRef) stageObj);
}
 
开发者ID:play2-maven-plugin,项目名称:play2-maven-test-projects,代码行数:8,代码来源:HomeController.java


示例11: waitOnAsyncTask

import scala.compat.java8.FutureConverters; //导入依赖的package包/类
protected static <T> T waitOnAsyncTask(final CompletionStage<T> completionStage, final Duration timeout)
        throws Exception {
    return Await.result(FutureConverters.toScala(completionStage), timeout);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:5,代码来源:AbstractTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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