scala.concurrent.Await.result()方法的使用及代码示例

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

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

Await.result介绍

暂无

代码示例

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

@Override
public GetClusterStatusResponse getClusterStatus() {
  ActorGateway jmGateway;
  try {
    jmGateway = getJobManagerGateway();
    Future<Object> future = jmGateway.ask(GetClusterStatus.getInstance(), timeout);
    Object result = Await.result(future, timeout);
    if (result instanceof GetClusterStatusResponse) {
      return (GetClusterStatusResponse) result;
    } else {
      throw new RuntimeException("Received the wrong reply " + result + " from cluster.");
    }
  } catch (Exception e) {
    throw new RuntimeException("Couldn't retrieve the cluster status.", e);
  }
}

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

/**
 * This method is only available if the cluster hasn't been started in detached mode.
 */
@Override
public GetClusterStatusResponse getClusterStatus() {
  try {
    final Future<Object> clusterStatusOption =
      getJobManagerGateway().ask(
        GetClusterStatus.getInstance(),
        akkaDuration);
    return (GetClusterStatusResponse) Await.result(clusterStatusOption, akkaDuration);
  } catch (Exception e) {
    throw new RuntimeException("Unable to get ClusterClient status from Application Client", e);
  }
}

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

/**
 * Cancels a job identified by the job id.
 * @param jobId the job id
 * @throws Exception In case an error occurred.
 */
public void cancel(JobID jobId) throws Exception {
  final ActorGateway jobManager = getJobManagerGateway();
  Object cancelMsg = new JobManagerMessages.CancelJob(jobId);
  Future<Object> response = jobManager.ask(cancelMsg, timeout);
  final Object rc = Await.result(response, timeout);
  if (rc instanceof JobManagerMessages.CancellationSuccess) {
    // no further action required
  } else if (rc instanceof JobManagerMessages.CancellationFailure) {
    throw new Exception("Canceling the job with ID " + jobId + " failed.",
      ((JobManagerMessages.CancellationFailure) rc).cause());
  } else {
    throw new IllegalStateException("Unexpected response: " + rc);
  }
}

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

/**
 * Cancels a job identified by the job id and triggers a savepoint.
 * @param jobId the job id
 * @param savepointDirectory directory the savepoint should be written to
 * @return path where the savepoint is located
 * @throws Exception In case an error occurred.
 */
public String cancelWithSavepoint(JobID jobId, @Nullable String savepointDirectory) throws Exception {
  final ActorGateway jobManager = getJobManagerGateway();
  Object cancelMsg = new JobManagerMessages.CancelJobWithSavepoint(jobId, savepointDirectory);
  Future<Object> response = jobManager.ask(cancelMsg, timeout);
  final Object rc = Await.result(response, timeout);
  if (rc instanceof JobManagerMessages.CancellationSuccess) {
    JobManagerMessages.CancellationSuccess success = (JobManagerMessages.CancellationSuccess) rc;
    return success.savepointPath();
  } else if (rc instanceof JobManagerMessages.CancellationFailure) {
    throw new Exception("Cancel & savepoint for the job with ID " + jobId + " failed.",
      ((JobManagerMessages.CancellationFailure) rc).cause());
  } else {
    throw new IllegalStateException("Unexpected response: " + rc);
  }
}

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

/**
 * Stops a program on Flink cluster whose job-manager is configured in this client's configuration.
 * Stopping works only for streaming programs. Be aware, that the program might continue to run for
 * a while after sending the stop command, because after sources stopped to emit data all operators
 * need to finish processing.
 *
 * @param jobId
 *            the job ID of the streaming program to stop
 * @throws Exception
 *             If the job ID is invalid (ie, is unknown or refers to a batch job) or if sending the stop signal
 *             failed. That might be due to an I/O problem, ie, the job-manager is unreachable.
 */
public void stop(final JobID jobId) throws Exception {
  final ActorGateway jobManager = getJobManagerGateway();
  Future<Object> response = jobManager.ask(new JobManagerMessages.StopJob(jobId), timeout);
  final Object rc = Await.result(response, timeout);
  if (rc instanceof JobManagerMessages.StoppingSuccess) {
    // no further action required
  } else if (rc instanceof JobManagerMessages.StoppingFailure) {
    throw new Exception("Stopping the job with ID " + jobId + " failed.",
      ((JobManagerMessages.StoppingFailure) rc).cause());
  } else {
    throw new IllegalStateException("Unexpected response: " + rc);
  }
}

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

