当前位置: 首页>>代码示例>>Java>>正文


Java Sleeper.DEFAULT属性代码示例

本文整理汇总了Java中com.google.api.client.util.Sleeper.DEFAULT属性的典型用法代码示例。如果您正苦于以下问题:Java Sleeper.DEFAULT属性的具体用法?Java Sleeper.DEFAULT怎么用?Java Sleeper.DEFAULT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.google.api.client.util.Sleeper的用法示例。


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

示例1: run

@Override
public Optional<URI> run(RunSpec runSpec) {
  Sleeper retrySleeper = Sleeper.DEFAULT;
  BackOff backoff = BACKOFF_FACTORY.backoff();

  while (true) {
    try {
      final Pod pod = client.pods().create(createPod(runSpec));
      final String podName = pod.getMetadata().getName();
      LOG.info("Created pod {}", podName);

      Optional<URI> uri = blockUntilComplete(podName);
      client.pods().withName(podName).delete();
      return uri;
    } catch (KubernetesClientException kce) {
      try {
        long sleep = backoff.nextBackOffMillis();
        if (sleep == BackOff.STOP) {
          // Rethrow last error, to be included as a cause in the catch below.
          LOG.error("Failed to create Kubernetes pod", kce);
          throw new KubernetesClientException("Failed to create Kubernetes pod", kce);
        } else {
          LOG.warn("Kubernetes creation attempt failed, sleeping before retrying", kce);
          retrySleeper.sleep(sleep);
        }
      } catch (IOException | InterruptedException ioe) {
        throw new RuntimeException(
            String.format("Failed to create Kubernetes pod when trying to sleep: %s", ioe.getMessage()), ioe);
      }
    } catch (InterruptedException ie) {
      throw new RuntimeException("Interrupted while blocking", ie);
    }
  }
}
 
开发者ID:spotify,项目名称:hype,代码行数:34,代码来源:KubernetesDockerRunner.java

示例2: RetryHttpRequestInitializer

/**
 * @param additionalIgnoredResponseCodes a list of HTTP status codes that should not be logged.
 * @param responseInterceptor HttpResponseInterceptor to be applied on all requests. May be null.
 */
public RetryHttpRequestInitializer(
    Collection<Integer> additionalIgnoredResponseCodes,
    @Nullable HttpResponseInterceptor responseInterceptor) {
  this(NanoClock.SYSTEM, Sleeper.DEFAULT, additionalIgnoredResponseCodes,
      responseInterceptor);
}
 
开发者ID:apache,项目名称:beam,代码行数:10,代码来源:RetryHttpRequestInitializer.java

示例3: pollJob

@Override
public Job pollJob(JobReference jobRef, int maxAttempts)
    throws InterruptedException {
  BackOff backoff =
      BackOffAdapter.toGcpBackOff(
          FluentBackoff.DEFAULT
              .withMaxRetries(maxAttempts)
              .withInitialBackoff(Duration.millis(10))
              .withMaxBackoff(Duration.standardSeconds(1))
              .backoff());
  Sleeper sleeper = Sleeper.DEFAULT;
  try {
    do {
      Job job = getJob(jobRef);
      if (job != null) {
        JobStatus status = job.getStatus();
        if (status != null && status.getState() != null
            && (status.getState().equals("DONE") || status.getState().equals("FAILED"))) {
          return job;
        }
      }
    } while (BackOffUtils.next(sleeper, backoff));
  } catch (IOException e) {
    return null;
  }
  return null;
}
 
开发者ID:apache,项目名称:beam,代码行数:27,代码来源:FakeJobService.java

示例4: upload

