/* * Copyright 2018-2023 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.augmentedairuntime; import javax.annotation.Generated; import com.amazonaws.services.augmentedairuntime.model.*; import com.amazonaws.client.AwsAsyncClientParams; import com.amazonaws.annotation.ThreadSafe; import java.util.concurrent.ExecutorService; /** * Client for accessing Amazon Augmented AI Runtime 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 Augmented AI (Amazon A2I) adds the benefit of human judgment to any machine learning application. When an AI * application can't evaluate data with a high degree of confidence, human reviewers can take over. This human review is * called a human review workflow. To create and start a human review workflow, you need three resources: a worker * task template, a flow definition, and a human loop. *

*

* For information about these resources and prerequisites for using Amazon A2I, see Get Started with Amazon Augmented * AI in the Amazon SageMaker Developer Guide. *

*

* This API reference includes information about API actions and data types that you can use to interact with Amazon A2I * programmatically. Use this guide to: *

* *

* Amazon A2I integrates APIs from various AWS services to create and start human review workflows for those services. * To learn how Amazon A2I uses these APIs, see Use APIs in Amazon A2I in the * Amazon SageMaker Developer Guide. *

*/ @ThreadSafe @Generated("com.amazonaws:aws-java-sdk-code-generator") public class AmazonAugmentedAIRuntimeAsyncClient extends AmazonAugmentedAIRuntimeClient implements AmazonAugmentedAIRuntimeAsync { private static final int DEFAULT_THREAD_POOL_SIZE = 50; private final java.util.concurrent.ExecutorService executorService; public static AmazonAugmentedAIRuntimeAsyncClientBuilder asyncBuilder() { return AmazonAugmentedAIRuntimeAsyncClientBuilder.standard(); } /** * Constructs a new asynchronous client to invoke service methods on Amazon Augmented AI Runtime using the specified * parameters. * * @param asyncClientParams * Object providing client parameters. */ AmazonAugmentedAIRuntimeAsyncClient(AwsAsyncClientParams asyncClientParams) { this(asyncClientParams, false); } /** * Constructs a new asynchronous client to invoke service methods on Amazon Augmented AI Runtime using the specified * parameters. * * @param asyncClientParams * Object providing client parameters. * @param endpointDiscoveryEnabled * true will enable endpoint discovery if the service supports it. */ AmazonAugmentedAIRuntimeAsyncClient(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 deleteHumanLoopAsync(DeleteHumanLoopRequest request) { return deleteHumanLoopAsync(request, null); } @Override public java.util.concurrent.Future deleteHumanLoopAsync(final DeleteHumanLoopRequest request, final com.amazonaws.handlers.AsyncHandler asyncHandler) { final DeleteHumanLoopRequest finalRequest = beforeClientExecution(request); return executorService.submit(new java.util.concurrent.Callable() { @Override public DeleteHumanLoopResult call() throws Exception { DeleteHumanLoopResult result = null; try { result = executeDeleteHumanLoop(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 describeHumanLoopAsync(DescribeHumanLoopRequest request) { return describeHumanLoopAsync(request, null); } @Override public java.util.concurrent.Future describeHumanLoopAsync(final DescribeHumanLoopRequest request, final com.amazonaws.handlers.AsyncHandler asyncHandler) { final DescribeHumanLoopRequest finalRequest = beforeClientExecution(request); return executorService.submit(new java.util.concurrent.Callable() { @Override public DescribeHumanLoopResult call() throws Exception { DescribeHumanLoopResult result = null; try { result = executeDescribeHumanLoop(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 listHumanLoopsAsync(ListHumanLoopsRequest request) { return listHumanLoopsAsync(request, null); } @Override public java.util.concurrent.Future listHumanLoopsAsync(final ListHumanLoopsRequest request, final com.amazonaws.handlers.AsyncHandler asyncHandler) { final ListHumanLoopsRequest finalRequest = beforeClientExecution(request); return executorService.submit(new java.util.concurrent.Callable() { @Override public ListHumanLoopsResult call() throws Exception { ListHumanLoopsResult result = null; try { result = executeListHumanLoops(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 startHumanLoopAsync(StartHumanLoopRequest request) { return startHumanLoopAsync(request, null); } @Override public java.util.concurrent.Future startHumanLoopAsync(final StartHumanLoopRequest request, final com.amazonaws.handlers.AsyncHandler asyncHandler) { final StartHumanLoopRequest finalRequest = beforeClientExecution(request); return executorService.submit(new java.util.concurrent.Callable() { @Override public StartHumanLoopResult call() throws Exception { StartHumanLoopResult result = null; try { result = executeStartHumanLoop(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 stopHumanLoopAsync(StopHumanLoopRequest request) { return stopHumanLoopAsync(request, null); } @Override public java.util.concurrent.Future stopHumanLoopAsync(final StopHumanLoopRequest request, final com.amazonaws.handlers.AsyncHandler asyncHandler) { final StopHumanLoopRequest finalRequest = beforeClientExecution(request); return executorService.submit(new java.util.concurrent.Callable() { @Override public StopHumanLoopResult call() throws Exception { StopHumanLoopResult result = null; try { result = executeStopHumanLoop(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(); } }