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


Java ExponentialBackOff类代码示例

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


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

示例1: YouTubeSingleton

import com.google.api.client.util.ExponentialBackOff; //导入依赖的package包/类
private YouTubeSingleton() {

        credential = GoogleAccountCredential.usingOAuth2(
                YTApplication.getAppContext(), Arrays.asList(SCOPES))
                .setBackOff(new ExponentialBackOff());

        youTube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer() {
            @Override
            public void initialize(HttpRequest httpRequest) throws IOException {

            }
        }).setApplicationName(YTApplication.getAppContext().getString(R.string.app_name))
                .build();

        youTubeWithCredentials = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
                .setApplicationName(YTApplication.getAppContext().getString(R.string.app_name))
                .build();
    }
 
开发者ID:pawelpaszki,项目名称:youtube_background_android,代码行数:19,代码来源:YouTubeSingleton.java

示例2: YouTubeSingleton

import com.google.api.client.util.ExponentialBackOff; //导入依赖的package包/类
private YouTubeSingleton(Context context)
{
    String appName = context.getString(R.string.app_name);
    credential = GoogleAccountCredential
            .usingOAuth2(context, Arrays.asList(SCOPES))
            .setBackOff(new ExponentialBackOff());

    youTube = new YouTube.Builder(
            new NetHttpTransport(),
            new JacksonFactory(),
            new HttpRequestInitializer()
            {
                @Override
                public void initialize(HttpRequest httpRequest) throws IOException {}
            }
    ).setApplicationName(appName).build();

    youTubeWithCredentials = new YouTube.Builder(
            new NetHttpTransport(),
            new JacksonFactory(),
            credential
    ).setApplicationName(appName).build();
}
 
开发者ID:teocci,项目名称:YouTube-In-Background,代码行数:24,代码来源:YouTubeSingleton.java

示例3: subscribe

import com.google.api.client.util.ExponentialBackOff; //导入依赖的package包/类
private synchronized void subscribe(ExponentialBackOff backOff) throws IOException {
    if (state == State.SUBSCRIBED || state == State.DISCONNECTED) {
        cancelSubscriber();
        return;
    }
    LOGGER.info("Sending SUBSCRIBE call");

    final Protos.Call.Builder callBuilder = Protos.Call.newBuilder()
            .setType(Protos.Call.Type.SUBSCRIBE)
            .setSubscribe(Protos.Call.Subscribe.newBuilder()
                    .setFrameworkInfo(frameworkInfo)
                    .build());
    if (frameworkInfo.hasId()) {
        callBuilder.setFrameworkId(frameworkInfo.getId());
    }

    mesos.send(callBuilder.build());

    scheduleNextSubscription(backOff);
}
 
开发者ID:mesosphere,项目名称:mesos-http-adapter,代码行数:21,代码来源:MesosToSchedulerDriverAdapter.java

示例4: performReliableSubscription

import com.google.api.client.util.ExponentialBackOff; //导入依赖的package包/类
/**
 * Task that performs Subscription.
 */
private synchronized void performReliableSubscription() {
    // If timer is not running, initialize it.
    if (subscriberTimer == null) {
        LOGGER.info("Initializing reliable subscriber");
        subscriberTimer = createTimerInternal();
        ExponentialBackOff backOff = new ExponentialBackOff.Builder()
                .setMaxElapsedTimeMillis(Integer.MAX_VALUE /* Try forever */)
                .setMaxIntervalMillis(MAX_BACKOFF_MS)
                .setMultiplier(MULTIPLIER)
                .setRandomizationFactor(0.5)
                .setInitialIntervalMillis(SEED_BACKOFF_MS)
                .build();
        subscriberTimer.schedule(new SubscriberTask(backOff), SEED_BACKOFF_MS, TimeUnit.MILLISECONDS);
    }
}
 
开发者ID:mesosphere,项目名称:mesos-http-adapter,代码行数:19,代码来源:MesosToSchedulerDriverAdapter.java

示例5: init

import com.google.api.client.util.ExponentialBackOff; //导入依赖的package包/类
private void init() {
    // Initializing Internet Checker
    internetDetector = new InternetDetector(getApplicationContext());

    // Initialize credentials and service object.
    mCredential = GoogleAccountCredential.usingOAuth2(
            getApplicationContext(), Arrays.asList(SCOPES))
            .setBackOff(new ExponentialBackOff());

    // Initializing Progress Dialog
    mProgress = new ProgressDialog(this);
    mProgress.setMessage("Sending...");

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    sendFabButton = (FloatingActionButton) findViewById(R.id.fab);
    edtToAddress = (EditText) findViewById(R.id.to_address);
    edtSubject = (EditText) findViewById(R.id.subject);
    edtMessage = (EditText) findViewById(R.id.body);
    edtAttachmentData = (EditText) findViewById(R.id.attachmentData);

}
 
开发者ID:androidmads,项目名称:JavaMailwithGmailApi,代码行数:23,代码来源:MainActivity.java

示例6: initialize

