Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 080742f

Browse files
committed
Edit pass for older topics
1 parent 2a69776 commit 080742f

12 files changed

Lines changed: 345 additions & 270 deletions

‎doc_source/basics-async.rst‎

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,35 @@
1212
Asynchronous Programming
1313
########################
1414

15+
.. meta::
16+
:description: How asynchronous programming works in the AWS SDK for Java and best practices for handling
17+
exceptions
18+
:keywords:
19+
1520
You can use either *synchronous* or *asynchronous* methods to call operations on AWS services.
1621
Synchronous methods block your thread's execution until the client receives a response from the
1722
service. Asynchronous methods return immediately, giving control back to the calling thread without
1823
waiting for a response.
1924

20-
Since an asynchronous method returns before a response is available, you need a way to get the
21-
response when it's ready. The |sdk-java| provides two methods: *Futures* and *callback methods*.
25+
Because an asynchronous method returns before a response is available, you need a way to get the
26+
response when it's ready. The |sdk-java| provides two ways: *Future objects* and *callback methods*.
2227

2328
.. _basics-async-future:
2429

2530
Java Futures
2631
============
2732

2833
Asynchronous methods in the |sdk-java| return a :javase-ref:`Future <java/util/concurrent/Future>`
29-
object that will contain the results of the asynchronous operation *in the future*.
34+
object that contains the results of the asynchronous operation *in the future*.
3035

31-
Call the Future's :methodname:`isDone()` method to see if the service has provided a response object
32-
yet. Once the response is ready, you can get the response object by calling the Future's
36+
Call the :code-java:`Future` :methodname:`isDone()` method to see if the service has provided a response
37+
object yet. When the response is ready, you can get the response object by calling the :code-java:`Future`
3338
:methodname:`get()` method. You can use this mechanism to periodically poll for the asynchronous
3439
operation's results while your application continues to work on other things.
3540

36-
Here is an example of an asynchronous operation that calls a |LAM| function, receiving a Future that
41+
Here is an example of an asynchronous operation that calls a |LAM| function, receiving a :code-java:`Future` that
3742
can hold an :aws-java-class:`InvokeResult <services/lambda/model/InvokeResult>` object. The
38-
:classname:`InvokeResult` object is retrieved only after :methodname:`isDone()` is ``true``:
43+
:classname:`InvokeResult` object is retrieved only after :methodname:`isDone()` is ``true``.
3944

4045
.. literalinclude:: snippets/lambda_invoke_example/src/main/java/example/lambda/InvokeLambdaFunctionAsync.java
4146
:language: java
@@ -46,13 +51,13 @@ can hold an :aws-java-class:`InvokeResult <services/lambda/model/InvokeResult>`
4651
Asynchronous Callbacks
4752
======================
4853

49-
In addition to using Java Futures to monitor the status of asynchronous requests, the SDK also
50-
allows you to implement a class that uses the :aws-java-class:`AsyncHandler <handlers/AsyncHandler>`
51-
interface, which provides two methods that are called depending on how the request completed:
54+
In addition to using the Java :code-java:`Future` object to monitor the status of asynchronous requests,
55+
the SDK also enables you to implement a class that uses the :aws-java-class:`AsyncHandler <handlers/AsyncHandler>`
56+
interface. :code-java:`AsyncHandler` provides two methods that are called depending on how the request completed:
5257
:methodname:`onSuccess` and :methodname:`onError`.
5358

5459
The major advantage of the callback interface approach is that it frees you from having to poll the
55-
Future object to find out when the request has completed. Instead, your code can immediately start
60+
:code-java:`Future` object to find out when the request has completed. Instead, your code can immediately start
5661
its next activity, and rely on the SDK to call your handler at the right time.
5762

