Example usage for com.amazonaws.retry PredefinedRetryPolicies DEFAULT_RETRY_CONDITION

List of usage examples for com.amazonaws.retry PredefinedRetryPolicies DEFAULT_RETRY_CONDITION

Introduction

In this page you can find the example usage for com.amazonaws.retry PredefinedRetryPolicies DEFAULT_RETRY_CONDITION.

Prototype

RetryPolicy.RetryCondition DEFAULT_RETRY_CONDITION

To view the source code for com.amazonaws.retry PredefinedRetryPolicies DEFAULT_RETRY_CONDITION.

Click Source Link

Document

The SDK default retry condition, which checks for various conditions in the following order:
  • Never retry on requests with non-repeatable content;
  • Retry on client exceptions caused by IOException;
  • Retry on service exceptions that are either 500 internal server errors, 503 service unavailable errors, service throttling errors or clock skew errors.

    Usage

    From source file:com.gu.logback.appender.kinesis.BaseKinesisAppender.java

    License:Open Source License

    /**
     * Configures appender instance and makes it ready for use by the consumers.
     * It validates mandatory parameters and confirms if the configured stream is
     * ready for publishing data yet.//from   w w w . j  a v  a2  s  .c  om
     * 
     * Error details are made available through the fallback handler for this
     * appender
     * 
     * @throws IllegalStateException if we encounter issues configuring this
     *           appender instance
     */
    @Override
    public void start() {
        if (layout == null) {
            initializationFailed = true;
            addError("Invalid configuration - No layout for appender: " + name);
            return;
        }
    
        if (streamName == null) {
            initializationFailed = true;
            addError("Invalid configuration - streamName cannot be null for appender: " + name);
            return;
        }
    
        ClientConfiguration clientConfiguration = new ClientConfiguration();
        clientConfiguration.setMaxErrorRetry(maxRetries);
        clientConfiguration.setRetryPolicy(new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION,
                PredefinedRetryPolicies.DEFAULT_BACKOFF_STRATEGY, maxRetries, true));
        clientConfiguration.setUserAgent(AppenderConstants.USER_AGENT_STRING);
    
        BlockingQueue<Runnable> taskBuffer = new LinkedBlockingDeque<Runnable>(bufferSize);
        threadPoolExecutor = new ThreadPoolExecutor(threadCount, threadCount,
                AppenderConstants.DEFAULT_THREAD_KEEP_ALIVE_SEC, TimeUnit.SECONDS, taskBuffer,
                new BlockFastProducerPolicy());
        threadPoolExecutor.prestartAllCoreThreads();
    
        this.client = createClient(credentials, clientConfiguration, threadPoolExecutor);
    
        client.setRegion(findRegion());
        if (!Validator.isBlank(endpoint)) {
            if (!Validator.isBlank(region)) {
                addError("Received configuration for both region as well as Amazon Kinesis endpoint. (" + endpoint
                        + ") will be used as endpoint instead of default endpoint for region (" + region + ")");
            }
            client.setEndpoint(endpoint);
        }
    
        validateStreamName(client, streamName);
    
        super.start();
    }
    

    From source file:com.gu.logback.appender.kinesis.KinesisAppender.java

    License:Open Source License

    /**
     * Configures this appender instance and makes it ready for use by the
     * consumers. It validates mandatory parameters and confirms if the configured
     * stream is ready for publishing data yet.
     * /*from  w  w  w  . jav  a2s  . c om*/
     * Error details are made available through the fallback handler for this
     * appender
     * 
     * @throws IllegalStateException
     *           if we encounter issues configuring this appender instance
     */
    @Override
    public void start() {
        if (layout == null) {
            initializationFailed = true;
            addError("Invalid configuration - No layout for appender: " + name);
            return;
        }
    
        if (streamName == null) {
            initializationFailed = true;
            addError("Invalid configuration - streamName cannot be null for appender: " + name);
            return;
        }
    
        ClientConfiguration clientConfiguration = new ClientConfiguration();
        clientConfiguration.setMaxErrorRetry(maxRetries);
        clientConfiguration.setRetryPolicy(new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION,
                PredefinedRetryPolicies.DEFAULT_BACKOFF_STRATEGY, maxRetries, true));
        clientConfiguration.setUserAgent(AppenderConstants.USER_AGENT_STRING);
    
        BlockingQueue<Runnable> taskBuffer = new LinkedBlockingDeque<Runnable>(bufferSize);
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(threadCount, threadCount,
                AppenderConstants.DEFAULT_THREAD_KEEP_ALIVE_SEC, TimeUnit.SECONDS, taskBuffer,
                new BlockFastProducerPolicy());
        threadPoolExecutor.prestartAllCoreThreads();
        kinesisClient = new AmazonKinesisAsyncClient(credentials, clientConfiguration, threadPoolExecutor);
    
        boolean regionProvided = !Validator.isBlank(region);
        if (!regionProvided) {
            region = AppenderConstants.DEFAULT_REGION;
        }
        kinesisClient.setRegion(Region.getRegion(Regions.fromName(region)));
        if (!Validator.isBlank(endpoint)) {
            if (regionProvided) {
                addError("Received configuration for both region as well as Amazon Kinesis endpoint. (" + endpoint
                        + ") will be used as endpoint instead of default endpoint for region (" + region + ")");
            }
            kinesisClient.setEndpoint(endpoint);
        }
    
        DescribeStreamResult describeResult = null;
        try {
            describeResult = kinesisClient.describeStream(streamName);
            String streamStatus = describeResult.getStreamDescription().getStreamStatus();
            if (!StreamStatus.ACTIVE.name().equals(streamStatus)
                    && !StreamStatus.UPDATING.name().equals(streamStatus)) {
                initializationFailed = true;
                addError(
                        "Stream " + streamName + " is not ready (in active/updating status) for appender: " + name);
            }
        } catch (ResourceNotFoundException rnfe) {
            initializationFailed = true;
            addError("Stream " + streamName + " doesn't exist for appender: " + name, rnfe);
        }
    
        asyncCallHander = new AsyncPutCallStatsReporter(this);
    
        super.start();
    }
    

    From source file:com.netflix.spinnaker.kork.aws.InstrumentedRetryCondition.java

    License:Apache License

    public InstrumentedRetryCondition(Registry registry) {
        this(registry, PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION);
    }
    

    From source file:com.tcl.gateway.firehose.log4j.FirehoseAppender.java

    License:Open Source License

    /**
     * Configures this appender instance and makes it ready for use by the
     * consumers. It validates mandatory parameters and confirms if the configured
     * stream is ready for publishing data yet.
     * //from   ww  w  . j a va  2 s  .  c o  m
     * Error details are made available through the fallback handler for this
     * appender
     * 
     * @throws IllegalStateException
     *           if we encounter issues configuring this appender instance
     */
    @Override
    public void activateOptions() {
        if (deliveryStreamName == null) {
            initializationFailed = true;
            error("Invalid configuration - streamName cannot be null for appender: " + name);
        }
    
        if (layout == null) {
            initializationFailed = true;
            error("Invalid configuration - No layout for appender: " + name);
        }
    
        ClientConfiguration clientConfiguration = new ClientConfiguration();
        clientConfiguration = setProxySettingsFromSystemProperties(clientConfiguration);
    
        clientConfiguration.setMaxErrorRetry(maxRetries);
        clientConfiguration.setRetryPolicy(new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION,
                PredefinedRetryPolicies.DEFAULT_BACKOFF_STRATEGY, maxRetries, true));
        clientConfiguration.setUserAgent(AppenderConstants.USER_AGENT_STRING);
    
        final BlockingQueue<Runnable> taskBuffer = new LinkedBlockingDeque<Runnable>(bufferSize);
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(threadCount, threadCount,
                AppenderConstants.DEFAULT_THREAD_KEEP_ALIVE_SEC, TimeUnit.SECONDS, taskBuffer,
                new BlockFastProducerPolicy());
        threadPoolExecutor.prestartAllCoreThreads();
        firehoseClient = new AmazonKinesisFirehoseAsyncClient(new CustomCredentialsProviderChain(),
                clientConfiguration, threadPoolExecutor);
    
        boolean regionProvided = !Validator.isBlank(region);
        if (!regionProvided) {
            region = AppenderConstants.DEFAULT_REGION;
        }
        if (!Validator.isBlank(endpoint)) {
            if (regionProvided) {
                LOGGER.warn("Received configuration for both region as well as Amazon Kinesis endpoint. ("
                        + endpoint + ") will be used as endpoint instead of default endpoint for region (" + region
                        + ")");
            }
            firehoseClient.setEndpoint(endpoint);
        } else {
            firehoseClient.setRegion(Region.getRegion(Regions.fromName(region)));
        }
    
        DescribeDeliveryStreamResult describeResult = null;
        try {
            describeResult = firehoseClient.describeDeliveryStream(
                    new DescribeDeliveryStreamRequest().withDeliveryStreamName(deliveryStreamName));
            String streamStatus = describeResult.getDeliveryStreamDescription().getDeliveryStreamStatus();
            if (!StreamStatus.ACTIVE.name().equals(streamStatus)
                    && !StreamStatus.UPDATING.name().equals(streamStatus)) {
                initializationFailed = true;
                error("Delivery Stream " + deliveryStreamName
                        + " is not ready (in active/updating status) for appender: " + name);
            }
        } catch (ResourceNotFoundException rnfe) {
            initializationFailed = true;
            error("Delivery  Stream " + deliveryStreamName + " doesn't exist for appender: " + name, rnfe);
        }
    
        asyncCallHander = new AsyncPutCallStatsReporter(name);
    
        if (metric) {
            MetricRegistry registry = new MetricRegistry();
            registry.register("Gauge", new Gauge<Integer>() {
    
                @Override
                public Integer getValue() {
                    return taskBuffer.size();
                }
    
            });
    
            ConsoleReporter.forRegistry(registry).build().start(3, TimeUnit.SECONDS);
        }
    }
    

    From source file:io.confluent.connect.s3.storage.S3Storage.java

    License:Open Source License

    /**
     * Creates a retry policy, based on full jitter backoff strategy
     * and default retry condition./*from  w w w.  j a va2  s .  c  o m*/
     * Visible for testing.
     *
     * @param config the S3 configuration.
     * @return retry policy
     * @see com.amazonaws.retry.PredefinedRetryPolicies.SDKDefaultRetryCondition
     * @see PredefinedBackoffStrategies.FullJitterBackoffStrategy
     */
    protected RetryPolicy newFullJitterRetryPolicy(S3SinkConnectorConfig config) {
    
        PredefinedBackoffStrategies.FullJitterBackoffStrategy backoffStrategy = new PredefinedBackoffStrategies.FullJitterBackoffStrategy(
                config.getLong(S3_RETRY_BACKOFF_CONFIG).intValue(), S3_RETRY_MAX_BACKOFF_TIME_MS);
    
        RetryPolicy retryPolicy = new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION, backoffStrategy,
                conf.getS3PartRetries(), false);
        return retryPolicy;
    }
    

    From source file:org.finra.herd.dao.RetryPolicyFactory.java

    License:Apache License

    /**
     * Gets the application's default retry policy. The policy uses PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION, a SimpleExponentialBackoffStrategy, and the
     * maximum number of attempts is dynamically configurable through AWS_MAX_RETRY_ATTEMPT.
     * //from w  w w  .j av  a2  s.co m
     * @return RetryPolicy
     */
    public RetryPolicy getRetryPolicy() {
        return new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION, backoffStrategy,
                configurationHelper.getProperty(ConfigurationValue.AWS_MAX_RETRY_ATTEMPT, Integer.class), true);
    }