private static void upload(String classpathElement, String target, Path targetPath)
    throws IOException, InterruptedException {
  ArrayList<OpenOption> options = new ArrayList<>();
  options.add(WRITE);
  options.add(CREATE_NEW);
  if ("gs".equals(targetPath.toUri().getScheme())) {
    options.add(withMimeType(BINARY));
  }

  // Upload file, retrying on failure.
  Sleeper retrySleeper = Sleeper.DEFAULT;
  BackOff backoff = BACKOFF_FACTORY.backoff();
  while (true) {
    try {
      LOG.debug("Uploading classpath element {} to {}", classpathElement, target);
      try (WritableByteChannel writer = java.nio.file.Files.newByteChannel(targetPath,
          options.toArray(new OpenOption[options.size()]))) {
        copyContent(classpathElement, writer);
      }
      break;
    } catch (IOException e) {
      if (ERROR_EXTRACTOR.accessDenied(e)) {
        String errorMessage = String.format(
            "Uploaded failed due to permissions error, will NOT retry staging "
            + "of classpath %s. Please verify credentials are valid and that you have "
            + "write access to %s. Stale credentials can be resolved by executing "
            + "'gcloud auth login'.", classpathElement, target);
        LOG.error(errorMessage);
        throw new IOException(errorMessage, e);
      }
      long sleep = backoff.nextBackOffMillis();
      if (sleep == BackOff.STOP) {
        // Rethrow last error, to be included as a cause in the catch below.
        LOG.error("Upload failed, will NOT retry staging of classpath: {}",
            classpathElement, e);
        throw e;
      } else {
        LOG.warn("Upload attempt failed, sleeping before retrying staging of classpath: {}",
            classpathElement, e);
        retrySleeper.sleep(sleep);
      }
    }
  }
}
 
开发者ID:spotify,项目名称:hype,代码行数:44,代码来源:StagingUtil.java

示例5: RetryHttpInitializerWrapper