import com.google.api.client.util.ExponentialBackOff; //导入依赖的package包/类
@Override
public void initialize(HttpRequest request) throws IOException {
  // Set a timeout for hanging-gets.
  // TODO: Do this exclusively for work requests.
  request.setReadTimeout(HANGING_GET_TIMEOUT_SEC * 1000);

  LoggingHttpBackOffHandler loggingHttpBackOffHandler = new LoggingHttpBackOffHandler(
      sleeper,
      // Back off on retryable http errors and IOExceptions.
      // A back-off multiplier of 2 raises the maximum request retrying time
      // to approximately 5 minutes (keeping other back-off parameters to
      // their default values).
      new ExponentialBackOff.Builder().setNanoClock(nanoClock).setMultiplier(2).build(),
      new ExponentialBackOff.Builder().setNanoClock(nanoClock).setMultiplier(2).build(),
      ignoredResponseCodes
  );

  request.setUnsuccessfulResponseHandler(loggingHttpBackOffHandler);
  request.setIOExceptionHandler(loggingHttpBackOffHandler);

  // Set response initializer
  if (responseInterceptor != null) {
    request.setResponseInterceptor(responseInterceptor);
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:26,代码来源:RetryHttpRequestInitializer.java

示例7: ResumingStreamingResultScanner

import com.google.api.client.util.ExponentialBackOff; //导入依赖的package包/类
public ResumingStreamingResultScanner(
    RetryOptions retryOptions,
    ReadRowsRequest originalRequest,
    BigtableResultScannerFactory scannerFactory) {
  Preconditions.checkArgument(
      !originalRequest.getAllowRowInterleaving(),
      "Row interleaving is not supported when using resumable streams");
  retryOnDeadlineExceeded = retryOptions.retryOnDeadlineExceeded();
  this.backOffBuilder = new ExponentialBackOff.Builder()
      .setInitialIntervalMillis(retryOptions.getInitialBackoffMillis())
      .setMaxElapsedTimeMillis(retryOptions.getMaxElaspedBackoffMillis())
      .setMultiplier(retryOptions.getBackoffMultiplier());
  this.originalRequest = originalRequest;
  this.scannerFactory = scannerFactory;
  this.currentBackoff = backOffBuilder.build();
  this.currentDelegate = scannerFactory.createScanner(originalRequest);
}
 
开发者ID:dmmcerlean,项目名称:cloud-bigtable-client,代码行数:18,代码来源:ResumingStreamingResultScanner.java

示例8: newCall

import com.google.api.client.util.ExponentialBackOff; //导入依赖的package包/类
@Override
public <ReqT, RespT> Call<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> methodDescriptor) {
  if (methodCanBeRetried(methodDescriptor)) {
    ExponentialBackOff.Builder backOffBuilder = new ExponentialBackOff.Builder();
    backOffBuilder.setInitialIntervalMillis(initialBackoffMillis);
    backOffBuilder.setMultiplier(backoffMultiplier);
    backOffBuilder.setMaxElapsedTimeMillis(maxElapsedBackoffMillis);
    Predicate<ReqT> isPayloadRetriablePredicate = getUncheckedPredicate(methodDescriptor);
    return new RetryingCall<>(
        delegate,
        methodDescriptor,
        isPayloadRetriablePredicate,
        executorService,
        backOffBuilder.build());
  }
  return delegate.newCall(methodDescriptor);
}
 
开发者ID:dmmcerlean,项目名称:cloud-bigtable-client,代码行数:18,代码来源:UnaryCallRetryInterceptor.java

示例9: onCreate

import com.google.api.client.util.ExponentialBackOff; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ensureFetcher();

    credential = GoogleAccountCredential.usingOAuth2(
            getApplicationContext(), Arrays.asList(Utils.SCOPES));
    // set exponential backoff policy
    credential.setBackOff(new ExponentialBackOff());

    if (savedInstanceState != null) {
        mChosenAccountName = savedInstanceState.getString(ACCOUNT_KEY);
    } else {
        loadAccount();
    }

    credential.setSelectedAccountName(mChosenAccountName);

    mEventsListFragment = (EventsListFragment) getFragmentManager()
            .findFragmentById(R.id.list_fragment);
}
 
开发者ID:holtaf,项目名称:youtube_livestream,代码行数:25,代码来源:MainActivity.java

示例10: configure

import com.google.api.client.util.ExponentialBackOff; //导入依赖的package包/类
@Override
protected void configure() {
  requireBinding(CommandLineArguments.class);

  bind(GmailService.class).in(Singleton.class);
  bind(Credential.class)
      .toProvider(Authorizer.class)
      .in(Singleton.class);

  bind(ExponentialBackOff.Builder.class)
      .toInstance(new ExponentialBackOff.Builder()
          .setInitialIntervalMillis(1000)
          .setMultiplier(2)
          .setRandomizationFactor(0.5)
          .setMaxIntervalMillis(60000)
          .setMaxElapsedTimeMillis(300000));
}
 
开发者ID:google,项目名称:mail-importer,代码行数:18,代码来源:GmailServiceModule.java

示例11: execute

