1
1
//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)]
3
4
//snippet-keyword:[Code Sample]
4
- //snippet-service:[Amazon Simple Workflow Service]
5
5
//snippet-sourcetype:[full-example]
6
- //snippet-sourcedate:[8/4 /2020]
6
+ //snippet-sourcedate:[11/06 /2020]
7
7
//snippet-sourceauthor:[scmacdon-aws]
8
8
9
9
/*
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
+
22
14
// snippet-start:[swf.java2.poll_tasks.complete]
23
15
package com .example .helloswf ;
24
16
25
17
// snippet-start:[swf.java2.poll_tasks.import]
26
18
import java .util .concurrent .CountDownLatch ;
27
19
import java .util .concurrent .TimeUnit ;
20
+
21
+ import software .amazon .awssdk .regions .Region ;
28
22
import software .amazon .awssdk .services .swf .SwfClient ;
29
23
import software .amazon .awssdk .services .swf .model .PollForActivityTaskRequest ;
30
24
import software .amazon .awssdk .services .swf .model .PollForActivityTaskResponse ;
@@ -45,8 +39,8 @@ public static void main(String[] args) {
45
39
"Usage:\n " +
46
40
" ActivityWorkerWithGracefulShutdown <domain><taskList> \n \n " +
47
41
"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 " ;
50
44
51
45
if (args .length < 2 ) {
52
46
System .out .println (USAGE );
@@ -56,7 +50,10 @@ public static void main(String[] args) {
56
50
String domain = args [0 ];
57
51
String taskList = args [1 ];
58
52
59
- SwfClient swf = SwfClient .builder ().build ();
53
+ Region region = Region .US_EAST_1 ;
54
+ SwfClient swf = SwfClient .builder ()
55
+ .region (region )
56
+ .build ();
60
57
61
58
Runtime .getRuntime ().addShutdownHook (new Thread () {
62
59
@ Override
@@ -73,14 +70,15 @@ public void run() {
73
70
});
74
71
try {
75
72
pollAndExecute (swf , domain , taskList );
73
+ swf .close ();
76
74
} finally {
77
75
waitForTermination .countDown ();
78
76
}
79
77
}
80
78
81
79
public static void pollAndExecute (SwfClient swf , String domain , String taskList ) {
82
80
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 '"
84
82
+ taskList + "' in the domain '" +
85
83
domain + "'." );
86
84
@@ -125,4 +123,4 @@ private static String executeActivityTask(String input) {
125
123
}
126
124
}
127
125
// 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