/* * Copyright 2010-2019 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.sagemakerruntime; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import com.amazonaws.AmazonClientException; import com.amazonaws.AmazonServiceException; import com.amazonaws.handlers.AsyncHandler; import com.amazonaws.ClientConfiguration; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; import com.amazonaws.services.sagemakerruntime.model.*; /** * Interface for accessing Amazon SageMaker Runtime Service asynchronously. *
* The Amazon SageMaker runtime API. *
**/ public class AmazonSageMakerRuntimeAsyncClient extends AmazonSageMakerRuntimeClient implements AmazonSageMakerRuntimeAsync { /** * Executor service for executing asynchronous requests. */ private ExecutorService executorService; private static final int DEFAULT_THREAD_POOL_SIZE = 10; /** * Constructs a new asynchronous client to invoke service methods on Amazon * SageMaker Runtime Service. A credentials provider chain will be used that * searches for credentials in this order: ** All service calls made using this new client object are blocking, and * will not return until the service call completes. * * @see DefaultAWSCredentialsProviderChain */ @Deprecated public AmazonSageMakerRuntimeAsyncClient() { this(new DefaultAWSCredentialsProviderChain()); } /** * Constructs a new asynchronous client to invoke service methods on Amazon * SageMaker Runtime Service. A credentials provider chain will be used that * searches for credentials in this order: *
* All service calls made using this new client object are blocking, and * will not return until the service call completes. * * @param clientConfiguration The client configuration options controlling * how this client connects to Amazon SageMaker Runtime Service * (ex: proxy settings, retry counts, etc.). * @see DefaultAWSCredentialsProviderChain */ @Deprecated public AmazonSageMakerRuntimeAsyncClient(ClientConfiguration clientConfiguration) { this(new DefaultAWSCredentialsProviderChain(), clientConfiguration, Executors .newFixedThreadPool(clientConfiguration.getMaxConnections())); } /** * Constructs a new asynchronous client to invoke service methods on Amazon * SageMaker Runtime Service using the specified AWS account credentials. * Default client settings will be used, and a fixed size thread pool will * be created for executing the asynchronous tasks. *
* All calls made using this new client object are non-blocking, and will * immediately return a Java Future object that the caller can later check * to see if the service call has actually completed. * * @param awsCredentials The AWS credentials (access key ID and secret key) * to use when authenticating with AWS services. */ public AmazonSageMakerRuntimeAsyncClient(AWSCredentials awsCredentials) { this(awsCredentials, Executors.newFixedThreadPool(DEFAULT_THREAD_POOL_SIZE)); } /** * Constructs a new asynchronous client to invoke service methods on Amazon * SageMaker Runtime Service using the specified AWS account credentials and * executor service. Default client settings will be used. *
* All calls made using this new client object are non-blocking, and will * immediately return a Java Future object that the caller can later check * to see if the service call has actually completed. * * @param awsCredentials The AWS credentials (access key ID and secret key) * to use when authenticating with AWS services. * @param executorService The executor service by which all asynchronous * requests will be executed. */ public AmazonSageMakerRuntimeAsyncClient(AWSCredentials awsCredentials, ExecutorService executorService) { super(awsCredentials); this.executorService = executorService; } /** * Constructs a new asynchronous client to invoke service methods on Amazon * SageMaker Runtime Service using the specified AWS account credentials, * executor service, and client configuration options. *
* All calls made using this new client object are non-blocking, and will * immediately return a Java Future object that the caller can later check * to see if the service call has actually completed. * * @param awsCredentials The AWS credentials (access key ID and secret key) * to use when authenticating with AWS services. * @param clientConfiguration Client configuration options (ex: max retry * limit, proxy settings, etc). * @param executorService The executor service by which all asynchronous * requests will be executed. */ public AmazonSageMakerRuntimeAsyncClient(AWSCredentials awsCredentials, ClientConfiguration clientConfiguration, ExecutorService executorService) { super(awsCredentials, clientConfiguration); this.executorService = executorService; } /** * Constructs a new asynchronous client to invoke service methods on Amazon * SageMaker Runtime Service using the specified AWS account credentials * provider. Default client settings will be used, and a fixed size thread * pool will be created for executing the asynchronous tasks. *
* All calls made using this new client object are non-blocking, and will * immediately return a Java Future object that the caller can later check * to see if the service call has actually completed. * * @param awsCredentialsProvider The AWS credentials provider which will * provide credentials to authenticate requests with AWS * services. */ public AmazonSageMakerRuntimeAsyncClient(AWSCredentialsProvider awsCredentialsProvider) { this(awsCredentialsProvider, Executors.newFixedThreadPool(DEFAULT_THREAD_POOL_SIZE)); } /** * Constructs a new asynchronous client to invoke service methods on Amazon * SageMaker Runtime Service using the specified AWS account credentials * provider and executor service. Default client settings will be used. *
* All calls made using this new client object are non-blocking, and will * immediately return a Java Future object that the caller can later check * to see if the service call has actually completed. * * @param awsCredentialsProvider The AWS credentials provider which will * provide credentials to authenticate requests with AWS * services. * @param executorService The executor service by which all asynchronous * requests will be executed. */ public AmazonSageMakerRuntimeAsyncClient(AWSCredentialsProvider awsCredentialsProvider, ExecutorService executorService) { this(awsCredentialsProvider, new ClientConfiguration(), executorService); } /** * Constructs a new asynchronous client to invoke service methods on Amazon * SageMaker Runtime Service using the specified AWS account credentials * provider and client configuration options. *
* All calls made using this new client object are non-blocking, and will * immediately return a Java Future object that the caller can later check * to see if the service call has actually completed. * * @param awsCredentialsProvider The AWS credentials provider which will * provide credentials to authenticate requests with AWS * services. * @param clientConfiguration Client configuration options (ex: max retry * limit, proxy settings, etc). */ public AmazonSageMakerRuntimeAsyncClient(AWSCredentialsProvider awsCredentialsProvider, ClientConfiguration clientConfiguration) { this(awsCredentialsProvider, clientConfiguration, Executors .newFixedThreadPool(clientConfiguration.getMaxConnections())); } /** * Constructs a new asynchronous client to invoke service methods on Amazon * SageMaker Runtime Service using the specified AWS account credentials * provider, executor service, and client configuration options. *
* All calls made using this new client object are non-blocking, and will * immediately return a Java Future object that the caller can later check * to see if the service call has actually completed. * * @param awsCredentialsProvider The AWS credentials provider which will * provide credentials to authenticate requests with AWS * services. * @param clientConfiguration Client configuration options (ex: max retry * limit, proxy settings, etc). * @param executorService The executor service by which all asynchronous * requests will be executed. */ public AmazonSageMakerRuntimeAsyncClient(AWSCredentialsProvider awsCredentialsProvider, ClientConfiguration clientConfiguration, ExecutorService executorService) { super(awsCredentialsProvider, clientConfiguration); this.executorService = executorService; } /** * Returns the executor service used by this async client to execute * requests. * * @return The executor service used by this async client to execute * requests. */ public ExecutorService getExecutorService() { return executorService; } /** * 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 getExecutorService().shutdown() followed by * getExecutorService().awaitTermination() prior to calling this method. */ @Override public void shutdown() { super.shutdown(); executorService.shutdownNow(); } /** *
* After you deploy a model into production using Amazon SageMaker hosting * services, your client applications use this API to get inferences from * the model hosted at the specified endpoint. *
** For an overview of Amazon SageMaker, see How It Works. *
** Amazon SageMaker strips all POST headers except those supported by the * API. Amazon SageMaker might add additional headers. You should not rely * on the behavior of headers outside those enumerated in the request * syntax. *
*
* Cals to InvokeEndpoint
are authenticated by using AWS
* Signature Version 4. For information, see Authenticating Requests (AWS Signature Version 4) in the Amazon
* S3 API Reference.
*
* Endpoints are scoped to an individual account, and are not public. The * URL does not contain the account ID, but Amazon SageMaker determines the * account ID from the authentication token that is supplied by the caller. *
** After you deploy a model into production using Amazon SageMaker hosting * services, your client applications use this API to get inferences from * the model hosted at the specified endpoint. *
** For an overview of Amazon SageMaker, see How It Works. *
** Amazon SageMaker strips all POST headers except those supported by the * API. Amazon SageMaker might add additional headers. You should not rely * on the behavior of headers outside those enumerated in the request * syntax. *
*
* Cals to InvokeEndpoint
are authenticated by using AWS
* Signature Version 4. For information, see Authenticating Requests (AWS Signature Version 4) in the Amazon
* S3 API Reference.
*
* Endpoints are scoped to an individual account, and are not public. The * URL does not contain the account ID, but Amazon SageMaker determines the * account ID from the authentication token that is supplied by the caller. *
*