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

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

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

Future.onComplete介绍

暂无

代码示例

代码示例来源:origin: apache/flink

actorSystem.terminate().onComplete(
  new OnComplete<Terminated>() {
    public void onComplete(Throwable failure, Terminated result) {

代码示例来源:origin: org.deeplearning4j/deeplearning4j-scaleout-akka

public static <T> void throwExceptionIfExists(Future<T> f,ExecutionContext context) {
  f.onComplete(new OnComplete<T>() {
    @Override
    public void onComplete(Throwable arg0, T arg1) throws Throwable {
      if(arg0 != null)
        throw arg0;
    }
    
  }, context);
}

代码示例来源:origin: opendaylight/controller

void getBucketVersions(final Consumer<Map<Address, Long>> callback) {
  Patterns.ask(actorRef, Singletons.GET_BUCKET_VERSIONS, timeout).onComplete(new OnComplete<Object>() {
    @SuppressWarnings("unchecked")
    @Override
    public void onComplete(final Throwable failure, final Object success) {
      if (failure == null) {
        callback.accept((Map<Address, Long>) success);
      }
    }
  }, dispatcher);
}

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

private Future<Object> completeOperation(Future<Object> operationFuture){
  operationFuture.onComplete(limiter, actorContext.getClientDispatcher());
  return operationFuture;
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

public static <T> Future<T> scalaToVertx(scala.concurrent.Future<T> future, ExecutionContext ec) {
 Future<T> fut = Future.future();
 future.onComplete(new AbstractFunction1<Try<T>, Void>() {
  @Override
  public Void apply(Try<T> v1) {
   if (v1.isSuccess()) {
    fut.complete(v1.get());
   } else {
    fut.fail(v1.failed().get());
   }
   return null;
  }
 }, ec);
 return fut;
}

代码示例来源:origin: com.outbrain.swinfra/ob1k-db

@Override
 public void produce(final Consumer<T> consumer) {
  final Future<T> future = source.provide();
  future.onComplete(new AbstractFunction1<Try<T>, Void>() {
   @Override public Void apply(final Try<T> res) {
    if (res.isSuccess()) {
     consumer.consume(com.outbrain.ob1k.concurrent.Try.fromValue(res.get()));
    } else {
     consumer.consume(com.outbrain.ob1k.concurrent.Try.<T>fromError(res.failed().get()));
    }
    return null;
   }
  }, ctx);
 }
});

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

@Override
public SQLConnection execute(String sql, Handler<AsyncResult<Void>> handler) {
 beginTransactionIfNeeded(v -> {
  final scala.concurrent.Future<QueryResult> future = connection.sendQuery(sql);
  future.onComplete(ScalaUtils.toFunction1(ar -> {
   if (ar.succeeded()) {
    handler.handle(Future.succeededFuture());
   } else {
    handler.handle(Future.failedFuture(ar.cause()));
   }
  }), executionContext);
 });
 return this;
}

代码示例来源:origin: opendaylight/controller

<T extends BucketData<T>> void getBucketsByMembers(final Collection<Address> members,
    final Consumer<Map<Address, Bucket<T>>> callback) {
  Patterns.ask(actorRef, getBucketsByMembersMessage(members), timeout)
    .onComplete(new OnComplete<Object>() {
      @SuppressWarnings("unchecked")
      @Override
      public void onComplete(final Throwable failure, final Object success) {
        if (failure == null) {
          callback.accept((Map<Address, Bucket<T>>) success);
        }
      }
    }, dispatcher);
}

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

private void executeEntityOwnershipShardOperation(final ActorRef shardActor, final Object message) {
  Future<Object> future = context.executeOperationAsync(shardActor, message, MESSAGE_TIMEOUT);
  future.onComplete(new OnComplete<Object>() {
    @Override
    public void onComplete(final Throwable failure, final Object response) {
      if(failure != null) {
        LOG.debug("Error sending message {} to {}", message, shardActor, failure);
      } else {
        LOG.debug("{} message to {} succeeded", message, shardActor, failure);
      }
    }
  }, context.getClientDispatcher());
}

代码示例来源:origin: opendaylight/controller

protected void completeWith(final Future<Object> future) {
  future.onComplete(new FutureUpdater(), ExecutionContext.Implicits$.MODULE$.global());
}

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

protected void completeWith(final Future<Object> future) {
  future.onComplete(new FutureUpdater(), ExecutionContext.Implicits$.MODULE$.global());
}

代码示例来源:origin: org.opendaylight.controller/sal-cluster-admin

private <T> ListenableFuture<T> ask(ActorRef actor, Object message, Timeout timeout) {
  final SettableFuture<T> returnFuture = SettableFuture.create();
  @SuppressWarnings("unchecked")
  scala.concurrent.Future<T> askFuture = (scala.concurrent.Future<T>) Patterns.ask(actor, message, timeout);
  askFuture.onComplete(new OnComplete<T>() {
    @Override
    public void onComplete(Throwable failure, T resp) {
      if(failure != null) {
        returnFuture.setException(failure);
      } else {
        returnFuture.set(resp);
      }
    }
  }, configDataStore.getActorContext().getClientDispatcher());
  return returnFuture;
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

private synchronized void createAndConnect(Handler<AsyncResult<Connection>> handler) {
 try {
  create()
   .connect()
   .onComplete(ScalaUtils.toFunction1(handler), VertxEventLoopExecutionContext.create(vertx));
 } catch (Throwable e) {
  logger.info("creating a connection went wrong", e);
  handler.handle(Future.failedFuture(e));
 }
}

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

private void tryFindPrimaryShard() {
  LOG.debug("Tx {} Retrying findPrimaryShardAsync for shard {}", getIdentifier(), shardName);
  this.primaryShardInfo = null;
  Future<PrimaryShardInfo> findPrimaryFuture = getActorContext().findPrimaryShardAsync(shardName);
  findPrimaryFuture.onComplete(new OnComplete<PrimaryShardInfo>() {
    @Override
    public void onComplete(final Throwable failure, final PrimaryShardInfo primaryShardInfo) {
      onFindPrimaryShardComplete(failure, primaryShardInfo);
    }
  }, getActorContext().getClientDispatcher());
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

@Override
public SQLConnection update(String sql, Handler<AsyncResult<UpdateResult>> handler) {
 beginTransactionIfNeeded(v -> {
  final scala.concurrent.Future<QueryResult> future = connection.sendQuery(sql);
  future.onComplete(ScalaUtils.toFunction1(handleAsyncUpdateResultToResultSet(handler)), executionContext);
 });
 return this;
}

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

private void sendCanCommitTransaction(CohortInfo toCohortInfo, OnComplete<Object> onComplete) {
  CanCommitTransaction message = new CanCommitTransaction(transactionId, toCohortInfo.getActorVersion());
  if(LOG.isDebugEnabled()) {
    LOG.debug("Tx {}: sending {} to {}", transactionId, message, toCohortInfo.getResolvedActor());
  }
  Future<Object> future = actorContext.executeOperationAsync(toCohortInfo.getResolvedActor(),
      message.toSerializable(), actorContext.getTransactionCommitOperationTimeout());
  future.onComplete(onComplete, actorContext.getClientDispatcher());
}

代码示例来源:origin: org.opendaylight.netconf/netconf-topology

private void registerProvidedSourcesToSchemaRegistry() {
  Future<Set<SourceIdentifier>> sourcesFuture = remoteYangTextSourceProvider.getProvidedSources();
  resolvedSourcesPromise.completeWith(sourcesFuture);
  final RemoteSchemaProvider remoteProvider = new RemoteSchemaProvider(remoteYangTextSourceProvider, actorSystem.dispatcher());
  sourcesFuture.onComplete(new OnComplete<Set<SourceIdentifier>>() {
    @Override
    public void onComplete(Throwable throwable, Set<SourceIdentifier> sourceIdentifiers) throws Throwable {
      for (SourceIdentifier sourceId : sourceIdentifiers) {
        sourceRegistrations.add(schemaRegistry.registerSchemaSource(remoteProvider,
            PotentialSchemaSource.create(sourceId, YangTextSchemaSource.class, PotentialSchemaSource.Costs.REMOTE_IO.getValue())));
      }
    }
  }, actorSystem.dispatcher());
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

@Override
public SQLConnection updateWithParams(String sql, JsonArray params, Handler<AsyncResult<UpdateResult>> handler) {
 beginTransactionIfNeeded(v -> {
  final scala.concurrent.Future<QueryResult> future = connection.sendPreparedStatement(sql,
    ScalaUtils.toScalaList(params.getList()));
  future.onComplete(ScalaUtils.toFunction1(handleAsyncUpdateResultToResultSet(handler)), executionContext);
 });
 return this;
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

@Override
public SQLConnection queryWithParams(String sql, JsonArray params, Handler<AsyncResult<ResultSet>> handler) {
 beginTransactionIfNeeded(v -> {
  final scala.concurrent.Future<QueryResult> future = connection.sendPreparedStatement(sql,
    ScalaUtils.toScalaList(params.getList()));
  future.onComplete(ScalaUtils.toFunction1(handleAsyncQueryResultToResultSet(handler)), executionContext);
 });
 return this;
}

代码示例来源:origin: baekjunlim/AkkaStarting

@Override
public void onReceive(Object message) throws Exception {
  if (message instanceof Integer) {
    Future<Object> future = Patterns.ask(child, message, timeout);
    
    // onSuccess, onComplete, onFailure 등은 blocking 동작이 아니다.
    future.onSuccess(new SaySuccess<Object>(), ec);
    future.onComplete(new SayComplete<Object>(), ec);
    future.onFailure(new SayFailure<Object>(), ec);
  } else if (message instanceof String) {
    log.info("NonblockingActor received a messasge: " + message);
  }
}

相关文章