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


Java RetryPolicy类代码示例

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


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

示例1: interruptCausedBySomethingOtherThanTimer_PropagatesInterruptToCaller

import com.amazonaws.retry.RetryPolicy; //导入依赖的package包/类
/**
 * The client execution timer uses interrupts to abort the client but if another thread
 * interrupts the current thread for another reason we don't want to squash the
 * {@link InterruptedException}. We should set the thread's interrupted status and throw the
 * exception back out (we can't throw the actual {@link InterruptedException} because it's
 * checked)
 */
@Test(timeout = TEST_TIMEOUT)
public void interruptCausedBySomethingOtherThanTimer_PropagatesInterruptToCaller() {
    final int socketTimeoutInMillis = 100;
    httpClient = new AmazonHttpClient(new ClientConfiguration().withSocketTimeout(socketTimeoutInMillis)
            .withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT)
            .withRetryPolicy(new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION,
                    new FixedTimeBackoffStrategy(CLIENT_EXECUTION_TIMEOUT), 1, false)));

    // We make sure the first connection has failed due to the socket timeout before
    // interrupting so we know that we are sleeping per the backoff strategy. Apache HTTP
    // client doesn't seem to honor interrupts reliably but Thread.sleep does
    interruptCurrentThreadAfterDelay(socketTimeoutInMillis * 2);

    try {
        httpClient.requestExecutionBuilder().request(newGetRequest()).execute();
        fail("Exception expected");
    } catch (AmazonClientException e) {
        assertTrue(Thread.currentThread().isInterrupted());
        assertThat(e.getCause(), instanceOf(InterruptedException.class));
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:29,代码来源:UnresponsiveServerIntegrationTests.java

示例2: clientExecutionTimeoutEnabled_WithShorterRequestTimeoutAndRetry_ThrowsClientExecutionTimeoutException

import com.amazonaws.retry.RetryPolicy; //导入依赖的package包/类
@Test(timeout = TEST_TIMEOUT)
public void clientExecutionTimeoutEnabled_WithShorterRequestTimeoutAndRetry_ThrowsClientExecutionTimeoutException()
        throws IOException {
    final int clientExecutionTimeout = 1500;
    final int requestTimeout = 1000;
    final int backoffTime = 300;
    httpClient = new AmazonHttpClient(new ClientConfiguration().withClientExecutionTimeout(clientExecutionTimeout)
            .withRequestTimeout(requestTimeout)
            .withRetryPolicy(new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION,
                    new FixedTimeBackoffStrategy(backoffTime), Integer.MAX_VALUE, false)));

    try {
        httpClient.requestExecutionBuilder().request(newGetRequest()).execute();
        fail("Exception expected");
    } catch (AmazonClientException e) {
        assertThat(e, instanceOf(ClientExecutionTimeoutException.class));
        // Completed tasks means the client execution was aborted by the timer
        assertNumberOfTasksTriggered(httpClient.getClientExecutionTimer(), 1);
        assertNumberOfTasksTriggered(httpClient.getHttpRequestTimer(), 1);
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:22,代码来源:UnresponsiveServerIntegrationTests.java

示例3: shouldRetryCompleteMultipartUpload

import com.amazonaws.retry.RetryPolicy; //导入依赖的package包/类
private boolean shouldRetryCompleteMultipartUpload(AmazonWebServiceRequest originalRequest,
                                                   AmazonS3Exception exception,
                                                   int retriesAttempted) {

    final RetryPolicy retryPolicy = clientConfiguration.getRetryPolicy();

    if (retryPolicy == null || retryPolicy.getRetryCondition() == null) {
        return false;
    }

    if (retryPolicy == PredefinedRetryPolicies.NO_RETRY_POLICY) {
        return false;
    }

    return completeMultipartUploadRetryCondition.shouldRetry
            (originalRequest, exception, retriesAttempted);
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:18,代码来源:AmazonS3Client.java

示例4: getS3Client

import com.amazonaws.retry.RetryPolicy; //导入依赖的package包/类
public static AmazonS3Client getS3Client(AuthCredentialsServiceState credentials,
        String regionId) {

    ClientConfiguration configuration = new ClientConfiguration();
    configuration.withRetryPolicy(new RetryPolicy(new CustomRetryCondition(),
            DEFAULT_BACKOFF_STRATEGY,
            DEFAULT_MAX_ERROR_RETRY,
            false));

    AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider(
            new BasicAWSCredentials(credentials.privateKeyId,
                    EncryptionUtils.decrypt(credentials.privateKey)));

    AmazonS3ClientBuilder amazonS3ClientBuilder = AmazonS3ClientBuilder
            .standard()
            .withClientConfiguration(configuration)
            .withCredentials(awsStaticCredentialsProvider)
            .withRegion(regionId);

    if (isAwsClientMock()) {
        throw new IllegalArgumentException("AWS Mock does not support S3 client");
    }

    return (AmazonS3Client) amazonS3ClientBuilder.build();
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:26,代码来源:AWSUtils.java

示例5: getEC2SynchronousClient

import com.amazonaws.retry.RetryPolicy; //导入依赖的package包/类
public static AmazonEC2 getEC2SynchronousClient(AuthCredentialsServiceState credentials,
        String region) {
    ClientConfiguration configuration = new ClientConfiguration();
    configuration.withRetryPolicy(new RetryPolicy(new CustomRetryCondition(),
            DEFAULT_BACKOFF_STRATEGY,
            DEFAULT_MAX_ERROR_RETRY,
            true));

    AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider(
            new BasicAWSCredentials(credentials.privateKeyId,
                    EncryptionUtils.decrypt(credentials.privateKey)));

    AmazonEC2ClientBuilder ec2ClientBuilder = AmazonEC2ClientBuilder.standard()
            .withCredentials(awsStaticCredentialsProvider)
            .withRegion(region)
            .withClientConfiguration(configuration);

    return ec2ClientBuilder.build();
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:20,代码来源:TestUtils.java

示例6: newInstance

import com.amazonaws.retry.RetryPolicy; //导入依赖的package包/类
public AmazonS3 newInstance(Configuration conf) {
  int maxErrorRetry = conf.getInt(ConfigurationVariable.UPLOAD_RETRY_COUNT.getName(),
      ConfigurationVariable.UPLOAD_RETRY_COUNT.defaultIntValue());
  long errorRetryDelay = conf.getLong(ConfigurationVariable.UPLOAD_RETRY_DELAY_MS.getName(),
      ConfigurationVariable.UPLOAD_RETRY_DELAY_MS.defaultLongValue());

  LOG.info("Creating AWS S3 client with a retry policy of {} retries and {} ms of exponential backoff delay",
      maxErrorRetry, errorRetryDelay);

  RetryPolicy retryPolicy = new RetryPolicy(new CounterBasedRetryCondition(maxErrorRetry),
      new ExponentialBackoffStrategy(errorRetryDelay), maxErrorRetry, true);
  ClientConfiguration clientConfiguration = new ClientConfiguration();
  clientConfiguration.setRetryPolicy(retryPolicy);
  clientConfiguration.setMaxErrorRetry(maxErrorRetry);

  AmazonS3ClientBuilder builder = AmazonS3ClientBuilder
      .standard()
      .withCredentials(new HadoopAWSCredentialProviderChain(conf))
      .withClientConfiguration(clientConfiguration);

  EndpointConfiguration endpointConfiguration = getEndpointConfiguration(conf);
  if (endpointConfiguration != null) {
    builder.withEndpointConfiguration(endpointConfiguration);
  } else {
    builder.withRegion(getRegion(conf));
  }

  return builder.build();
}
 
开发者ID:HotelsDotCom,项目名称:circus-train,代码行数:30,代码来源:AwsS3ClientFactory.java

示例7: S3SQSClient

import com.amazonaws.retry.RetryPolicy; //导入依赖的package包/类
public S3SQSClient(Region region, String queueName, String accessKey, String secretKey) {
    ClientConfiguration clientConfiguration = new ClientConfiguration();

    clientConfiguration.setRequestTimeout(5000);
    clientConfiguration.setRetryPolicy(new RetryPolicy(null, null, 3, true));

    if (accessKey.isEmpty() && secretKey.isEmpty()) {
        this.sqs = new AmazonSQSClient(new InstanceProfileCredentialsProvider(), clientConfiguration);
    } else {
        this.sqs = new AmazonSQSClient(new BasicAWSCredentials(accessKey, secretKey), clientConfiguration);
    }
    this.sqs.setRegion(region);

    this.queueName = queueName;
}
 
开发者ID:sherzberg,项目名称:graylog-plugin-s3,代码行数:16,代码来源:S3SQSClient.java

示例8: getClientConfiguration

import com.amazonaws.retry.RetryPolicy; //导入依赖的package包/类
private ClientConfiguration getClientConfiguration() {
    ClientConfiguration clientConfig = new ClientConfiguration()
            .withUserAgentPrefix("CodeBuild-Jenkins-Plugin") //tags all calls made from Jenkins plugin.
            .withProxyHost(proxyHost)
            .withRetryPolicy(new RetryPolicy(new CodeBuildClientRetryCondition(),
                    new PredefinedBackoffStrategies.ExponentialBackoffStrategy(5000, 20000),
                    10, true));

    if(proxyPort != null) {
        clientConfig.setProxyPort(proxyPort);
    }
    return clientConfig;
}
 
开发者ID:awslabs,项目名称:aws-codebuild-jenkins-plugin,代码行数:14,代码来源:AWSClientFactory.java

示例9: getAsyncClient

import com.amazonaws.retry.RetryPolicy; //导入依赖的package包/类
public static AmazonEC2AsyncClient getAsyncClient(
        AuthCredentialsServiceState credentials, String region,
        ExecutorService executorService) {

    ClientConfiguration configuration = new ClientConfiguration();
    configuration.setMaxConnections(100);
    configuration.withRetryPolicy(new RetryPolicy(new CustomRetryCondition(),
            DEFAULT_BACKOFF_STRATEGY,
            DEFAULT_MAX_ERROR_RETRY,
            false));

    AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider(
            new BasicAWSCredentials(credentials.privateKeyId,
                    EncryptionUtils.decrypt(credentials.privateKey)));

    AmazonEC2AsyncClientBuilder ec2AsyncClientBuilder = AmazonEC2AsyncClientBuilder
            .standard()
            .withClientConfiguration(configuration)
            .withCredentials(awsStaticCredentialsProvider)
            .withExecutorFactory(() -> executorService);

    if (region == null) {
        region = Regions.DEFAULT_REGION.getName();
    }

    if (isAwsClientMock()) {
        configuration.addHeader(AWS_REGION_HEADER, region);
        ec2AsyncClientBuilder.setClientConfiguration(configuration);
        AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(
                getAWSMockHost() + AWS_MOCK_EC2_ENDPOINT, region);
        ec2AsyncClientBuilder.setEndpointConfiguration(endpointConfiguration);
    } else {
        ec2AsyncClientBuilder.setRegion(region);
    }

    return (AmazonEC2AsyncClient) ec2AsyncClientBuilder.build();
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:38,代码来源:AWSUtils.java

示例10: getStatsAsyncClient

import com.amazonaws.retry.RetryPolicy; //导入依赖的package包/类
public static AmazonCloudWatchAsyncClient getStatsAsyncClient(
        AuthCredentialsServiceState credentials, String region,
        ExecutorService executorService, boolean isMockRequest) {

    ClientConfiguration configuration = new ClientConfiguration();
    configuration.withRetryPolicy(new RetryPolicy(new CustomRetryCondition(),
            DEFAULT_BACKOFF_STRATEGY,
            DEFAULT_MAX_ERROR_RETRY,
            false));

    AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider(
            new BasicAWSCredentials(credentials.privateKeyId,
                    EncryptionUtils.decrypt(credentials.privateKey)));

    AmazonCloudWatchAsyncClientBuilder amazonCloudWatchAsyncClientBuilder = AmazonCloudWatchAsyncClientBuilder
            .standard()
            .withClientConfiguration(configuration)
            .withCredentials(awsStaticCredentialsProvider)
            .withExecutorFactory(() -> executorService);

    if (region == null) {
        region = Regions.DEFAULT_REGION.getName();
    }

    if (isAwsClientMock()) {
        configuration.addHeader(AWS_REGION_HEADER, region);
        amazonCloudWatchAsyncClientBuilder.setClientConfiguration(configuration);
        AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(
                getAWSMockHost() + AWS_MOCK_CLOUDWATCH_ENDPOINT, region);
        amazonCloudWatchAsyncClientBuilder.setEndpointConfiguration(endpointConfiguration);
    } else {
        amazonCloudWatchAsyncClientBuilder.setRegion(region);
    }

    return (AmazonCloudWatchAsyncClient) amazonCloudWatchAsyncClientBuilder.build();
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:37,代码来源:AWSUtils.java

示例11: getLoadBalancingAsyncClient

import com.amazonaws.retry.RetryPolicy; //导入依赖的package包/类
public static AmazonElasticLoadBalancingAsyncClient getLoadBalancingAsyncClient(
        AuthCredentialsServiceState credentials, String region,
        ExecutorService executorService) {

    ClientConfiguration configuration = new ClientConfiguration();
    configuration.withRetryPolicy(new RetryPolicy(new CustomRetryCondition(),
            DEFAULT_BACKOFF_STRATEGY,
            DEFAULT_MAX_ERROR_RETRY,
            false));

    AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider(
            new BasicAWSCredentials(credentials.privateKeyId,
                    EncryptionUtils.decrypt(credentials.privateKey)));

    AmazonElasticLoadBalancingAsyncClientBuilder amazonElasticLoadBalancingAsyncClientBuilder = AmazonElasticLoadBalancingAsyncClientBuilder
            .standard()
            .withClientConfiguration(configuration)
            .withCredentials(awsStaticCredentialsProvider)
            .withExecutorFactory(() -> executorService);

    if (region == null) {
        region = Regions.DEFAULT_REGION.getName();
    }

    if (isAwsClientMock()) {
        AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(
                getAWSMockHost() + AWS_MOCK_LOAD_BALANCING_ENDPOINT, region);
        amazonElasticLoadBalancingAsyncClientBuilder
                .setEndpointConfiguration(endpointConfiguration);
    } else {
        amazonElasticLoadBalancingAsyncClientBuilder.setRegion(region);
    }

    return (AmazonElasticLoadBalancingAsyncClient) amazonElasticLoadBalancingAsyncClientBuilder
            .build();
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:37,代码来源:AWSUtils.java

示例12: couldRecoverFromException

import com.amazonaws.retry.RetryPolicy; //导入依赖的package包/类
/**
 * Returns whether this method was able to initiate recovery from the given exception.
 *
 * <p>If recovery is possible and if the retry policy returned by {@link ClientConfiguration#getRetryPolicy()}
 * suggests to perform another transmission attempt, this methods schedules this task to be run again, with a
 * delay as returned by the back-off strategy of the retry policy.
 *
 * @param amazonClientException the exception that will be passed to the retry policy and the back-off strategy
 * @param getObjectRequest the S3 get-object request
 * @return whether this method was able to initiate recovery
 *
 * @see RetryPolicy.BackoffStrategy#delayBeforeNextRetry(com.amazonaws.AmazonWebServiceRequest, AmazonClientException, int)
 */
private boolean couldRecoverFromException(AmazonClientException amazonClientException,
    GetObjectRequest getObjectRequest) {

    RetryPolicy retryPolicy = s3ClientConfiguration.getRetryPolicy();
    int configuredMaxErrorRetry = s3ClientConfiguration.getMaxErrorRetry();
    // The following is copied from AmazonHttpClient#shouldRetry(): "We should use the maxErrorRetry in the
    // RetryPolicy if either the user has not explicitly set it in ClientConfiguration, or the RetryPolicy
    // is configured to take higher precedence."
    int maxErrorRetry = (configuredMaxErrorRetry < 0 || !retryPolicy.isMaxErrorRetryInClientConfigHonored())
        ? retryPolicy.getMaxErrorRetry()
        : configuredMaxErrorRetry;

    RetryPolicy.RetryCondition retryCondition = retryPolicy.getRetryCondition();
    boolean returnValue = false;
    if (retriesAttempted <= maxErrorRetry
        && retryCondition.shouldRetry(getObjectRequest, amazonClientException, retriesAttempted)) {

        long delay = retryPolicy.getBackoffStrategy()
            .delayBeforeNextRetry(getObjectRequest, amazonClientException, retriesAttempted);
        ++retriesAttempted;

        // java.util.concurrent states: "Actions in a thread prior to the submission of a Runnable to an
        // Executor happen-before its execution begins." Consequently, memory consistency with the thread that
        // will execute this task is guaranteed.
        // Note that the state of this object will not be touched after this line (-> tail recursion).
        executorService.schedule(this, delay, TimeUnit.MILLISECONDS);
        returnValue = true;
    }
    return returnValue;
}
 
开发者ID:cloudkeeper-project,项目名称:cloudkeeper,代码行数:44,代码来源:S3ConnectionImpl.java

示例13: withRetryPolicy

import com.amazonaws.retry.RetryPolicy; //导入依赖的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

示例14: getApiGatewayClient

import com.amazonaws.retry.RetryPolicy; //导入依赖的package包/类
protected AmazonApiGateway getApiGatewayClient() {
    if (apiGatewayClient != null) {
        return apiGatewayClient;
    }

    RetryPolicy.RetryCondition retryCondition = new RetryPolicy.RetryCondition() {

        @Override
        public boolean shouldRetry(AmazonWebServiceRequest amazonWebServiceRequest, AmazonClientException amazonClientException, int i) {
            if (amazonClientException instanceof TooManyRequestsException) {
                return true;
            }
            return PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION.shouldRetry(amazonWebServiceRequest,
                    amazonClientException, i);
        }
    };

    RetryPolicy retryPolicy = new RetryPolicy(retryCondition,
            PredefinedRetryPolicies.DEFAULT_BACKOFF_STRATEGY,
            10, true);

    ClientConfiguration clientConfig = new ClientConfiguration()
            .withRetryPolicy(retryPolicy);

    apiGatewayClient = new AmazonApiGatewayClient(getAWSCredentialsProvideChain(), clientConfig).withRegion(Region.getRegion(Regions.fromName(deployment.getRegion())));
    return apiGatewayClient;
}
 
开发者ID:lambadaframework,项目名称:lambadaframework,代码行数:28,代码来源:ApiGateway.java

示例15: createClient

import com.amazonaws.retry.RetryPolicy; //导入依赖的package包/类
private AmazonKinesisAsyncClient createClient() {

        // Building Kinesis configuration
        int connectionTimeout = ClientConfiguration.DEFAULT_CONNECTION_TIMEOUT;
        int maxConnection = ClientConfiguration.DEFAULT_MAX_CONNECTIONS;

        RetryPolicy retryPolicy = ClientConfiguration.DEFAULT_RETRY_POLICY;
        int socketTimeout = ClientConfiguration.DEFAULT_SOCKET_TIMEOUT;
        boolean useReaper = ClientConfiguration.DEFAULT_USE_REAPER;
        String userAgent = ClientConfiguration.DEFAULT_USER_AGENT;

        ClientConfiguration clientConfiguration = new ClientConfiguration();
        clientConfiguration.setConnectionTimeout(connectionTimeout);
        clientConfiguration.setMaxConnections(maxConnection);
        clientConfiguration.setRetryPolicy(retryPolicy);
        clientConfiguration.setSocketTimeout(socketTimeout);
        clientConfiguration.setUseReaper(useReaper);
        clientConfiguration.setUserAgent(userAgent);

        // Reading credentials from ENV-variables
        AWSCredentialsProvider awsCredentialsProvider = new DefaultAWSCredentialsProviderChain();

        // Configuring Kinesis-client with configuration
        AmazonKinesisAsyncClient kinesisAsyncClient = new AmazonKinesisAsyncClient(awsCredentialsProvider, clientConfiguration);
        Regions myRegion = Regions.fromName(AmazonUtil.getInstance().getRegion());
        kinesisAsyncClient.withRegion(Region.getRegion(myRegion));

        return kinesisAsyncClient;
    }
 
开发者ID:SaschaMoellering,项目名称:ingestion-service,代码行数:30,代码来源:KinesisVerticle.java


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