5863
.. literalinclude:: snippets/lambda_invoke_example/src/main/java/example/lambda/InvokeLambdaFunctionCallback.java
@@ -71,30 +76,31 @@ Callback Execution
7176
Your implementation of :classname:`AsyncHandler` is executed inside the thread pool owned by the
7277
asynchronous client. Short, quickly executed code is most appropriate inside your
7378
:classname:`AsyncHandler` implementation. Long-running or blocking code inside your handler methods
74-
can cause contention for the thread pool used by the asynchronous client and can prevent the client
75-
from being able to execute requests. If you have a long-running task that needs to begin from a
79+
can cause contention for the thread pool used by the asynchronous client, and can prevent the client
80+
from executing requests. If you have a long-running task that needs to begin from a
7681
callback, have the callback run its task in a new thread or in a thread pool managed by your
7782
application.
7883

7984

8085
Thread Pool Configuration
8186
-------------------------
8287

83-
The asynchronous clients in the SDK provide a default thread pool that should work for most
84-
applications. You can implement a custom :javase-ref:`ExecutorService
85-
<java/util/concurrent/ExecutorService>` and pass it to |sdk-java| asynchronous clients if you want
88+
The asynchronous clients in the |sdk-java| provide a default thread pool that should work for most
89+
applications. You can implement a custom
90+
:javase-ref:`ExecutorService <java/util/concurrent/ExecutorService>` and pass it to
91+
|sdk-java| asynchronous clients for
8692
more control over how the thread pools are managed.
8793

88-
For example, you could provide a :classname:`ExecutorService` implementation that uses a custom
94+
For example, you could provide an :classname:`ExecutorService` implementation that uses a custom
8995
:javase-ref:`ThreadFactory <java/util/concurrent/ThreadFactory>` to control how threads in the pool
9096
are named, or to log additional information about thread usage.
9197

9298

93-
Amazon S3 Asynchronous Access
99+
|S3| Asynchronous Access
94100
-----------------------------
95101

96102
The :aws-java-class:`TransferManager <amazonaws/services/s3/transfer/TransferManager>` class in the SDK
97-
offers asynchronous support for working with the |S3long| (|S3|). :classname:`TransferManager`
103+
offers asynchronous support for working with the |S3|. :classname:`TransferManager`
98104
manages asynchronous uploads and downloads, provides detailed progress reporting on transfers, and
99105
supports callbacks into different events.
100106

‎doc_source/basics.rst‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88
either express or implied. See the License for the specific language governing permissions and
99
limitations under the License.
1010
11-
#############
12-
Using the SDK
13-
#############
11+
####################
12+
Using the |sdk-java|
13+
####################
1414

15-
This section provides important general information about programming with the |sdk-java|.
16-
Information in this section applies to all services that you might be using with the |sdk-java|.
15+
.. meta::
16+
:description: Programming information for the AWS SDK for Java
17+
:keywords:
1718

18-
For information that is specific to a particular service (EC2, SWF, etc.), see the
19-
:doc:`prog-services` section.
19+
This section provides important general information about programming with the |sdk-java| that applies
20+
to all services you might use with the SDK.
21+
22+
For service-specific programming information and examples (for |EC2|, |S3|, SWF|, etc.), see
23+
:doc:`prog-services`.
2024

2125
.. toctree::
2226
:maxdepth: 1

‎doc_source/best-practices.rst‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
Best Practices for AWS Development with the |sdk-java|
1313
######################################################
1414

15-
Avoid trouble when developing your AWS applications with the |sdk-java|. Best practices are divided
16-
by service.
15+
.. meta::
16+
:description: AWS coding best practices using the AWS SDK for Java.
17+
:keywords:
18+
19+
The following best practices can help you avoid issues or trouble as you develop AWS applications
20+
with the |sdk-java|. We've organized best practices by service.
1721

1822
.. best-practices-s3:
1923
@@ -25,23 +29,24 @@ by service.
2529
Avoid ResetExceptions
2630
---------------------
2731

28-
You might encounter network connectivity or timeout issues when uploading objects to |s3| using
29-
streams (either through an |s3client| client or |xfermgr|). By default, the |sdk-java| attempts
30-
to retry failed transfers by marking the input stream before the start of a transfer and then
31-
resetting it before retrying.
32+
When you upload objects to |s3| by using
33+
streams (either through an |s3client| client or |xfermgr|), you might encounter network
34+
connectivity or timeout issues. By default, the |sdk-java| attempts to retry failed transfers by marking
35+
the input stream before
36+
the start of a transfer and then resetting it before retrying.
3237

