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

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

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

Future.recover介绍

暂无

代码示例

代码示例来源:origin: org.opendaylight.controller/sal-distributed-datastore

@Override
  public Future<Object> apply(final CanCommit input) {
    return Patterns.ask(input.getCohort(), input, timeout).recover(EXCEPTION_TO_MESSAGE,
        ExecutionContexts.global());
  }
}, ExecutionContexts.global());

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

@Override
public <R> Future<R> exceptionallyAsync(final ApplyFunction<Throwable, ? extends R> exceptionallyFunction, Executor executor) {
  Preconditions.checkNotNull(scalaFuture);
  Preconditions.checkNotNull(exceptionallyFunction);
  Preconditions.checkNotNull(executor);
  scala.concurrent.Future<R> recoveredFuture = scalaFuture.recover(new Recover<R>() {
    @Override
    public R recover(Throwable failure) throws Throwable {
      return exceptionallyFunction.apply(failure);
    }
  }, createExecutionContext(executor));
  return new FlinkFuture<>(recoveredFuture);
}

代码示例来源: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());
}

相关文章