import com.google.api.client.util.ExponentialBackOff; //导入依赖的package包/类
private <U, T extends ResponseEnvelope<U>> U execute(final HttpRequest httpRequest, final Class<T> responseType) throws IOException {
   httpRequest.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()));
   if (authToken != null) {
      HttpHeaders headers = httpRequest.getHeaders();
      headers.set("X-Auth-Token", authToken);
   }

   HttpResponse httpResponse = httpRequest.execute();
   T response = httpResponse.parseAs(responseType);

   // Update authToken, if necessary
   if (response.getAuthToken() != null) {
      authToken = response.getAuthToken();
   }

   return response.getData();
}
 
开发者ID:scratch-wireless,项目名称:kazoo-client,代码行数:18,代码来源:KazooConnection.java

示例12: CredentialOrBackoffResponseHandler

import com.google.api.client.util.ExponentialBackOff; //导入依赖的package包/类
public CredentialOrBackoffResponseHandler() {
  HttpBackOffUnsuccessfulResponseHandler errorCodeHandler =
      new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff());
  errorCodeHandler.setBackOffRequired(
      new HttpBackOffUnsuccessfulResponseHandler.BackOffRequired() {
        @Override
        public boolean isRequired(HttpResponse response) {
          return BASE_HTTP_BACKOFF_REQUIRED.isRequired(response)
              || response.getStatusCode() == STATUS_CODE_TOO_MANY_REQUESTS;
        }
      });
  if (sleeperOverride != null) {
    errorCodeHandler.setSleeper(sleeperOverride);
  }
  this.delegateHandler = errorCodeHandler;
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:17,代码来源:RetryHttpInitializer.java

示例13: resetOrCreateBackOff

import com.google.api.client.util.ExponentialBackOff; //导入依赖的package包/类
/**
 * Helper for reseting the BackOff used for retries. If no backoff is given, a generic
 * one is initialized.
 */
private BackOff resetOrCreateBackOff() throws IOException{
  if (backOff != null){
    backOff.reset();
  } else {
    backOff = new ExponentialBackOff.Builder()
        .setInitialIntervalMillis(readOptions.getBackoffInitialIntervalMillis())
        .setRandomizationFactor(readOptions.getBackoffRandomizationFactor())
        .setMultiplier(readOptions.getBackoffMultiplier())
        .setMaxIntervalMillis(readOptions.getBackoffMaxIntervalMillis())
        .setMaxElapsedTimeMillis(readOptions.getBackoffMaxElapsedTimeMillis())
        .setNanoClock(clock)
        .build();
  }
  return backOff;
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:20,代码来源:GoogleCloudStorageReadChannel.java

示例14: processElement

import com.google.api.client.util.ExponentialBackOff; //导入依赖的package包/类
@ProcessElement
public void processElement(DoFn<String, Integer>.ProcessContext context) throws Exception {
  String variantId = context.element();
  // Call the deletion operation via exponential backoff so that "Rate Limit Exceeded"
  // quota issues do not cause the pipeline to fail.
  ExponentialBackOff backoff = new ExponentialBackOff.Builder().build();
  while (true) {
    try {
      genomics.variants().delete(variantId).execute();
      Metrics.counter(DeleteVariantFn.class, "Number of variants deleted").inc();
      context.output(1);
      return;
    } catch (Exception e) {
      if (e.getMessage().startsWith("429 Too Many Requests")) {
        LOG.warn("Backing-off per: ", e);
        long backOffMillis = backoff.nextBackOffMillis();
        if (backOffMillis == BackOff.STOP) {
          throw e;
        }
        Thread.sleep(backOffMillis);
      } else {
        throw e;
      }
    }
  }
}
 
开发者ID:googlegenomics,项目名称:dataflow-java,代码行数:27,代码来源:DeleteVariants.java

示例15: setHttpBackoffTimeout

import com.google.api.client.util.ExponentialBackOff; //导入依赖的package包/类
private static HttpRequestInitializer setHttpBackoffTimeout(final HttpRequestInitializer requestInitializer,
                                                            final int connectTimeoutMs, final int readTimeoutMs) {
    return new HttpRequestInitializer() {
        @Override
        public void initialize(HttpRequest httpRequest) throws IOException {
            requestInitializer.initialize(httpRequest);

            // Configure exponential backoff on error
            // https://developers.google.com/api-client-library/java/google-http-java-client/backoff
            ExponentialBackOff backoff = new ExponentialBackOff();
            HttpUnsuccessfulResponseHandler backoffHandler = new HttpBackOffUnsuccessfulResponseHandler(backoff)
                    .setBackOffRequired(HttpBackOffUnsuccessfulResponseHandler.BackOffRequired.ALWAYS);
            httpRequest.setUnsuccessfulResponseHandler(backoffHandler);

            httpRequest.setConnectTimeout(connectTimeoutMs);
            httpRequest.setReadTimeout(readTimeoutMs);
        }
    };
}
 
开发者ID:pinterest,项目名称:secor,代码行数:20,代码来源:GsUploadManager.java


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