scala.concurrent.Future.map()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中scala.concurrent.Future.map()方法的一些代码示例,展示了Future.map()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Future.map()方法的具体详情如下:
包路径:scala.concurrent.Future
类名称:Future
方法名:map

Future.map介绍

暂无

代码示例

代码示例来源:origin: write2munish/Akka-Essentials

final Future<OrderHistory> aggResult = aggregate.map(
    new Mapper<Iterable<Object>, OrderHistory>() {
      public OrderHistory apply(Iterable<Object> coll) {

代码示例来源:origin: traneio/future

@Benchmark
public String mapConstN() throws Exception {
 Future<String> f = constFuture;
 for (int i = 0; i < N.n; i++)
  f = f.map(mapF, ec);
 return Await.result(f, inf);
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.10

@Override
public void notifyLeaderAddress(String leaderAddress, final UUID leaderSessionID) {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Received leader address notification {}:{}", leaderAddress, leaderSessionID);
  }
  if (leaderAddress == null) {
    jobManagerFuture = UNKNOWN_JOB_MANAGER;
  } else {
    jobManagerFuture = AkkaUtils.getActorRefFuture(leaderAddress, actorSystem, askTimeout)
        .map(new Mapper<ActorRef, ActorGateway>() {
          @Override
          public ActorGateway apply(ActorRef actorRef) {
            return new AkkaActorGateway(actorRef, leaderSessionID);
          }
        }, actorSystem.dispatcher());
  }
}

代码示例来源:origin: uk.gov.hmrc/microservice-bootstrap-java

default F.Promise<Result> wrapAndReturn(Future<play.api.mvc.Result> result) {
  JFunction1<play.api.mvc.Result, Result> resultConverter = scalaResult -> (Result) () -> scalaResult;
  ExecutionContext ec = play.api.libs.concurrent.Execution.defaultContext();
  return F.Promise.wrap(result.map(resultConverter, ec));
}

代码示例来源:origin: traneio/future

@Benchmark
public String mapConst() throws Exception {
 return Await.result(constFuture.map(mapF, ec), inf);
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.11

@Override
public void notifyLeaderAddress(final String leaderAddress, final UUID leaderSessionID) {
  if(leaderAddress != null && !leaderAddress.equals("") && !futureActorGateway.isCompleted()) {
    AkkaUtils.getActorRefFuture(leaderAddress, actorSystem, timeout)
      .map(new Mapper<ActorRef, ActorGateway>() {
        public ActorGateway apply(ActorRef ref) {
          return new AkkaActorGateway(ref, leaderSessionID);
        }
      }, actorSystem.dispatcher())
      .onComplete(new OnComplete<ActorGateway>() {
        @Override
        public void onComplete(Throwable failure, ActorGateway success) throws Throwable {
          if (failure == null) {
            completePromise(success);
          } else {
            LOG.debug("Could not retrieve the leader for address " + leaderAddress + ".", failure);
          }
        }
      }, actorSystem.dispatcher());
  }
}

代码示例来源:origin: com.typesafe.play/play-java-ws

/**
 * Check the identity of the user from the current request, that should be the callback from the OpenID server
 */
@Override
public CompletionStage<UserInfo> verifiedId(Http.RequestHeader request) {
  scala.concurrent.Future<UserInfo> scalaPromise = client.verifiedId(request.queryString()).map(
      new AbstractFunction1<play.api.libs.openid.UserInfo, UserInfo>() {
        @Override
        public UserInfo apply(play.api.libs.openid.UserInfo scalaUserInfo) {
          return new UserInfo(scalaUserInfo.id(), JavaConversions.mapAsJavaMap(scalaUserInfo.attributes()));
        }
      }, Execution.internalContext());
  return FutureConverters.toJava(scalaPromise);
}

代码示例来源:origin: com.alibaba.blink/flink-runtime

@Override
public void notifyLeaderAddress(final String leaderAddress, final UUID leaderSessionID) {
  if(leaderAddress != null && !leaderAddress.equals("") && !futureActorGateway.isCompleted()) {
    AkkaUtils.getActorRefFuture(leaderAddress, actorSystem, timeout)
      .map(new Mapper<ActorRef, ActorGateway>() {
        public ActorGateway apply(ActorRef ref) {
          return new AkkaActorGateway(ref, leaderSessionID);
        }
      }, actorSystem.dispatcher())
      .onComplete(new OnComplete<ActorGateway>() {
        @Override
        public void onComplete(Throwable failure, ActorGateway success) throws Throwable {
          if (failure == null) {
            completePromise(success);
          } else {
            LOG.debug("Could not retrieve the leader for address " + leaderAddress + ".", failure);
          }
        }
      }, actorSystem.dispatcher());
  }
}

代码示例来源:origin: org.apache.flink/flink-runtime

@Override
public void notifyLeaderAddress(final String leaderAddress, final UUID leaderSessionID) {
  if(leaderAddress != null && !leaderAddress.equals("") && !futureActorGateway.isCompleted()) {
    AkkaUtils.getActorRefFuture(leaderAddress, actorSystem, timeout)
      .map(new Mapper<ActorRef, ActorGateway>() {
        public ActorGateway apply(ActorRef ref) {
          return new AkkaActorGateway(ref, leaderSessionID);
        }
      }, actorSystem.dispatcher())
      .onComplete(new OnComplete<ActorGateway>() {
        @Override
        public void onComplete(Throwable failure, ActorGateway success) throws Throwable {
          if (failure == null) {
            completePromise(success);
          } else {
            LOG.debug("Could not retrieve the leader for address " + leaderAddress + ".", failure);
          }
        }
      }, actorSystem.dispatcher());
  }
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.10

@Override
public void notifyLeaderAddress(final String leaderAddress, final UUID leaderSessionID) {
  if(leaderAddress != null && !leaderAddress.equals("") && !futureActorGateway.isCompleted()) {
    AkkaUtils.getActorRefFuture(leaderAddress, actorSystem, timeout)
      .map(new Mapper<ActorRef, ActorGateway>() {
        public ActorGateway apply(ActorRef ref) {
          return new AkkaActorGateway(ref, leaderSessionID);
        }
      }, actorSystem.dispatcher())
      .onComplete(new OnComplete<ActorGateway>() {
        @Override
        public void onComplete(Throwable failure, ActorGateway success) throws Throwable {
          if (failure == null) {
            completePromise(success);
          } else {
            LOG.debug("Could not retrieve the leader for address " + leaderAddress + ".", failure);
          }
        }
      }, actorSystem.dispatcher());
  }
}

代码示例来源:origin: traneio/future

@Benchmark
public String setValueN() throws Exception {
 Promise<String> p = Promise.<String>apply();
 Future<String> f = p.future();
 for (int i = 0; i < N.n; i++)
  f = f.map(mapF, ec);
 p.success(string);
 return Await.result(f, inf);
}

代码示例来源:origin: traneio/future

@Benchmark
public String mapPromise() throws Exception {
 Promise<String> p = Promise.<String>apply();
 Future<String> f = p.future().map(mapF, ec);
 p.success(string);
 return Await.result(f, inf);
}

代码示例来源:origin: traneio/future

@Benchmark
public String mapPromiseN() throws Exception {
 Promise<String> p = Promise.<String>apply();
 Future<String> f = p.future();
 for (int i = 0; i < N.n; i++)
  f = f.map(mapF, ec);
 p.success(string);
 return Await.result(f, inf);
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.10

@Override
public <R> Future<R> thenApplyAsync(final ApplyFunction<? super T, ? extends R> applyFunction, Executor executor) {
  Preconditions.checkNotNull(scalaFuture);
  Preconditions.checkNotNull(applyFunction);
  Preconditions.checkNotNull(executor);
  scala.concurrent.Future<R> mappedFuture = scalaFuture.map(new Mapper<T, R>() {
    @Override
    public R apply(T value) {
      return applyFunction.apply(value);
    }
  }, createExecutionContext(executor));
  return new FlinkFuture<>(mappedFuture);
}

代码示例来源:origin: org.apache.flink/flink-runtime_2.10

@Override
public Future<Void> thenAcceptAsync(final AcceptFunction<? super T> acceptFunction, Executor executor) {
  Preconditions.checkNotNull(scalaFuture);
  Preconditions.checkNotNull(acceptFunction);
  Preconditions.checkNotNull(executor);
  scala.concurrent.Future<Void> acceptedFuture = scalaFuture.map(new Mapper<T, Void>() {
    @Override
    public Void apply(T value) {
      acceptFunction.accept(value);
      return null;
    }
  }, createExecutionContext(executor));
  return new FlinkFuture<>(acceptedFuture);
}

代码示例来源:origin: play/play-java

/**
 * Check the identity of the user from the current request, that should be the callback from the OpenID server
 */
public static F.Promise<UserInfo> verifiedId() {
  Request request = Http.Context.current().request();
  scala.concurrent.Future<UserInfo> scalaPromise = play.api.libs.openid.OpenID.verifiedId(request.queryString()).map(
      new AbstractFunction1<play.api.libs.openid.UserInfo, UserInfo>() {
        @Override
        public UserInfo apply(play.api.libs.openid.UserInfo scalaUserInfo) {
          return new UserInfo(scalaUserInfo.id(), JavaConversions.mapAsJavaMap(scalaUserInfo.attributes()));
        }
      },Invoker.executionContext());
  return new F.Promise<UserInfo>(scalaPromise);
}

代码示例来源:origin: org.opendaylight.controller/sal-remoterpc-connector

/**
 * Gets the buckets from bucket store for the given node addresses and sends them to remote gossiper
 *
 * @param remote     remote node to send Buckets to
 * @param addresses  node addresses whose buckets needs to be sent
 */
void sendGossipTo(final ActorRef remote, final Set<Address> addresses){
  Future<Object> futureReply =
      Patterns.ask(getContext().parent(), new GetBucketsByMembers(addresses), config.getAskDuration());
  futureReply.map(getMapperToSendGossip(remote), getContext().dispatcher());
}

代码示例来源:origin: org.opendaylight.controller/sal-remoterpc-connector

/**
 * Process gossip status received from a remote gossiper. Remote versions are compared with
 * the local copy. <p>
 *
 * For each bucket
 * <ul>
 *  <li>If local copy is newer, the newer buckets are sent in GossipEnvelope to remote</li>
 *  <li>If local is older, GossipStatus is sent to remote so that it can reply with GossipEnvelope</li>
 *  <li>If both are same, noop</li>
 * </ul>
 *
 * @param status bucket versions from a remote member
 */
void receiveGossipStatus(GossipStatus status){
  //Don't accept messages from non-members
  if (!clusterMembers.contains(status.from())) {
    return;
  }
  final ActorRef sender = getSender();
  Future<Object> futureReply =
      Patterns.ask(getContext().parent(), new GetBucketVersions(), config.getAskDuration());
  futureReply.map(getMapperToProcessRemoteStatus(sender, status), getContext().dispatcher());
}

代码示例来源:origin: org.opendaylight.controller/sal-remoterpc-connector

/**
 * Gets bucket versions from bucket store and sends to the supplied address
 *
 * @param remoteActorSystemAddress remote gossiper to send to
 */
void getLocalStatusAndSendTo(Address remoteActorSystemAddress){
  //Get local status from bucket store and send to remote
  Future<Object> futureReply =
      Patterns.ask(getContext().parent(), new GetBucketVersions(), config.getAskDuration());
  //Find gossiper on remote system
  ActorSelection remoteRef = getContext().system().actorSelection(
      remoteActorSystemAddress.toString() + getSelf().path().toStringWithoutAddress());
  if(log.isTraceEnabled()) {
    log.trace("Sending bucket versions to [{}]", remoteRef);
  }
  futureReply.map(getMapperToSendLocalStatus(remoteRef), getContext().dispatcher());
}

代码示例来源:origin: keeps/roda

@Override
public void onReceive(Object message) {
 Timeout timeout = new Timeout(5, TimeUnit.SECONDS);
 Future<Object> f = ask(masterProxy, message, timeout);
 final ExecutionContext ec = getContext().system().dispatcher();
 Future<Object> res = f.map(new Mapper<Object, Object>() {
  @Override
  public Object apply(Object msg) {
   if (msg instanceof Master.Ack)
    return Ok.getInstance();
   else
    return super.apply(msg);
  }
 }, ec).recover(new Recover<Object>() {
  @Override
  public Object recover(Throwable failure) throws Throwable {
   return NotOk.getInstance();
  }
 }, ec);
 pipe(res, ec).to(getSender());
}

相关文章