in src/native/s3_client.c [45:149]
JNIEXPORT jlong JNICALL Java_software_amazon_awssdk_crt_s3_S3Client_s3ClientNew(
JNIEnv *env,
jclass jni_class,
jobject s3_client_jobject,
jbyteArray jni_region,
jbyteArray jni_endpoint,
jlong jni_client_bootstrap,
jlong jni_tls_ctx,
jlong jni_credentials_provider,
jlong part_size,
jdouble throughput_target_gbps,
int max_connections,
jobject jni_standard_retry_options,
jboolean compute_content_md5) {
(void)jni_class;
struct aws_allocator *allocator = aws_jni_get_allocator();
struct aws_client_bootstrap *client_bootstrap = (struct aws_client_bootstrap *)jni_client_bootstrap;
if (!client_bootstrap) {
aws_jni_throw_runtime_exception(env, "Invalid Client Bootstrap");
return (jlong)NULL;
}
struct aws_credentials_provider *credentials_provider = (struct aws_credentials_provider *)jni_credentials_provider;
if (!credentials_provider) {
aws_jni_throw_runtime_exception(env, "Invalid Credentials Provider");
return (jlong)NULL;
}
struct aws_retry_strategy *retry_strategy = NULL;
if (jni_standard_retry_options != NULL) {
struct aws_standard_retry_options retry_options;
if (aws_standard_retry_options_from_java(env, jni_standard_retry_options, &retry_options)) {
return (jlong)NULL;
}
if (retry_options.backoff_retry_options.el_group == NULL) {
retry_options.backoff_retry_options.el_group = client_bootstrap->event_loop_group;
}
retry_strategy = aws_retry_strategy_new_standard(allocator, &retry_options);
if (retry_strategy == NULL) {
aws_jni_throw_runtime_exception(env, "Could not create retry strategy with standard-retry-options");
return (jlong)NULL;
}
}
struct aws_byte_cursor region = aws_jni_byte_cursor_from_jbyteArray_acquire(env, jni_region);
struct s3_client_callback_data *callback_data =
aws_mem_calloc(allocator, 1, sizeof(struct s3_client_callback_data));
AWS_FATAL_ASSERT(callback_data);
callback_data->java_s3_client = (*env)->NewGlobalRef(env, s3_client_jobject);
jint jvmresult = (*env)->GetJavaVM(env, &callback_data->jvm);
(void)jvmresult;
AWS_FATAL_ASSERT(jvmresult == 0);
struct aws_signing_config_aws signing_config;
aws_s3_init_default_signing_config(&signing_config, region, credentials_provider);
struct aws_tls_connection_options *tls_options = NULL;
struct aws_tls_connection_options tls_options_storage;
AWS_ZERO_STRUCT(tls_options_storage);
if (jni_tls_ctx) {
struct aws_tls_ctx *tls_ctx = (void *)jni_tls_ctx;
tls_options = &tls_options_storage;
aws_tls_connection_options_init_from_ctx(tls_options, tls_ctx);
struct aws_byte_cursor endpoint = aws_jni_byte_cursor_from_jbyteArray_acquire(env, jni_endpoint);
aws_tls_connection_options_set_server_name(tls_options, allocator, &endpoint);
aws_jni_byte_cursor_from_jbyteArray_release(env, jni_endpoint, endpoint);
}
struct aws_s3_client_config client_config = {
.max_active_connections_override = max_connections,
.region = region,
.client_bootstrap = client_bootstrap,
.tls_connection_options = tls_options,
.signing_config = &signing_config,
.part_size = (size_t)part_size,
.throughput_target_gbps = throughput_target_gbps,
.retry_strategy = retry_strategy,
.shutdown_callback = s_on_s3_client_shutdown_complete_callback,
.shutdown_callback_user_data = callback_data,
.compute_content_md5 = compute_content_md5 ? AWS_MR_CONTENT_MD5_ENABLED : AWS_MR_CONTENT_MD5_DISABLED,
};
struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config);
if (!client) {
aws_jni_throw_runtime_exception(env, "S3Client.aws_s3_client_new: creating aws_s3_client failed");
goto clean_up;
}
clean_up:
aws_retry_strategy_release(retry_strategy);
aws_jni_byte_cursor_from_jbyteArray_release(env, jni_region, region);
return (jlong)client;
}