Example usage for com.amazonaws ClientConfiguration DEFAULT_MAX_CONNECTIONS

List of usage examples for com.amazonaws ClientConfiguration DEFAULT_MAX_CONNECTIONS

Introduction

In this page you can find the example usage for com.amazonaws ClientConfiguration DEFAULT_MAX_CONNECTIONS.

Prototype

int DEFAULT_MAX_CONNECTIONS

To view the source code for com.amazonaws ClientConfiguration DEFAULT_MAX_CONNECTIONS.

Click Source Link

Document

The default max connection pool size.

Usage

From source file:com.amazon.kinesis.streaming.agent.config.AgentConfiguration.java

License:Open Source License

public int defaultMaxConnections() {
    return Math.max(ClientConfiguration.DEFAULT_MAX_CONNECTIONS, maxSendingThreads());
}

From source file:com.dssmp.agent.config.AgentConfiguration.java

License:Apache License

public int defaultMaxConnections() {
    return Math.max(com.amazonaws.ClientConfiguration.DEFAULT_MAX_CONNECTIONS, maxSendingThreads());
}

From source file:com.plumbee.flume.source.sqs.SQSSource.java

License:Apache License

@Override
public void configure(Context context) {

    // Mandatory configuration parameters.
    queueURL = context.getString(ConfigurationConstants.CONFIG_QUEUE_URL);
    Preconditions.checkArgument(StringUtils.isNotBlank(queueURL), ErrorMessages.MISSING_MANDATORY_PARAMETER,
            ConfigurationConstants.CONFIG_QUEUE_URL);

    // Optional configuration parameters.
    queueRecvBatchSize = context.getInteger(ConfigurationConstants.CONFIG_RECV_BATCH_SIZE,
            ConfigurationConstants.DEFAULT_RECV_BATCH_SIZE);
    Preconditions.checkArgument(queueRecvBatchSize > 0, ErrorMessages.NEGATIVE_PARAMETER_VALUE,
            ConfigurationConstants.CONFIG_RECV_BATCH_SIZE);

    queueDeleteBatchSize = context.getInteger(ConfigurationConstants.CONFIG_DELETE_BATCH_SIZE,
            ConfigurationConstants.DEFAULT_DELETE_BATCH_SIZE);
    Preconditions.checkArgument(queueDeleteBatchSize > 0, ErrorMessages.NEGATIVE_PARAMETER_VALUE,
            ConfigurationConstants.CONFIG_DELETE_BATCH_SIZE);

    queueRecvPollingTimeout = context.getInteger(ConfigurationConstants.CONFIG_RECV_TIMEOUT,
            ConfigurationConstants.DEFAULT_RECV_TIMEOUT);
    Preconditions.checkArgument(queueRecvPollingTimeout > 0, ErrorMessages.NEGATIVE_PARAMETER_VALUE,
            ConfigurationConstants.CONFIG_RECV_TIMEOUT);

    queueRecvVisabilityTimeout = context.getInteger(ConfigurationConstants.CONFIG_RECV_VISTIMEOUT,
            ConfigurationConstants.DEFAULT_RECV_VISTIMEOUT);
    Preconditions.checkArgument(queueRecvVisabilityTimeout > 0, ErrorMessages.NEGATIVE_PARAMETER_VALUE,
            ConfigurationConstants.CONFIG_RECV_VISTIMEOUT);

    batchSize = context.getInteger(ConfigurationConstants.CONFIG_BATCH_SIZE,
            ConfigurationConstants.DEFAULT_BATCH_SIZE);
    Preconditions.checkArgument(batchSize > 0, ErrorMessages.NEGATIVE_PARAMETER_VALUE,
            ConfigurationConstants.CONFIG_BATCH_SIZE);

    nbThreads = context.getInteger(ConfigurationConstants.CONFIG_NB_CONSUMER_THREADS,
            ConfigurationConstants.DEFAULT_NB_CONSUMER_THREADS);
    Preconditions.checkArgument(nbThreads > 0, ErrorMessages.NEGATIVE_PARAMETER_VALUE,
            ConfigurationConstants.CONFIG_NB_CONSUMER_THREADS);
    Preconditions.checkArgument(nbThreads <= ClientConfiguration.DEFAULT_MAX_CONNECTIONS,
            "%s cannot cannot exceed %s " + "(Default Amazon client connection pool size)",
            ConfigurationConstants.CONFIG_NB_CONSUMER_THREADS, ClientConfiguration.DEFAULT_MAX_CONNECTIONS);

    // Don't let the number of messages to be polled from SQS using one
    // call exceed the transaction batchSize for the downstream channel.
    Preconditions.checkArgument(queueRecvBatchSize <= batchSize, "%s must be smaller than or equal to the %s",
            ConfigurationConstants.CONFIG_RECV_BATCH_SIZE, ConfigurationConstants.CONFIG_BATCH_SIZE);

    flushInterval = context.getLong(ConfigurationConstants.CONFIG_FLUSH_INTERVAL,
            ConfigurationConstants.DEFAULT_FLUSH_INTERVAL);
    Preconditions.checkArgument(flushInterval > 0, ErrorMessages.NEGATIVE_PARAMETER_VALUE,
            ConfigurationConstants.CONFIG_FLUSH_INTERVAL);
    flushInterval = TimeUnit.SECONDS.toMillis(flushInterval);

    // Runner backoff configuration.
    maxBackOffSleep = context.getLong(ConfigurationConstants.CONFIG_MAX_BACKOFF_SLEEP,
            ConfigurationConstants.DEFAULT_MAX_BACKOFF_SLEEP);
    Preconditions.checkArgument(maxBackOffSleep > 0, ErrorMessages.NEGATIVE_PARAMETER_VALUE,
            ConfigurationConstants.CONFIG_MAX_BACKOFF_SLEEP);

    backOffSleepIncrement = context.getLong(ConfigurationConstants.CONFIG_BACKOFF_SLEEP_INCREMENT,
            ConfigurationConstants.DEFAULT_BACKOFF_SLEEP_INCREMENT);
    Preconditions.checkArgument(backOffSleepIncrement > 0, ErrorMessages.NEGATIVE_PARAMETER_VALUE,
            ConfigurationConstants.CONFIG_BACKOFF_SLEEP_INCREMENT);

    Preconditions.checkArgument(flushInterval > maxBackOffSleep, "%s too high, %s cannot be respected",
            ConfigurationConstants.CONFIG_MAX_BACKOFF_SLEEP, ConfigurationConstants.CONFIG_FLUSH_INTERVAL);

    // Log a warning if the flushInterval plus maxBackOffSleep exceed
    // the queueRecvVisabilityTimeout of messages. On queues with
    // low levels of throughput this can cause message duplication!
    if ((flushInterval + maxBackOffSleep) > TimeUnit.SECONDS.toMillis(queueRecvVisabilityTimeout)) {
        LOGGER.warn("{} too low, potential for message duplication",
                ConfigurationConstants.CONFIG_FLUSH_INTERVAL);
    }//from www .j a  v a  2s .  c  om

    // The following configuration options allows credentials to be
    // provided via the configuration context.
    String awsAccessKeyId = context.getString(ConfigurationConstants.CONFIG_AWS_ACCESS_KEY_ID);
    String awsSecretKey = context.getString(ConfigurationConstants.CONFIG_AWS_SECRET_KEY);

    if (StringUtils.isNotBlank(awsAccessKeyId) && StringUtils.isNotBlank(awsSecretKey)) {
        if (client == null) {
            // Create the AmazonSQSClient using BasicAWSCredentials
            client = new AmazonSQSClient(new BasicAWSCredentials(awsAccessKeyId, awsSecretKey),
                    new ClientConfiguration().withMaxConnections(nbThreads));
        } else {
            LOGGER.warn("Cannot set AWS credentials for AmazonSQSClient, " + "client already initialized");
        }
    }

    // Default to the DefaultAWSCredentialsProviderChain.
    if (client == null) {
        client = new AmazonSQSClient(new ClientConfiguration().withMaxConnections(nbThreads));
    }
}