33-
If the stream doesn't support mark and reset, the SDK will throw a :aws-java-class:`ResetException`
38+
If the stream doesn't support mark and reset, the SDK throws a :aws-java-class:`ResetException`
3439
when there are transient failures and retries are enabled.
3540

3641
**Best Practice**
3742

3843
We recommend that you use streams that support mark and reset operations.
3944

40-
The most reliable way to avoid :aws-java-class:`ResetException` is to provide data using a
45+
The most reliable way to avoid a :aws-java-class:`ResetException` is to provide data by using a
4146
:javase-ref:`File <java/io/File>` or :javase-ref:`FileInputStream <java/io/FileInputStream>`, which
4247
the |sdk-java| can handle without being constrained by mark and reset limits.
4348

44-
If the stream isn't a :javase-ref:`FileInputStream <java/io/FileInputStream>` but supports mark and
49+
If the stream isn't a :javase-ref:`FileInputStream <java/io/FileInputStream>` but does support mark and
4550
reset, you can set the mark limit by using the :methodname:`setReadLimit` method of
4651
:aws-java-class:`RequestClientOptions`. Its default value is 128 KB. Setting the read limit value to
4752
*one byte greater than the size of stream* will reliably avoid a :aws-java-class:`ResetException`.

‎doc_source/creating-clients.rst‎

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,35 @@
1212
Creating Service Clients
1313
########################
1414

15-
To make requests to |AWSlong|, you first create a service client object. The preferred way to do
16-
this is to use the service client builder. Each AWS service has a service interface that has methods
15+
.. meta::
16+
:description: How to create service clients by using the AWS SDK for Java.
17+
:keywords:
18+
19+
To make requests to |AWSlong|, you first create a service client object. The recommended
20+
way is
21+
to use the service client builder.
22+
23+
Each AWS service has a service interface with methods
1724
for each action in the service API. For example, the service interface for |DDBlong| is named
1825
:aws-java-class:`AmazonDynamoDB <services/dynamodbv2/AmazonDynamoDB>`. Each service interface has a
1926
corresponding client builder you can use to construct an implementation of the service interface.
2027
The client builder class for |DDB| is named :aws-java-class:`AmazonDynamoDBClientBuilder
2128
<services/dynamodbv2/AmazonDynamoDBClientBuilder>`.
2229

23-
To obtain an instance of the client builder, use the static factory method ``standard``, as shown in
24-
the following example.
30+
Obtaining a Client Builder
31+
==========================
32+
33+
To obtain an instance of the client builder, use the static factory method ``standard``,
34+
as shown in the following example.
2535

2636
.. code-block:: java
2737
2838
AmazonDynamoDBClientBuilder builder = AmazonDynamoDBClientBuilder.standard();
2939
3040
31-
Once you obtain a builder, you can customize properties of the client by using many fluent setters
32-
in the builder API. For example, you can set a custom region and a custom credentials provider as
41+
Once you have a builder, you can customize the client's properties by using many fluent
42+
setters
43+
in the builder API. For example, you can set a custom region and a custom credentials provider, as
3344
follows.
3445

3546
.. code-block:: java
@@ -39,14 +50,16 @@ follows.
3950
.withCredentials(new ProfileCredentialsProvider("myProfile"))
4051
.build();
4152
42-
.. note:: The fluent withXXX methods return the ``builder`` object so that you can chain the method
43-
calls for convenience and more readable code. After you configure all the properties you want,
44-
you can call the ``build`` method to create the client. Once a client is created, it is immutable
53+
.. note:: The fluent ``withXXX`` methods return the ``builder`` object so that you can chain the
54+
method calls for convenience and for more readable code. After you configure the properties you
55+
want,
56+
you can call the ``build`` method to create the client. Once a client is created, it's immutable
4557
and any calls to ``setRegion`` or ``setEndpoint`` will fail.
4658

