本文整理汇总了Java中com.amazonaws.retry.RetryUtils类的典型用法代码示例。如果您正苦于以下问题:Java RetryUtils类的具体用法?Java RetryUtils怎么用?Java RetryUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RetryUtils类属于com.amazonaws.retry包,在下文中一共展示了RetryUtils类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: captureExceptionMetrics
import com.amazonaws.retry.RetryUtils; //导入依赖的package包/类
/**
* Capture the metrics for the given throwable.
*/
private <T extends Throwable> T captureExceptionMetrics(T t) {
awsRequestMetrics.incrementCounterWith(Field.Exception)
.addProperty(Field.Exception, t);
if (t instanceof AmazonServiceException) {
AmazonServiceException ase = (AmazonServiceException) t;
if (RetryUtils.isThrottlingException(ase)) {
awsRequestMetrics.incrementCounterWith(Field.ThrottleException)
.addProperty(Field.ThrottleException, ase);
}
}
return t;
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:16,代码来源:AmazonHttpClient.java
示例2: withRetryPolicy
import com.amazonaws.retry.RetryUtils; //导入依赖的package包/类
private static ClientConfiguration withRetryPolicy(ClientConfiguration config, String tableName, String indexName) {
RetryPolicy.RetryCondition retryCondition = new PredefinedRetryPolicies.SDKDefaultRetryCondition() {
@Override
public boolean shouldRetry(AmazonWebServiceRequest originalRequest,
AmazonClientException exception,
int retriesAttempted)
{
if (exception instanceof AmazonServiceException) {
AmazonServiceException ase = (AmazonServiceException)exception;
if (RetryUtils.isThrottlingException(ase)) {
if ( null != indexName ) {
if(LOG.isWarnEnabled())
LOG.warn("throttling on table "+tableName+" index "+indexName);
} else {
if(LOG.isWarnEnabled())
LOG.warn("throttling on table "+tableName+" (main index)");
}
}
}
return super.shouldRetry(originalRequest, exception, retriesAttempted);
}
};
config.withRetryPolicy(new RetryPolicy(
retryCondition,
PredefinedRetryPolicies.DYNAMODB_DEFAULT_BACKOFF_STRATEGY,
PredefinedRetryPolicies.DYNAMODB_DEFAULT_MAX_ERROR_RETRY,
true));
return config;
}
开发者ID:Distelli,项目名称:java-persistence,代码行数:30,代码来源:DdbIndex.java
示例3: provideBackoffStrategy
import com.amazonaws.retry.RetryUtils; //导入依赖的package包/类
@Provides
protected RetryPolicy.BackoffStrategy provideBackoffStrategy() {
// tune these parameters to handle throttling errors
final int maxBackoffInMilliseconds = 50 * 1000; // maximum exponential back-off time before retrying a request
final int throttlingScaleFactor = 800; // base sleep time for throttling exceptions
final int maxRetriesBeforeBackoff = 10; // log2(maxBackoffInMilliseconds/throttlingScaleFactor)
final int baseScaleFactor = 600; // base sleep time for general exceptions
final int throttlingScaleFactorRandomRange = throttlingScaleFactor / 4;
final Random random = new Random();
return (originalRequest, exception, retriesAttempted) -> {
LOG.debug("Caught error from service. Retry attempt: " + retriesAttempted, exception);
if (retriesAttempted < 0) return 0;
if (retriesAttempted > maxRetriesBeforeBackoff) return maxBackoffInMilliseconds;
int scaleFactor;
if (exception instanceof AmazonServiceException
&& RetryUtils.isThrottlingException((AmazonServiceException) exception)) {
scaleFactor = throttlingScaleFactor + random.nextInt(throttlingScaleFactorRandomRange);
} else {
scaleFactor = baseScaleFactor;
}
long delay = (1L << retriesAttempted) * scaleFactor;
delay = Math.min(delay, maxBackoffInMilliseconds);
LOG.info("Client backing off for " + delay + "ms");
return delay;
};
}
开发者ID:awslabs,项目名称:aws-apigateway-importer,代码行数:37,代码来源:ApiImporterDefaultModule.java
示例4: afterError
import com.amazonaws.retry.RetryUtils; //导入依赖的package包/类
@Override
public void afterError(Request<?> request, Response<?> response, Exception e) {
if (isSubsegmentDuplicate(recorder.getCurrentSubsegmentOptional(), request)) {
Optional<Subsegment> currentSubsegmentOptional = recorder.getCurrentSubsegmentOptional();
if (!currentSubsegmentOptional.isPresent()) {
return;
}
Subsegment currentSubsegment = currentSubsegmentOptional.get();
int statusCode = -1;
if (null != response) {
statusCode = response.getHttpResponse().getStatusCode();
} else {
if (e instanceof AmazonServiceException) {
AmazonServiceException ase = (AmazonServiceException) e;
statusCode = ase.getStatusCode();
/*
* The S3 client will throw and re-swallow AmazonServiceExceptions if they have these status codes. Customers will never see the exceptions in their application code but they still
* travel through our TracingHandler#afterError method. We special case these status codes in order to prevent addition of the full exception object to the current subsegment.
* Instead, we'll just add any exception error message to the current subsegment's cause's message.
*/
if ((304 == statusCode || 412 == statusCode) && S3_SERVICE_NAME.equals(ase.getServiceName())) {
populateAndEndSubsegment(currentSubsegment, request, response, ase);
return;
}
if (RetryUtils.isThrottlingException(ase)) {
currentSubsegment.setError(true);
currentSubsegment.setThrottle(true);
}
}
}
if (-1 != statusCode) {
int statusCodePrefix = statusCode / 100;
if (4 == statusCodePrefix) {
currentSubsegment.setError(true);
if (429 == statusCode) {
currentSubsegment.setThrottle(true);
}
}
}
currentSubsegment.addException(e);
if (e instanceof AmazonServiceException) {
populateAndEndSubsegment(currentSubsegment, request, response, (AmazonServiceException) e);
} else {
populateAndEndSubsegment(currentSubsegment, request, response);
}
}
}
开发者ID:aws,项目名称:aws-xray-sdk-java,代码行数:53,代码来源:TracingHandler.java
示例5: shouldRetry
import com.amazonaws.retry.RetryUtils; //导入依赖的package包/类
/**
* Returns true if a failed request should be retried.
*
* @param params Params for the individual request being executed.
* @param exception The client/service exception from the failed request.
* @return True if the failed request should be retried.
*/
private boolean shouldRetry(ExecOneRequestParams params, SdkBaseException exception) {
final int retriesAttempted = params.requestCount - 1;
final HttpRequestBase method = params.apacheRequest;
// Never retry on requests containing non-repeatable entity
if (method instanceof HttpEntityEnclosingRequest) {
HttpEntity entity = ((HttpEntityEnclosingRequest) method).getEntity();
if (entity != null && !entity.isRepeatable()) {
if (log.isDebugEnabled()) {
log.debug("Entity not repeatable");
}
return false;
}
}
// Do not use retry capacity for throttling exceptions
if (!RetryUtils.isThrottlingException(exception)) {
// See if we have enough available retry capacity to be able to execute
// this retry attempt.
if (!retryCapacity.acquire(THROTTLED_RETRY_COST)) {
awsRequestMetrics.incrementCounter(ThrottledRetryCount);
return false;
}
executionContext.markRetryCapacityConsumed();
}
RetryPolicyContext context = RetryPolicyContext.builder()
.request(request)
.originalRequest(requestConfig.getOriginalRequest())
.exception(exception)
.retriesAttempted(retriesAttempted)
.httpStatusCode(params.getStatusCode())
.build();
// Finally, pass all the context information to the RetryCondition and let it
// decide whether it should be retried.
if (!retryPolicy.shouldRetry(context)) {
// If the retry policy fails we immediately return consumed capacity to the pool.
if (executionContext.retryCapacityConsumed()) {
retryCapacity.release(THROTTLED_RETRY_COST);
}
return false;
}
return true;
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:53,代码来源:AmazonHttpClient.java
示例6: shouldRetry
import com.amazonaws.retry.RetryUtils; //导入依赖的package包/类
@Override
public boolean shouldRetry(AmazonWebServiceRequest amazonWebServiceRequest, AmazonClientException e, int i) {
return RetryUtils.isThrottlingException(e);
}
开发者ID:awslabs,项目名称:aws-codebuild-jenkins-plugin,代码行数:5,代码来源:CodeBuildClientRetryCondition.java
示例7: shouldRetry
import com.amazonaws.retry.RetryUtils; //导入依赖的package包/类
@Override
public boolean shouldRetry(AmazonWebServiceRequest originalRequest,
AmazonClientException exception,
int retriesAttempted) {
Utils.log(CustomRetryCondition.class, CustomRetryCondition.class.getSimpleName(),
Level.FINE, () -> String
.format("Encountered exception %s for request %s, retries attempted: %d",
Utils.toString(exception), originalRequest, retriesAttempted));
// Always retry on client exceptions caused by IOException
if (exception.getCause() instanceof IOException) {
return true;
}
// Only retry on a subset of service exceptions
if (exception instanceof AmazonServiceException) {
AmazonServiceException ase = (AmazonServiceException) exception;
/*
* For 500 internal server errors and 503 service unavailable errors, we want to
* retry, but we need to use an exponential back-off strategy so that we don't
* overload a server with a flood of retries.
*/
if (RetryUtils.isRetryableServiceException(new SdkBaseException(ase))) {
return true;
}
/*
* Throttling is reported as a 400 error from newer services. To try and smooth out
* an occasional throttling error, we'll pause and retry, hoping that the pause is
* long enough for the request to get through the next time.
*/
if (RetryUtils.isThrottlingException(new SdkBaseException(ase))) {
return true;
}
/*
* Clock skew exception. If it is then we will get the time offset between the
* device time and the server time to set the clock skew and then retry the request.
*/
if (RetryUtils.isClockSkewError(new SdkBaseException(ase))) {
return true;
}
}
return false;
}
开发者ID:vmware,项目名称:photon-model,代码行数:48,代码来源:AWSUtils.java
注:本文中的com.amazonaws.retry.RetryUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论