From source file:com.zanox.vertx.mods.KinesisMessageProcessor.java

License:Apache License

private AmazonKinesisAsyncClient createClient() {

    // Building Kinesis configuration
    int connectionTimeout = getOptionalIntConfig(CONNECTION_TIMEOUT,
            ClientConfiguration.DEFAULT_CONNECTION_TIMEOUT);
    int maxConnection = getOptionalIntConfig(MAX_CONNECTION, ClientConfiguration.DEFAULT_MAX_CONNECTIONS);

    // TODO: replace default retry policy
    RetryPolicy retryPolicy = ClientConfiguration.DEFAULT_RETRY_POLICY;
    int socketTimeout = getOptionalIntConfig(SOCKET_TIMEOUT, ClientConfiguration.DEFAULT_SOCKET_TIMEOUT);
    boolean useReaper = getOptionalBooleanConfig(USE_REAPER, ClientConfiguration.DEFAULT_USE_REAPER);
    String userAgent = getOptionalStringConfig(USER_AGENT, ClientConfiguration.DEFAULT_USER_AGENT);

    streamName = getMandatoryStringConfig(STREAM_NAME);
    partitionKey = getMandatoryStringConfig(PARTITION_KEY);
    region = getMandatoryStringConfig(REGION);

    logger.info(" --- Stream name: " + streamName);
    logger.info(" --- Partition key: " + partitionKey);
    logger.info(" --- Region: " + region);

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

    /*//  www.j  av a 2s.c  o m
    AWS credentials provider chain that looks for credentials in this order:
       Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY
       Java System Properties - aws.accessKeyId and aws.secretKey
       Credential profiles file at the default location (~/.aws/credentials) shared by all AWS SDKs and the AWS CLI
       Instance profile credentials delivered through the Amazon EC2 metadata service
    */

    AWSCredentialsProvider awsCredentialsProvider = new DefaultAWSCredentialsProviderChain();

    // Configuring Kinesis-client with configuration
    AmazonKinesisAsyncClient kinesisAsyncClient = new AmazonKinesisAsyncClient(awsCredentialsProvider,
            clientConfiguration);
    Region awsRegion = RegionUtils.getRegion(region);
    kinesisAsyncClient.setRegion(awsRegion);

    return kinesisAsyncClient;
}