YarnMessages.getLocalGetYarnMessage(),
      new Timeout(akkaDuration));
  result = Await.result(response, akkaDuration);
} catch (Exception ioe) {
  LOG.warn("Error retrieving the YARN messages locally", ioe);

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

/**
 * Requests and returns the accumulators for the given job identifier. Accumulators can be
 * requested while a is running or after it has finished.
 * @param jobID The job identifier of a job.
 * @param loader The class loader for deserializing the accumulator results.
 * @return A Map containing the accumulator's name and its value.
 */
public Map<String, OptionalFailure<Object>> getAccumulators(JobID jobID, ClassLoader loader) throws Exception {
  ActorGateway jobManagerGateway = getJobManagerGateway();
  Future<Object> response;
  try {
    response = jobManagerGateway.ask(new RequestAccumulatorResults(jobID), timeout);
  } catch (Exception e) {
    throw new Exception("Failed to query the job manager gateway for accumulators.", e);
  }
  Object result = Await.result(response, timeout);
  if (result instanceof AccumulatorResultsFound) {
    Map<String, SerializedValue<OptionalFailure<Object>>> serializedAccumulators =
        ((AccumulatorResultsFound) result).result();
    return AccumulatorHelper.deserializeAccumulators(serializedAccumulators, loader);
  } else if (result instanceof AccumulatorResultsErroneous) {
    throw ((AccumulatorResultsErroneous) result).cause();
  } else {
    throw new Exception("Failed to fetch accumulators for the job " + jobID + ".");
  }
}

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

private Status sendMessageToLocalRouters( QakkaMessage message ) {
  int maxRetries = 5;
  int retries = 0;
  while ( retries++ < maxRetries ) {
    try {
      Timeout t = new Timeout( 1, TimeUnit.SECONDS );
      // ask ClientActor and wait (up to timeout) for response
      Future<Object> fut = Patterns.ask( actorSystemManager.getClientActor(), message, t );
      final QakkaMessage response = (QakkaMessage)Await.result( fut, t.duration() );
      if ( response != null && response instanceof QueueAckResponse) {
        QueueAckResponse qprm = (QueueAckResponse)response;
        return qprm.getStatus();
      } else if ( response != null  ) {
        logger.debug("UNKNOWN RESPONSE sending message, retrying {}", retries );
      } else {
        logger.trace("TIMEOUT sending message, retrying {}", retries );
      }
    } catch ( TimeoutException e ) {
      logger.trace( "TIMEOUT sending message, retrying " + retries, e );
    } catch ( Exception e ) {
      logger.debug("ERROR sending message, retrying " + retries, e );
    }
  }
  throw new QakkaRuntimeException(
      "Error sending message " + message + "after " + retries );
}

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

Object responseObject = Await.result( fut, t.duration() );
  final QakkaMessage response = (QakkaMessage)Await.result( fut, t.duration() );

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

private void waitForClientActor( ActorRef ra ) {
  logger.info( "Waiting on ClientActor [{}]...", ra.path() );
  started = false;
  int retries = 0;
  int maxRetries = 60;
  while (retries < maxRetries) {
    Timeout t = new Timeout( 10, TimeUnit.SECONDS );
    Future<Object> fut = Patterns.ask( ra, new ClientActor.StatusRequest(), t );
    try {
      ClientActor.StatusMessage result = (ClientActor.StatusMessage) Await.result( fut, t.duration() );
      if (result.getStatus().equals( ClientActor.StatusMessage.Status.READY )) {
        started = true;
        break;
      }
      logger.info( "Waiting for ClientActor [{}] region [{}] for [{}s]", ra.path(), currentRegion, retries );
      Thread.sleep( 1000 );
    } catch (Exception e) {
      logger.error( "Error: Timeout waiting for ClientActor [{}]", ra.path() );
    }
    retries++;
  }
  if (started) {
    logger.info( "ClientActor [{}] has started", ra.path() );
  } else {
    throw new RuntimeException( "ClientActor ["+ra.path()+"] did not start in time, validate that akka seeds are configured properly" );
  }
}

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

final Object response = Await.result( fut, t.duration() );

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

final Object response = Await.result( fut, t.duration() );

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

response = (UniqueValueActor.Response) Await.result( fut, t.duration() );

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

int numberOfRegisteredResources = (Integer) Await.result(numberOfRegisteredResourcesFuture, deadline.timeLeft());

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

timeout);
int numRegisteredTMs = (Integer) Await.result(registeredTMs, timeout);

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

Await.result(jobSubmission.resultPromise.future(), deadline.timeLeft());

代码示例来源:origin: eBay/parallec

commandResponseFromManager = (ResponseFromManager) Await.result(
    future, duration);

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

@Benchmark
public String setValue() throws Exception {
 Promise<String> p = Promise.<String>apply();
 p.success(string);
 return Await.result(p.future(), inf);
}

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

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

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

@Test
public void testGetProvidedSources() throws Exception {
  Set<SourceIdentifier> remoteProvidedSources = Await.result(remoteRepository
      .getProvidedSources(), FiniteDuration.Zero());
  assertEquals(providedSources, remoteProvidedSources);
}

相关文章

微信公众号

最新文章

更多