4759
A builder can create multiple clients with the same configuration. When you're writing your
48-
application, be aware that the builder is mutable and not thread-safe. The following code uses the
49-
builder as a factory for client instances.
60+
application, be aware that the builder is mutable and not thread-safe.
61+
62+
The following code uses the builder as a factory for client instances.
5063

5164
.. code-block:: java
5265
@@ -61,8 +74,8 @@ builder as a factory for client instances.
6174
}
6275
}
6376
64-
The builder also exposes fluent setters for :aws-java-class:`ClientConfiguration <ClientConfiguration>`',
65-
:aws-java-class:`RequestMetricCollector <metrics/RequestMetricCollector>`, and a custom list of
77+
The builder also exposes fluent setters for :aws-java-class:`ClientConfiguration <ClientConfiguration>`'
78+
and :aws-java-class:`RequestMetricCollector <metrics/RequestMetricCollector>`, and a custom list of
6679
:aws-java-class:`RequestHandler2 <handlers/RequestHandler2>`.
6780

6881
The following is a complete example that overrides all configurable properties.
@@ -79,8 +92,8 @@ The following is a complete example that overrides all configurable properties.
7992
8093
Creating Async Clients
8194
======================
82-
The |sdk-java| also has asynchronous (or async) clients for every service, except for |S3long|. There is also a corresponding async
83-
client builder for every service.
95+
The |sdk-java| has asynchronous (or async) clients for every service (except for |S3|), and a corresponding
96+
async client builder for every service.
8497
8598
.. topic:: To create an async |DDB| client with the default ExecutorService
8699
@@ -91,8 +104,8 @@ client builder for every service.
91104
.withCredentials(new ProfileCredentialsProvider("myProfile"))
92105
.build();
93106
94-
In addition to the configuration options that the synchronous (or sync) client builder supports, the
95-
async client allows you to set a custom :aws-java-class:`ExecutorFactory <client/builder/ExecutorFactory>`
107+
In addition to the configuration options that the synchronous (or sync) client builder supports,
108+
the async client enables you to set a custom :aws-java-class:`ExecutorFactory <client/builder/ExecutorFactory>`
96109
to change the :classname:`ExecutorService` that the async client uses. :classname:`ExecutorFactory`
97110
is a functional interface, so it interoperates with Java 8 lambda expressions and method references.
98111
@@ -105,15 +118,15 @@ is a functional interface, so it interoperates with Java 8 lambda expressions an
105118
.build();
106119
107120
108-
Default Client
109-
==============
121+
Using DefaultClient
122+
===================
110123
111-
Both the sync and async client builders have another factory method called
124+
Both the sync and async client builders have another factory method named
112125
:methodname:`defaultClient`. This method creates a service client with the default configuration,
113-
using the default provider chain to load credentials and the AWS region. If either credentials or
114-
the region cannot be determined from the environment that the application is running in, the call to
115-
:methodname:`defaultClient` will fail. See :doc:`credentials` and :doc:`java-dg-region-selection`
116-
for more information on how credentials and region are determined.
126+
using the default provider chain to load credentials and the AWS Region. If credentials or
127+
the region can't be determined from the environment that the application is running in, the call to
128+
:methodname:`defaultClient` fails. See :doc:`credentials` and :doc:`java-dg-region-selection`
129+
for more information about how credentials and region are determined.
117130
118131
.. topic:: To create a default service client
119132
@@ -127,7 +140,7 @@ Client Lifecycle
127140
128141
Service clients in the SDK are thread-safe and, for best performance, you should treat them as
129142
long-lived objects. Each client has its own connection pool resource that is shut down when the
130-
client is garbage collected. To explicitly shut down a client, you can call the
143+
client is garbage collected. To explicitly shut down a client, call the
131144
:methodname:`shutdown` method. After calling :methodname:`shutdown`, all client resources are
132145
released and the client is unusable.
133146

0 commit comments

Comments
 (0)