本文整理汇总了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();
}
示例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();
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
}
}
}
示例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);
}
};
}