public RetryHttpInitializerWrapper(Credential wrappedCredential) {
    this(wrappedCredential, Sleeper.DEFAULT, TimeValue.timeValueMillis(ExponentialBackOff.DEFAULT_MAX_ELAPSED_TIME_MILLIS));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:3,代码来源:RetryHttpInitializerWrapper.java

示例6: RetryHttpInitializerWrapper

public RetryHttpInitializerWrapper(Credential wrappedCredential) {
	this(wrappedCredential, Sleeper.DEFAULT);
}
 
开发者ID:SignifAi,项目名称:Spark-PubSub,代码行数:3,代码来源:RetryHttpInitializerWrapper.java

示例7: RetryHttpInitializerWrapper

public RetryHttpInitializerWrapper(Credential wrappedCredential) {
  this(wrappedCredential, Sleeper.DEFAULT);
}
 
开发者ID:google,项目名称:play-work,代码行数:3,代码来源:RetryHttpInitializerWrapper.java

示例8: waitForJobCompletion

/**
 * Polls job until it is completed.
 *
 * @param bigquery the Bigquery instance to poll.
 * @param projectId the project that is polling.
 * @param jobReference the job to poll.
 * @param progressable to get progress of task.
 *
 * @throws IOException on IO Error.
 * @throws InterruptedException on sleep interrupt.
 */
public static void waitForJobCompletion(
    Bigquery bigquery,
    String projectId,
    JobReference jobReference,
    Progressable progressable)
    throws IOException, InterruptedException {

  Sleeper sleeper = Sleeper.DEFAULT;
  BackOff pollBackOff =
      new ExponentialBackOff.Builder()
          .setMaxIntervalMillis(POLL_WAIT_INTERVAL_MAX_MILLIS)
          .setInitialIntervalMillis(POLL_WAIT_INITIAL_MILLIS)
          .setMaxElapsedTimeMillis(POLL_WAIT_MAX_ELAPSED_MILLIS)
          .build();

  // Get starting time.
  long startTime = System.currentTimeMillis();
  long elapsedTime = 0;
  boolean notDone = true;

  // While job is incomplete continue to poll.
  while (notDone) {
    BackOff operationBackOff = new ExponentialBackOff.Builder().build();
    Get get = bigquery.jobs().get(projectId, jobReference.getJobId());
    
    Job pollJob = ResilientOperation.retry(
        ResilientOperation.getGoogleRequestCallable(get),
        operationBackOff,
        RetryDeterminer.RATE_LIMIT_ERRORS,
        IOException.class,
        sleeper);

    elapsedTime = System.currentTimeMillis() - startTime;
    LOG.debug("Job status ({} ms) {}: {}", elapsedTime, jobReference.getJobId(),
        pollJob.getStatus().getState());
    if (pollJob.getStatus().getState().equals("DONE")) {
      notDone = false;
      if (pollJob.getStatus().getErrorResult() != null) {
        throw new IOException(pollJob.getStatus().getErrorResult().getMessage());
      }
    } else {
      long millisToWait = pollBackOff.nextBackOffMillis();
      if (millisToWait == BackOff.STOP) {
        throw new IOException(
            String.format(
                "Job %s failed to complete after %s millis.",
                jobReference.getJobId(),
                elapsedTime));
      }
      // Pause execution for the configured duration before polling job status again.
      Thread.sleep(millisToWait);
      // Call progress to ensure task doesn't time out.
      progressable.progress();
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:67,代码来源:BigQueryUtils.java

示例9: RetryHttpInitializerWrapper

public RetryHttpInitializerWrapper(GoogleCredential wrappedCredential) {
  this(wrappedCredential, Sleeper.DEFAULT);
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-samples-java,代码行数:3,代码来源:NewsInjector.java

示例10: RetryHttpInitializerWrapper

/**
 * A constructor.
 *
 * @param wrappedCredential Credential which will be wrapped and used for providing auth header.
 */
public RetryHttpInitializerWrapper(final Credential wrappedCredential) {
  this(wrappedCredential, Sleeper.DEFAULT);
}
 
开发者ID:mdvorsky,项目名称:DataflowSME,代码行数:8,代码来源:RetryHttpInitializerWrapper.java

示例11: RetryHttpInitializerWrapper

/**
 * A constructor.
 *
 * @param wrappedCredential Credential which will be wrapped and
 * used for providing auth header.
 */
public RetryHttpInitializerWrapper(final Credential wrappedCredential) {
    this(wrappedCredential, Sleeper.DEFAULT);
}
 
开发者ID:davorbonaci,项目名称:beam-portability-demo,代码行数:9,代码来源:RetryHttpInitializerWrapper.java

示例12: RetryHttpInitializerWrapper

/**
 * Initialize variables for retry.
 *
 * @param wrappedCredential Google Credentials for retry.
 */
public RetryHttpInitializerWrapper(final Credential wrappedCredential) {
  this.wrappedCredential = wrappedCredential;
  this.sleeper = Sleeper.DEFAULT;
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-mqtt-proxy,代码行数:9,代码来源:RetryHttpInitializerWrapper.java

示例13: RetryHttpInitializerWrapper

/**
 * A constructor using the default Sleeper.
 *
 * @param wrappedCredential
 *          the credential used to authenticate with a Google Cloud Platform project
 */
public RetryHttpInitializerWrapper(Credential wrappedCredential) {
  this(wrappedCredential, Sleeper.DEFAULT);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:9,代码来源:RetryHttpInitializerWrapper.java

示例14: ReportDownloader

/**
 * Constructs a {@code ReportDownloader} object for a
 * {@link ReportServiceInterface} and a report job id that the the class works
 * on.
 *
 * @param reportService the ReportService stub to make calls to
 * @param reportJobId the report job ID
 */
public ReportDownloader(ReportServiceInterface reportService, long reportJobId) {
  this(reportService, reportJobId, Sleeper.DEFAULT);
}
 
开发者ID:googleads,项目名称:googleads-java-lib,代码行数:11,代码来源:ReportDownloader.java


注:本文中的com.google.api.client.util.Sleeper.DEFAULT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。