com.amazonaws.services.keyspaces.AmazonKeyspacesAsyncClient Maven / Gradle / Ivy
Show all versions of aws-java-sdk-keyspaces Show documentation
/*
* Copyright 2019-2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.amazonaws.services.keyspaces;
import javax.annotation.Generated;
import com.amazonaws.services.keyspaces.model.*;
import com.amazonaws.client.AwsAsyncClientParams;
import com.amazonaws.annotation.ThreadSafe;
import java.util.concurrent.ExecutorService;
/**
* Client for accessing Amazon Keyspaces asynchronously. Each asynchronous method will return a Java Future object
* representing the asynchronous operation; overloads which accept an {@code AsyncHandler} can be used to receive
* notification when an asynchronous operation completes.
*
*
* Amazon Keyspaces (for Apache Cassandra) is a scalable, highly available, and managed Apache Cassandra-compatible
* database service. Amazon Keyspaces makes it easy to migrate, run, and scale Cassandra workloads in the Amazon Web
* Services Cloud. With just a few clicks on the Amazon Web Services Management Console or a few lines of code, you can
* create keyspaces and tables in Amazon Keyspaces, without deploying any infrastructure or installing software.
*
*
* In addition to supporting Cassandra Query Language (CQL) requests via open-source Cassandra drivers, Amazon Keyspaces
* supports data definition language (DDL) operations to manage keyspaces and tables using the Amazon Web Services SDK
* and CLI, as well as infrastructure as code (IaC) services and tools such as CloudFormation and Terraform. This API
* reference describes the supported DDL operations in detail.
*
*
* For the list of all supported CQL APIs, see Supported Cassandra APIs,
* operations, and data types in Amazon Keyspaces in the Amazon Keyspaces Developer Guide.
*
*
* To learn how Amazon Keyspaces API actions are recorded with CloudTrail, see Amazon Keyspaces information in CloudTrail in the Amazon Keyspaces Developer Guide.
*
*
* For more information about Amazon Web Services APIs, for example how to implement retry logic or how to sign Amazon
* Web Services API requests, see Amazon Web
* Services APIs in the General Reference.
*
*/
@ThreadSafe
@Generated("com.amazonaws:aws-java-sdk-code-generator")
public class AmazonKeyspacesAsyncClient extends AmazonKeyspacesClient implements AmazonKeyspacesAsync {
private static final int DEFAULT_THREAD_POOL_SIZE = 50;
private final java.util.concurrent.ExecutorService executorService;
public static AmazonKeyspacesAsyncClientBuilder asyncBuilder() {
return AmazonKeyspacesAsyncClientBuilder.standard();
}
/**
* Constructs a new asynchronous client to invoke service methods on Amazon Keyspaces using the specified
* parameters.
*
* @param asyncClientParams
* Object providing client parameters.
*/
AmazonKeyspacesAsyncClient(AwsAsyncClientParams asyncClientParams) {
this(asyncClientParams, false);
}
/**
* Constructs a new asynchronous client to invoke service methods on Amazon Keyspaces using the specified
* parameters.
*
* @param asyncClientParams
* Object providing client parameters.
* @param endpointDiscoveryEnabled
* true will enable endpoint discovery if the service supports it.
*/
AmazonKeyspacesAsyncClient(AwsAsyncClientParams asyncClientParams, boolean endpointDiscoveryEnabled) {
super(asyncClientParams, endpointDiscoveryEnabled);
this.executorService = asyncClientParams.getExecutor();
}
/**
* Returns the executor service used by this client to execute async requests.
*
* @return The executor service used by this client to execute async requests.
*/
public ExecutorService getExecutorService() {
return executorService;
}
@Override
public java.util.concurrent.Future createKeyspaceAsync(CreateKeyspaceRequest request) {
return createKeyspaceAsync(request, null);
}
@Override
public java.util.concurrent.Future createKeyspaceAsync(final CreateKeyspaceRequest request,
final com.amazonaws.handlers.AsyncHandler asyncHandler) {
final CreateKeyspaceRequest finalRequest = beforeClientExecution(request);
return executorService.submit(new java.util.concurrent.Callable() {
@Override
public CreateKeyspaceResult call() throws Exception {
CreateKeyspaceResult result = null;
try {
result = executeCreateKeyspace(finalRequest);
} catch (Exception ex) {
if (asyncHandler != null) {
asyncHandler.onError(ex);
}
throw ex;
}
if (asyncHandler != null) {
asyncHandler.onSuccess(finalRequest, result);
}
return result;
}
});
}
@Override
public java.util.concurrent.Future createTableAsync(CreateTableRequest request) {
return createTableAsync(request, null);
}
@Override
public java.util.concurrent.Future createTableAsync(final CreateTableRequest request,
final com.amazonaws.handlers.AsyncHandler asyncHandler) {
final CreateTableRequest finalRequest = beforeClientExecution(request);
return executorService.submit(new java.util.concurrent.Callable() {
@Override
public CreateTableResult call() throws Exception {
CreateTableResult result = null;
try {
result = executeCreateTable(finalRequest);
} catch (Exception ex) {
if (asyncHandler != null) {
asyncHandler.onError(ex);
}
throw ex;
}
if (asyncHandler != null) {
asyncHandler.onSuccess(finalRequest, result);
}
return result;
}
});
}
@Override
public java.util.concurrent.Future deleteKeyspaceAsync(DeleteKeyspaceRequest request) {
return deleteKeyspaceAsync(request, null);
}
@Override
public java.util.concurrent.Future deleteKeyspaceAsync(final DeleteKeyspaceRequest request,
final com.amazonaws.handlers.AsyncHandler asyncHandler) {
final DeleteKeyspaceRequest finalRequest = beforeClientExecution(request);
return executorService.submit(new java.util.concurrent.Callable() {
@Override
public DeleteKeyspaceResult call() throws Exception {
DeleteKeyspaceResult result = null;
try {
result = executeDeleteKeyspace(finalRequest);
} catch (Exception ex) {
if (asyncHandler != null) {
asyncHandler.onError(ex);
}
throw ex;
}
if (asyncHandler != null) {
asyncHandler.onSuccess(finalRequest, result);
}
return result;
}
});
}
@Override
public java.util.concurrent.Future deleteTableAsync(DeleteTableRequest request) {
return deleteTableAsync(request, null);
}
@Override
public java.util.concurrent.Future deleteTableAsync(final DeleteTableRequest request,
final com.amazonaws.handlers.AsyncHandler asyncHandler) {
final DeleteTableRequest finalRequest = beforeClientExecution(request);
return executorService.submit(new java.util.concurrent.Callable() {
@Override
public DeleteTableResult call() throws Exception {
DeleteTableResult result = null;
try {
result = executeDeleteTable(finalRequest);
} catch (Exception ex) {
if (asyncHandler != null) {
asyncHandler.onError(ex);
}
throw ex;
}
if (asyncHandler != null) {
asyncHandler.onSuccess(finalRequest, result);
}
return result;
}
});
}
@Override
public java.util.concurrent.Future getKeyspaceAsync(GetKeyspaceRequest request) {
return getKeyspaceAsync(request, null);
}
@Override
public java.util.concurrent.Future getKeyspaceAsync(final GetKeyspaceRequest request,
final com.amazonaws.handlers.AsyncHandler asyncHandler) {
final GetKeyspaceRequest finalRequest = beforeClientExecution(request);
return executorService.submit(new java.util.concurrent.Callable() {
@Override
public GetKeyspaceResult call() throws Exception {
GetKeyspaceResult result = null;
try {
result = executeGetKeyspace(finalRequest);
} catch (Exception ex) {
if (asyncHandler != null) {
asyncHandler.onError(ex);
}
throw ex;
}
if (asyncHandler != null) {
asyncHandler.onSuccess(finalRequest, result);
}
return result;
}
});
}
@Override
public java.util.concurrent.Future getTableAsync(GetTableRequest request) {
return getTableAsync(request, null);
}
@Override
public java.util.concurrent.Future getTableAsync(final GetTableRequest request,
final com.amazonaws.handlers.AsyncHandler asyncHandler) {
final GetTableRequest finalRequest = beforeClientExecution(request);
return executorService.submit(new java.util.concurrent.Callable() {
@Override
public GetTableResult call() throws Exception {
GetTableResult result = null;
try {
result = executeGetTable(finalRequest);
} catch (Exception ex) {
if (asyncHandler != null) {
asyncHandler.onError(ex);
}
throw ex;
}
if (asyncHandler != null) {
asyncHandler.onSuccess(finalRequest, result);
}
return result;
}
});
}
@Override
public java.util.concurrent.Future getTableAutoScalingSettingsAsync(GetTableAutoScalingSettingsRequest request) {
return getTableAutoScalingSettingsAsync(request, null);
}
@Override
public java.util.concurrent.Future getTableAutoScalingSettingsAsync(final GetTableAutoScalingSettingsRequest request,
final com.amazonaws.handlers.AsyncHandler asyncHandler) {
final GetTableAutoScalingSettingsRequest finalRequest = beforeClientExecution(request);
return executorService.submit(new java.util.concurrent.Callable() {
@Override
public GetTableAutoScalingSettingsResult call() throws Exception {
GetTableAutoScalingSettingsResult result = null;
try {
result = executeGetTableAutoScalingSettings(finalRequest);
} catch (Exception ex) {
if (asyncHandler != null) {
asyncHandler.onError(ex);
}
throw ex;
}
if (asyncHandler != null) {
asyncHandler.onSuccess(finalRequest, result);
}
return result;
}
});
}
@Override
public java.util.concurrent.Future listKeyspacesAsync(ListKeyspacesRequest request) {
return listKeyspacesAsync(request, null);
}
@Override
public java.util.concurrent.Future listKeyspacesAsync(final ListKeyspacesRequest request,
final com.amazonaws.handlers.AsyncHandler asyncHandler) {
final ListKeyspacesRequest finalRequest = beforeClientExecution(request);
return executorService.submit(new java.util.concurrent.Callable() {
@Override
public ListKeyspacesResult call() throws Exception {
ListKeyspacesResult result = null;
try {
result = executeListKeyspaces(finalRequest);
} catch (Exception ex) {
if (asyncHandler != null) {
asyncHandler.onError(ex);
}
throw ex;
}
if (asyncHandler != null) {
asyncHandler.onSuccess(finalRequest, result);
}
return result;
}
});
}
@Override
public java.util.concurrent.Future listTablesAsync(ListTablesRequest request) {
return listTablesAsync(request, null);
}
@Override
public java.util.concurrent.Future listTablesAsync(final ListTablesRequest request,
final com.amazonaws.handlers.AsyncHandler asyncHandler) {
final ListTablesRequest finalRequest = beforeClientExecution(request);
return executorService.submit(new java.util.concurrent.Callable() {
@Override
public ListTablesResult call() throws Exception {
ListTablesResult result = null;
try {
result = executeListTables(finalRequest);
} catch (Exception ex) {
if (asyncHandler != null) {
asyncHandler.onError(ex);
}
throw ex;
}
if (asyncHandler != null) {
asyncHandler.onSuccess(finalRequest, result);
}
return result;
}
});
}
@Override
public java.util.concurrent.Future listTagsForResourceAsync(ListTagsForResourceRequest request) {
return listTagsForResourceAsync(request, null);
}
@Override
public java.util.concurrent.Future listTagsForResourceAsync(final ListTagsForResourceRequest request,
final com.amazonaws.handlers.AsyncHandler asyncHandler) {
final ListTagsForResourceRequest finalRequest = beforeClientExecution(request);
return executorService.submit(new java.util.concurrent.Callable() {
@Override
public ListTagsForResourceResult call() throws Exception {
ListTagsForResourceResult result = null;
try {
result = executeListTagsForResource(finalRequest);
} catch (Exception ex) {
if (asyncHandler != null) {
asyncHandler.onError(ex);
}
throw ex;
}
if (asyncHandler != null) {
asyncHandler.onSuccess(finalRequest, result);
}
return result;
}
});
}
@Override
public java.util.concurrent.Future restoreTableAsync(RestoreTableRequest request) {
return restoreTableAsync(request, null);
}
@Override
public java.util.concurrent.Future restoreTableAsync(final RestoreTableRequest request,
final com.amazonaws.handlers.AsyncHandler asyncHandler) {
final RestoreTableRequest finalRequest = beforeClientExecution(request);
return executorService.submit(new java.util.concurrent.Callable() {
@Override
public RestoreTableResult call() throws Exception {
RestoreTableResult result = null;
try {
result = executeRestoreTable(finalRequest);
} catch (Exception ex) {
if (asyncHandler != null) {
asyncHandler.onError(ex);
}
throw ex;
}
if (asyncHandler != null) {
asyncHandler.onSuccess(finalRequest, result);
}
return result;
}
});
}
@Override
public java.util.concurrent.Future tagResourceAsync(TagResourceRequest request) {
return tagResourceAsync(request, null);
}
@Override
public java.util.concurrent.Future tagResourceAsync(final TagResourceRequest request,
final com.amazonaws.handlers.AsyncHandler asyncHandler) {
final TagResourceRequest finalRequest = beforeClientExecution(request);
return executorService.submit(new java.util.concurrent.Callable() {
@Override
public TagResourceResult call() throws Exception {
TagResourceResult result = null;
try {
result = executeTagResource(finalRequest);
} catch (Exception ex) {
if (asyncHandler != null) {
asyncHandler.onError(ex);
}
throw ex;
}
if (asyncHandler != null) {
asyncHandler.onSuccess(finalRequest, result);
}
return result;
}
});
}
@Override
public java.util.concurrent.Future untagResourceAsync(UntagResourceRequest request) {
return untagResourceAsync(request, null);
}
@Override
public java.util.concurrent.Future untagResourceAsync(final UntagResourceRequest request,
final com.amazonaws.handlers.AsyncHandler asyncHandler) {
final UntagResourceRequest finalRequest = beforeClientExecution(request);
return executorService.submit(new java.util.concurrent.Callable() {
@Override
public UntagResourceResult call() throws Exception {
UntagResourceResult result = null;
try {
result = executeUntagResource(finalRequest);
} catch (Exception ex) {
if (asyncHandler != null) {
asyncHandler.onError(ex);
}
throw ex;
}
if (asyncHandler != null) {
asyncHandler.onSuccess(finalRequest, result);
}
return result;
}
});
}
@Override
public java.util.concurrent.Future updateTableAsync(UpdateTableRequest request) {
return updateTableAsync(request, null);
}
@Override
public java.util.concurrent.Future updateTableAsync(final UpdateTableRequest request,
final com.amazonaws.handlers.AsyncHandler asyncHandler) {
final UpdateTableRequest finalRequest = beforeClientExecution(request);
return executorService.submit(new java.util.concurrent.Callable() {
@Override
public UpdateTableResult call() throws Exception {
UpdateTableResult result = null;
try {
result = executeUpdateTable(finalRequest);
} catch (Exception ex) {
if (asyncHandler != null) {
asyncHandler.onError(ex);
}
throw ex;
}
if (asyncHandler != null) {
asyncHandler.onSuccess(finalRequest, result);
}
return result;
}
});
}
/**
* Shuts down the client, releasing all managed resources. This includes forcibly terminating all pending
* asynchronous service calls. Clients who wish to give pending asynchronous service calls time to complete should
* call {@code getExecutorService().shutdown()} followed by {@code getExecutorService().awaitTermination()} prior to
* calling this method.
*/
@Override
public void shutdown() {
super.shutdown();
executorService.shutdownNow();
}
}