本文整理汇总了Java中com.google.api.client.http.HttpBackOffIOExceptionHandler类的典型用法代码示例。如果您正苦于以下问题:Java HttpBackOffIOExceptionHandler类的具体用法?Java HttpBackOffIOExceptionHandler怎么用?Java HttpBackOffIOExceptionHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpBackOffIOExceptionHandler类属于com.google.api.client.http包,在下文中一共展示了HttpBackOffIOExceptionHandler类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DefaultHttpRequestInitializer
import com.google.api.client.http.HttpBackOffIOExceptionHandler; //导入依赖的package包/类
DefaultHttpRequestInitializer(GoogleCredential credential, TimeValue connectTimeout, TimeValue readTimeout) {
this.credential = credential;
this.connectTimeout = connectTimeout;
this.readTimeout = readTimeout;
this.handler = new HttpBackOffUnsuccessfulResponseHandler(newBackOff());
this.ioHandler = new HttpBackOffIOExceptionHandler(newBackOff());
}
示例2: createRequestFactory
import com.google.api.client.http.HttpBackOffIOExceptionHandler; //导入依赖的package包/类
private HttpRequestFactory createRequestFactory() {
return new NetHttpTransport().createRequestFactory(request -> {
request.setConnectTimeout(HttpClient.this.config.getConnectTimeout());
request.setReadTimeout(HttpClient.this.config.getReadTimeout());
request.setNumberOfRetries(HttpClient.this.config.getRetries());
request.setIOExceptionHandler(new HttpBackOffIOExceptionHandler(new ExponentialBackOff.Builder().build()));
});
}
示例3: initialize
import com.google.api.client.http.HttpBackOffIOExceptionHandler; //导入依赖的package包/类
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
httpRequest.setIOExceptionHandler(
new HttpBackOffIOExceptionHandler(new ExponentialBackOff()));
httpRequest.setUnsuccessfulResponseHandler(
new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()));
}
示例4: initialize
import com.google.api.client.http.HttpBackOffIOExceptionHandler; //导入依赖的package包/类
@Override
public void initialize(HttpRequest request) {
// Credential must be the interceptor to fill in accessToken fields.
request.setInterceptor(credential);
// IOExceptions such as "socket timed out" of "insufficient bytes written" will follow a
// straightforward backoff.
HttpBackOffIOExceptionHandler exceptionHandler =
new HttpBackOffIOExceptionHandler(new ExponentialBackOff());
if (sleeperOverride != null) {
exceptionHandler.setSleeper(sleeperOverride);
}
// Supply a new composite handler for unsuccessful return codes. 401 Unauthorized will be
// handled by the Credential, 410 Gone will be logged, and 5XX will be handled by a backoff
// handler.
LoggingResponseHandler loggingResponseHandler = new LoggingResponseHandler(
new CredentialOrBackoffResponseHandler(), exceptionHandler,
ImmutableSet.of(HttpStatus.SC_GONE, HttpStatus.SC_SERVICE_UNAVAILABLE));
request.setUnsuccessfulResponseHandler(loggingResponseHandler);
request.setIOExceptionHandler(loggingResponseHandler);
if (Strings.isNullOrEmpty(request.getHeaders().getUserAgent())) {
LOG.debug("Request is missing a user-agent, adding default value of '{}'", defaultUserAgent);
request.getHeaders().setUserAgent(defaultUserAgent);
}
}
示例5: initialize
import com.google.api.client.http.HttpBackOffIOExceptionHandler; //导入依赖的package包/类
@Override
public void initialize(HttpRequest httpRequest) {
final HttpUnsuccessfulResponseHandler backoffHandler =
new HttpBackOffUnsuccessfulResponseHandler(
new ExponentialBackOff.Builder()
.setMaxElapsedTimeMillis(((int) maxWait.getMillis()))
.build())
.setSleeper(sleeper);
httpRequest.setInterceptor(wrappedCredential);
httpRequest.setUnsuccessfulResponseHandler(
new HttpUnsuccessfulResponseHandler() {
int retry = 0;
@Override
public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) throws IOException {
if (wrappedCredential.handleResponse(
request, response, supportsRetry)) {
// If credential decides it can handle it,
// the return code or message indicated
// something specific to authentication,
// and no backoff is desired.
return true;
} else if (backoffHandler.handleResponse(
request, response, supportsRetry)) {
// Otherwise, we defer to the judgement of
// our internal backoff handler.
logger.debug("Retrying [{}] times : [{}]", retry, request.getUrl());
return true;
} else {
return false;
}
}
});
httpRequest.setIOExceptionHandler(
new HttpBackOffIOExceptionHandler(
new ExponentialBackOff.Builder()
.setMaxElapsedTimeMillis(((int) maxWait.getMillis()))
.build())
.setSleeper(sleeper)
);
}
示例6: getHttpBackOffIOExceptionHandler
import com.google.api.client.http.HttpBackOffIOExceptionHandler; //导入依赖的package包/类
private HttpBackOffIOExceptionHandler getHttpBackOffIOExceptionHandler() {
MockBackOff backOff = new MockBackOff();
backOff.setBackOffMillis(200);
backOff.setMaxTries(5);
return new HttpBackOffIOExceptionHandler(backOff);
}
示例7: main
import com.google.api.client.http.HttpBackOffIOExceptionHandler; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
if (args.length != 3) {
System.out.println("UploadDirs accountname folderid folder");
return;
}
String folderid = args[1];
String account = args[0];
String folder = args[2];
java.io.File jdrivedir = new java.io.File(
new java.io.File(new java.io.File(
System.getProperty("user.home")), ".gyingpan"), account);
jdrivedir.mkdirs();
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport, jsonFactory, GDrive.CLIENT_ID,
GDrive.CLIENT_SECRET, Arrays.asList(DriveScopes.DRIVE))
.setAccessType("offline")
.setApprovalPrompt("auto")
.setDataStoreFactory(
new FileDataStoreFactory(new java.io.File(jdrivedir,
"driveauth"))).build();
Credential credential = flow.loadCredential(args[0]);
Drive service = new Drive.Builder(httpTransport, jsonFactory,
credential).setHttpRequestInitializer(
new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request)
throws IOException {
credential.initialize(request);
request.setIOExceptionHandler(new HttpBackOffIOExceptionHandler(
new ExponentialBackOff()));
request.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(
new ExponentialBackOff()));
}
}).build();
HashMap<String, File> gfilelist = getGDriveFileList(service, folderid);
uploadDir(service, gfilelist, folderid,
new java.io.File(folder).toPath());
}