Skip to content

Commit 25442d1

Browse files
authored
Merge pull request #1495 from scmacdon/master
Update Java V2 examples
2 parents 82cb31b + 211b488 commit 25442d1

31 files changed

+2282
-2307
lines changed

javav2/example_code/swf/src/main/java/com/example/helloswf/ActivityWorker.java

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
//snippet-sourcedescription:[ActivityWorker.java demonstrates how to implement an activity worker that polls for tasks in a task list and executes its task.]
2-
//snippet-keyword:[SDK for Java 2.0]
2+
//snippet-keyword:[AWS SDK for Java v2]
3+
//snippet-service:[Amazon Simple Workflow Service (Amazon SWF)]
34
//snippet-keyword:[Code Sample]
4-
//snippet-service:[Amazon Simple Workflow Service]
55
//snippet-sourcetype:[full-example]
6-
//snippet-sourcedate:[8/4/2020]
6+
//snippet-sourcedate:[11/06/2020]
77
//snippet-sourceauthor:[scmacdon-aws]
88

99
/*
10-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.*
11-
* Licensed under the Apache License, Version 2.0 (the "License").
12-
* You may not use this file except in compliance with the License.
13-
* A copy of the License is located at
14-
*
15-
* http://aws.amazon.com/apache2.0
16-
*
17-
* or in the "license" file accompanying this file. This file is distributed
18-
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
19-
* express or implied. See the License for the specific language governing
20-
* permissions and limitations under the License.
21-
*/
22-
// snippet-start:[swf.java2.activity_worker.complete]
10+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
11+
SPDX-License-Identifier: Apache-2.0
12+
*/
13+
2314
package com.example.helloswf;
2415

2516
// snippet-start:[swf.java2.activity_worker.import]
@@ -39,12 +30,12 @@ public static void main(String[] args) {
3930

4031
final String USAGE = "\n" +
4132
"Usage:\n" +
42-
" HelloTypes <domain><taskList><workflow><workflowVersion><activity><activityVersion> \n\n" +
33+
" HelloTypes <domain> <taskList> \n\n" +
4334
"Where:\n" +
44-
" domain - The domain to use (i.e., mydomain) \n" +
45-
" taskList - The taskList to use (i.e., HelloTasklist) \n" ;
35+
" domain - The domain to use (for example, mydomain). \n" +
36+
" taskList - The taskList to use (for example, HelloTasklist). \n" ;
4637

47-
if (args.length < 2) {
38+
if (args.length != 2) {
4839
System.out.println(USAGE);
4940
System.exit(1);
5041
}
@@ -58,11 +49,12 @@ public static void main(String[] args) {
5849
.build();
5950

6051
getPollData(swf, domain, taskList) ;
52+
swf.close();
6153
}
6254

6355
public static void getPollData( SwfClient swf, String domain, String taskList) {
6456

65-
System.out.println("Polling for an activity task from the task list '"
57+
System.out.println("Polling for an activity task from the tasklist '"
6658
+ taskList + "' in the domain '" +
6759
domain + "'.");
6860

@@ -108,4 +100,3 @@ private static String sayHello(String input) {
108100
}
109101
}
110102
// snippet-end:[swf.java2.activity_worker.main]
111-
// snippet-end:[swf.java2.activity_worker.complete]

javav2/example_code/swf/src/main/java/com/example/helloswf/ActivityWorkerWithGracefulShutdown.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
11
//snippet-sourcedescription:[ActivityWorkerWithGracefulShutdown.java demonstrates how to implement an activity worker with a graceful shutdown.]
2-
//snippet-keyword:[SDK for Java 2.0]
2+
//snippet-keyword:[AWS SDK for Java v2]
3+
//snippet-service:[Amazon Simple Workflow Service (Amazon SWF)]
34
//snippet-keyword:[Code Sample]
4-
//snippet-service:[Amazon Simple Workflow Service]
55
//snippet-sourcetype:[full-example]
6-
//snippet-sourcedate:[8/4/2020]
6+
//snippet-sourcedate:[11/06/2020]
77
//snippet-sourceauthor:[scmacdon-aws]
88

99
/*
10-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.*
11-
* Licensed under the Apache License, Version 2.0 (the "License").
12-
* You may not use this file except in compliance with the License.
13-
* A copy of the License is located at
14-
*
15-
* http://aws.amazon.com/apache2.0
16-
*
17-
* or in the "license" file accompanying this file. This file is distributed
18-
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
19-
* express or implied. See the License for the specific language governing
20-
* permissions and limitations under the License.
21-
*/
10+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
11+
SPDX-License-Identifier: Apache-2.0
12+
*/
13+
2214
// snippet-start:[swf.java2.poll_tasks.complete]
2315
package com.example.helloswf;
2416

2517
// snippet-start:[swf.java2.poll_tasks.import]
2618
import java.util.concurrent.CountDownLatch;
2719
import java.util.concurrent.TimeUnit;
20+
21+
import software.amazon.awssdk.regions.Region;
2822
import software.amazon.awssdk.services.swf.SwfClient;
2923
import software.amazon.awssdk.services.swf.model.PollForActivityTaskRequest;
3024
import software.amazon.awssdk.services.swf.model.PollForActivityTaskResponse;
@@ -45,8 +39,8 @@ public static void main(String[] args) {
4539
"Usage:\n" +
4640
" ActivityWorkerWithGracefulShutdown <domain><taskList> \n\n" +
4741
"Where:\n" +
48-
" domain - The domain to use (i.e., mydomain) \n" +
49-
" taskList - The taskList to use (i.e., HelloTasklist) \n" ;
42+
" domain - The domain to use (ie, mydomain). \n" +
43+
" taskList - The taskList to use (ie, HelloTasklist). \n" ;
5044

5145
if (args.length < 2) {
5246
System.out.println(USAGE);
@@ -56,7 +50,10 @@ public static void main(String[] args) {
5650
String domain = args[0];
5751
String taskList = args[1];
5852

59-
SwfClient swf = SwfClient.builder().build();
53+
Region region = Region.US_EAST_1;
54+
SwfClient swf = SwfClient.builder()
55+
.region(region)
56+
.build();
6057

6158
Runtime.getRuntime().addShutdownHook(new Thread() {
6259
@Override
@@ -73,14 +70,15 @@ public void run() {
7370
});
7471
try {
7572
pollAndExecute(swf, domain, taskList);
73+
swf.close();
7674
} finally {
7775
waitForTermination.countDown();
7876
}
7977
}
8078

8179
public static void pollAndExecute(SwfClient swf, String domain, String taskList ) {
8280
while (!terminate) {
83-
System.out.println("Polling for an activity task from the task list '"
81+
System.out.println("Polling for an activity task from the tasklist '"
8482
+ taskList + "' in the domain '" +
8583
domain + "'.");
8684

@@ -125,4 +123,4 @@ private static String executeActivityTask(String input) {
125123
}
126124
}
127125
// snippet-end:[swf.java2.poll_tasks.main]
128-
// snippet-end:[swf.java2.poll_tasks.complete]
126+
// snippet-end:[swf.java2.poll_tasks.complete]

0 commit comments

Comments
 (0)