Source:
<code>private AwsContext(Configuration configuration) { String region = configuration.region(); String rootDirectory = configuration.rootDirectory(); if (rootDirectory != null && rootDirectory.length() > 0 && rootDirectory.charAt(0) == '/') { rootDirectory = rootDirectory.substring(1); } AWSCredentials credentials = configuration.sessionToken() == null || configuration.sessionToken().isEmpty() ? new BasicAWSCredentials(configuration.accessKey(), configuration.secretKey()) : new BasicSessionCredentials(configuration.accessKey(), configuration.secretKey(), configuration.sessionToken()); AWSStaticCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); RequestHandler2 handler = new RequestHandler2() { @Override public void afterError(Request<?> request, Response<?> response, Exception e) { process(request, response, e); } @Override public void afterResponse(Request<?> request, Response<?> response) { process(request, response, null); } private void process(Request<?> request, Response<?> response, Exception e) { if (monitor != null) { TimingInfo timing = request.getAWSRequestMetrics().getTimingInfo(); if (timing.isEndTimeKnown()) { long requestDuration = timing.getEndTimeNano() - timing.getStartTimeNano(); monitor.requestDuration(requestDuration, TimeUnit.NANOSECONDS); } if (e == null) { monitor.requestCount(); } else { monitor.requestError(); } } } }; AmazonS3 s3 = AmazonS3ClientBuilder.standard().withCredentials(credentialsProvider).withRegion(region) .withRequestHandlers(handler).build(); <START> AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.standard().withCredentials(credentialsProvider) <END> .withRegion(region).withRequestHandlers(handler).build(); this.s3 = s3; this.bucketName = configuration.bucketName(); this.rootDirectory = rootDirectory.endsWith("/") ? rootDirectory : rootDirectory + "/"; this.ddb = ddb; this.journalTable = new DynamoDB(ddb).getTable(configuration.journalTableName()); this.lockTableName = configuration.lockTableName(); }</code><technical_language>Is ok re-use previous hander here? request metrics skewed b/c frequent calls update journal..</technical_language>

Target:
private AwsContext(Configuration configuration) { AmazonS3ClientBuilder s3ClientBuilder = AmazonS3ClientBuilder.standard(); AmazonDynamoDBClientBuilder dynamoDBClientBuilder = AmazonDynamoDBClientBuilder.standard(); if (!isEmpty(configuration.accessKey())) { AWSCredentials credentials = isEmpty(configuration.sessionToken()) ? new BasicAWSCredentials(configuration.accessKey(), configuration.secretKey()) : new BasicSessionCredentials(configuration.accessKey(), configuration.secretKey(), configuration.sessionToken()); AWSStaticCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); s3ClientBuilder = s3ClientBuilder.withCredentials(credentialsProvider); dynamoDBClientBuilder = dynamoDBClientBuilder.withCredentials(credentialsProvider); } String region = configuration.region(); if (!isEmpty(region)) { s3ClientBuilder = s3ClientBuilder.withRegion(region); dynamoDBClientBuilder = dynamoDBClientBuilder.withRegion(region); } RequestHandler2 handler = new RequestHandler2() { @Override public void afterError(Request<?> request, Response<?> response, Exception e) { process(request, response, e); } @Override public void afterResponse(Request<?> request, Response<?> response) { process(request, response, null); } private void process(Request<?> request, Response<?> response, Exception e) { if (monitor != null) { TimingInfo timing = request.getAWSRequestMetrics().getTimingInfo(); if (timing.isEndTimeKnown()) { long requestDuration = timing.getEndTimeNano() - timing.getStartTimeNano(); monitor.requestDuration(requestDuration, TimeUnit.NANOSECONDS); } if (e == null) { monitor.requestCount(); } else { monitor.requestError(); } } } }; s3ClientBuilder = s3ClientBuilder.withRequestHandlers(handler); dynamoDBClientBuilder = dynamoDBClientBuilder.withRequestHandlers(handler); this.directory = new S3Directory(s3ClientBuilder.build(), configuration.bucketName(), configuration.rootDirectory()); this.dynamoDBClient = new DynamoDBClient(dynamoDBClientBuilder.build(), configuration.journalTableName(), configuration.lockTableName()); this.path = configuration.bucketName() + "/" + configuration.rootDirectory() + "/"; }