List of usage examples for com.amazonaws ClientConfiguration withConnectionTimeout
public ClientConfiguration withConnectionTimeout(int connectionTimeout)
From source file:com.amazon.janusgraph.diskstorage.dynamodb.Client.java
License:Open Source License
public Client(final Configuration config) { final String credentialsClassName = config.get(Constants.DYNAMODB_CREDENTIALS_CLASS_NAME); final Class<?> clazz; try {//from w w w . j a v a 2 s . c o m clazz = Class.forName(credentialsClassName); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(VALIDATE_CREDENTIALS_CLASS_NAME, e); } final String[] credentialsConstructorArgsValues = config .get(Constants.DYNAMODB_CREDENTIALS_CONSTRUCTOR_ARGS); final List<String> filteredArgList = new ArrayList<>(); for (Object obj : credentialsConstructorArgsValues) { final String str = obj.toString(); if (!str.isEmpty()) { filteredArgList.add(str); } } final AWSCredentialsProvider credentialsProvider; if (AWSCredentials.class.isAssignableFrom(clazz)) { final AWSCredentials credentials = createCredentials(clazz, filteredArgList.toArray(new String[filteredArgList.size()])); credentialsProvider = new AWSStaticCredentialsProvider(credentials); } else if (AWSCredentialsProvider.class.isAssignableFrom(clazz)) { credentialsProvider = createCredentialsProvider(clazz, credentialsConstructorArgsValues); } else { throw new IllegalArgumentException(VALIDATE_CREDENTIALS_CLASS_NAME); } //begin adaptation of constructor at //https://github.com/buka/titan/blob/master/src/main/java/com/thinkaurelius/titan/diskstorage/dynamodb/DynamoDBClient.java#L77 final ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.withConnectionTimeout(config.get(Constants.DYNAMODB_CLIENT_CONN_TIMEOUT)) .withConnectionTTL(config.get(Constants.DYNAMODB_CLIENT_CONN_TTL)) .withMaxConnections(config.get(Constants.DYNAMODB_CLIENT_MAX_CONN)) .withMaxErrorRetry(config.get(Constants.DYNAMODB_CLIENT_MAX_ERROR_RETRY)) .withGzip(config.get(Constants.DYNAMODB_CLIENT_USE_GZIP)) .withReaper(config.get(Constants.DYNAMODB_CLIENT_USE_REAPER)) .withUserAgentSuffix(config.get(Constants.DYNAMODB_CLIENT_USER_AGENT)) .withSocketTimeout(config.get(Constants.DYNAMODB_CLIENT_SOCKET_TIMEOUT)) .withSocketBufferSizeHints(config.get(Constants.DYNAMODB_CLIENT_SOCKET_BUFFER_SEND_HINT), config.get(Constants.DYNAMODB_CLIENT_SOCKET_BUFFER_RECV_HINT)) .withProxyDomain(config.get(Constants.DYNAMODB_CLIENT_PROXY_DOMAIN)) .withProxyWorkstation(config.get(Constants.DYNAMODB_CLIENT_PROXY_WORKSTATION)) .withProxyHost(config.get(Constants.DYNAMODB_CLIENT_PROXY_HOST)) .withProxyPort(config.get(Constants.DYNAMODB_CLIENT_PROXY_PORT)) .withProxyUsername(config.get(Constants.DYNAMODB_CLIENT_PROXY_USERNAME)) .withProxyPassword(config.get(Constants.DYNAMODB_CLIENT_PROXY_PASSWORD)); forceConsistentRead = config.get(Constants.DYNAMODB_FORCE_CONSISTENT_READ); //end adaptation of constructor at //https://github.com/buka/titan/blob/master/src/main/java/com/thinkaurelius/titan/diskstorage/dynamodb/DynamoDBClient.java#L77 enableParallelScan = config.get(Constants.DYNAMODB_ENABLE_PARALLEL_SCAN); prefix = config.get(Constants.DYNAMODB_TABLE_PREFIX); final String metricsPrefix = config.get(Constants.DYNAMODB_METRICS_PREFIX); final long maxRetries = config.get(Constants.DYNAMODB_MAX_SELF_THROTTLED_RETRIES); Preconditions.checkArgument(maxRetries >= 0, Constants.DYNAMODB_MAX_SELF_THROTTLED_RETRIES.getName() + " must be at least 0"); final long retryMillis = config.get(Constants.DYNAMODB_INITIAL_RETRY_MILLIS); Preconditions.checkArgument(retryMillis > 0, Constants.DYNAMODB_INITIAL_RETRY_MILLIS.getName() + " must be at least 1"); final double controlPlaneRate = config.get(Constants.DYNAMODB_CONTROL_PLANE_RATE); Preconditions.checkArgument(controlPlaneRate >= 0, "must have a positive control plane rate"); final RateLimiter controlPlaneRateLimiter = RateLimiter.create(controlPlaneRate); final Map<String, RateLimiter> readRateLimit = new HashMap<>(); final Map<String, RateLimiter> writeRateLimit = new HashMap<>(); final Set<String> storeNames = new HashSet<>(Constants.REQUIRED_BACKEND_STORES); storeNames.add(config.get(GraphDatabaseConfiguration.IDS_STORE_NAME)); storeNames.addAll(config.getContainedNamespaces(Constants.DYNAMODB_STORES_NAMESPACE)); storeNames.forEach(storeName -> setupStore(config, readRateLimit, writeRateLimit, storeName)); delegate = new DynamoDbDelegate( JanusGraphConfigUtil.getNullableConfigValue(config, Constants.DYNAMODB_CLIENT_ENDPOINT), JanusGraphConfigUtil.getNullableConfigValue(config, Constants.DYNAMODB_CLIENT_SIGNING_REGION), credentialsProvider, clientConfig, config, readRateLimit, writeRateLimit, maxRetries, retryMillis, prefix, metricsPrefix, controlPlaneRateLimiter); }
From source file:com.rapid7.diskstorage.dynamodb.Client.java
License:Open Source License
public Client(com.thinkaurelius.titan.diskstorage.configuration.Configuration config) { String credentialsClassName = config.get(Constants.DYNAMODB_CREDENTIALS_CLASS_NAME); Class<?> clazz;//w w w. j ava 2s . c o m try { clazz = Class.forName(credentialsClassName); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(VALIDATE_CREDENTIALS_CLASS_NAME, e); } String[] credentialsConstructorArgsValues = config.get(Constants.DYNAMODB_CREDENTIALS_CONSTRUCTOR_ARGS); final List<String> filteredArgList = new ArrayList<String>(); for (Object obj : credentialsConstructorArgsValues) { final String str = obj.toString(); if (!str.isEmpty()) { filteredArgList.add(str); } } AWSCredentialsProvider credentialsProvider; if (AWSCredentials.class.isAssignableFrom(clazz)) { AWSCredentials credentials = createCredentials(clazz, filteredArgList.toArray(new String[filteredArgList.size()])); credentialsProvider = new StaticCredentialsProvider(credentials); } else if (AWSCredentialsProvider.class.isAssignableFrom(clazz)) { credentialsProvider = createCredentialsProvider(clazz, credentialsConstructorArgsValues); } else { throw new IllegalArgumentException(VALIDATE_CREDENTIALS_CLASS_NAME); } //begin adaptation of constructor at //https://github.com/buka/titan/blob/master/src/main/java/com/thinkaurelius/titan/diskstorage/dynamodb/DynamoDBClient.java#L77 ClientConfiguration clientConfig = new ClientConfiguration(); clientConfig.withConnectionTimeout(config.get(Constants.DYNAMODB_CLIENT_CONN_TIMEOUT)) // .withConnectionTTL(config.get(Constants.DYNAMODB_CLIENT_CONN_TTL)) // .withMaxConnections(config.get(Constants.DYNAMODB_CLIENT_MAX_CONN)) // .withMaxErrorRetry(config.get(Constants.DYNAMODB_CLIENT_MAX_ERROR_RETRY)) // .withGzip(config.get(Constants.DYNAMODB_CLIENT_USE_GZIP)) // .withReaper(config.get(Constants.DYNAMODB_CLIENT_USE_REAPER)) // .withUserAgent(config.get(Constants.DYNAMODB_CLIENT_USER_AGENT)) // .withSocketTimeout(config.get(Constants.DYNAMODB_CLIENT_SOCKET_TIMEOUT)) // .withSocketBufferSizeHints( // config.get(Constants.DYNAMODB_CLIENT_SOCKET_BUFFER_SEND_HINT), // config.get(Constants.DYNAMODB_CLIENT_SOCKET_BUFFER_RECV_HINT)) // .withProxyDomain(config.get(Constants.DYNAMODB_CLIENT_PROXY_DOMAIN)) // .withProxyWorkstation(config.get(Constants.DYNAMODB_CLIENT_PROXY_WORKSTATION)) // .withProxyHost(config.get(Constants.DYNAMODB_CLIENT_PROXY_HOST)) // .withProxyPort(config.get(Constants.DYNAMODB_CLIENT_PROXY_PORT)) // .withProxyUsername(config.get(Constants.DYNAMODB_CLIENT_PROXY_USERNAME)) // .withProxyPassword(config.get(Constants.DYNAMODB_CLIENT_PROXY_PASSWORD)); // forceConsistentRead = config.get(Constants.DYNAMODB_FORCE_CONSISTENT_READ); //end adaptation of constructor at //https://github.com/buka/titan/blob/master/src/main/java/com/thinkaurelius/titan/diskstorage/dynamodb/DynamoDBClient.java#L77 enableParallelScan = config.get(Constants.DYNAMODB_ENABLE_PARALLEL_SCAN); prefix = config.get(Constants.DYNAMODB_TABLE_PREFIX); final String metricsPrefix = config.get(Constants.DYNAMODB_METRICS_PREFIX); final long maxRetries = config.get(Constants.DYNAMODB_MAX_SELF_THROTTLED_RETRIES); if (maxRetries < 0) { throw new IllegalArgumentException( Constants.DYNAMODB_MAX_SELF_THROTTLED_RETRIES.getName() + " must be at least 0"); } final long retryMillis = config.get(Constants.DYNAMODB_INITIAL_RETRY_MILLIS); if (retryMillis <= 0) { throw new IllegalArgumentException( Constants.DYNAMODB_INITIAL_RETRY_MILLIS.getName() + " must be at least 1"); } final double controlPlaneRate = config.get(Constants.DYNAMODB_CONTROL_PLANE_RATE); if (controlPlaneRate < 0) { throw new IllegalArgumentException("must have a positive control plane rate"); } final RateLimiter controlPlaneRateLimiter = RateLimiter.create(controlPlaneRate); final Map<String, RateLimiter> readRateLimit = new HashMap<>(); final Map<String, RateLimiter> writeRateLimit = new HashMap<>(); Set<String> storeNames = new HashSet<String>(Constants.REQUIRED_BACKEND_STORES); storeNames.addAll(config.getContainedNamespaces(Constants.DYNAMODB_STORES_NAMESPACE)); for (String storeName : storeNames) { setupStore(config, prefix, readRateLimit, writeRateLimit, storeName); } endpoint = TitanConfigUtil.getNullableConfigValue(config, Constants.DYNAMODB_CLIENT_ENDPOINT); delegate = new DynamoDBDelegate(endpoint, credentialsProvider, clientConfig, config, readRateLimit, writeRateLimit, maxRetries, retryMillis, prefix, metricsPrefix, controlPlaneRateLimiter); }