@@ -185,17 +185,15 @@ interest of time, these steps *will be implied every time you add a new file to
185185#. Add a :code-java: `package ` declaration to the beginning of each file to declare its namespace.
186186   The example project uses:
187187
188-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/HelloTypes .java
188+    .. literalinclude :: swf.java.hello_types.package.txt  
189189       :language:  java
190-        :lines:  16
191190
192191#. Add :code-java: `import ` declarations for the :aws-java-class: `AmazonSimpleWorkflowClient 
193192   <services/simpleworkflow/AmazonSimpleWorkflowClient> ` class and for multiple classes in the
194193   ``com.amazonaws.services.simpleworkflow.model `` namespace. To simplify things, we'll use:
195194
196-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/HelloTypes .java
195+    .. literalinclude :: swf.java.hello_types.import.txt  
197196       :language:  java
198-        :lines:  18-20
199197
200198.. _swf-hello-hellotypes :
201199
@@ -212,28 +210,25 @@ your activity and workflow types, the domain name and the task list name.
212210#. Declare the :classname: `HelloTypes ` class and provide it with values to use for your registered
213211   activity and workflow types:
214212
215-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/HelloTypes .java
213+    .. literalinclude :: swf.java.hello_types.string_declare.txt  
216214       :language:  java
217-        :lines:  22-28, 83
218215
219216   These values will be used throughout the code.
220217
221218#. After the String declarations, create an instance of the :aws-java-class: `AmazonSimpleWorkflowClient 
222219   <services/simpleworkflow/AmazonSimpleWorkflowClient> ` class. This is the basic interface to the
223220   |SWF | methods provided by the |sdk-java |.
224221
225-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/HelloTypes .java
222+    .. literalinclude :: swf.java.hello_types.client.txt  
226223       :language:  java
227-        :lines:  30-31
228224       :dedent:  4
229225
230226#. Add a new function to register a SWF domain. A *domain * is a logical container for a number of
231227   related SWF activity and workflow types. SWF components can only communicate with each other if
232228   they exist within the same domain.
233229
234-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/HelloTypes .java
230+    .. literalinclude :: swf.java.hello_types.new_function.txt  
235231       :language:  java
236-        :lines:  33-42
237232       :dedent:  4
238233
239234   When you register a domain, you provide it with a *name * (any set of 1 |ndash | 256 characters
@@ -254,9 +249,8 @@ your activity and workflow types, the domain name and the task list name.
254249#. Add a function to register a new activity type. An *activity * represents a unit of work in your
255250   workflow.
256251
257-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/HelloTypes .java
252+    .. literalinclude :: swf.java.hello_types.new_activity_type.txt  
258253       :language:  java
259-        :lines:  44-60
260254       :dedent:  4
261255
262256   An activity type is identified by a *name * and a *version *, which are used to uniquely identify
@@ -276,9 +270,8 @@ your activity and workflow types, the domain name and the task list name.
276270#. Add a function to register a new workflow type. A *workflow *, also known as a *decider *
277271   represents the logic of your workflow's execution.
278272
279-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/HelloTypes .java
273+    .. literalinclude :: swf.java.hello_types.new_workflow_type.txt  
280274       :language:  java
281-        :lines:  62-76
282275       :dedent:  4
283276
284277   Similar to activity types, workflow types are identified by a *name * and a *version * and also
@@ -292,9 +285,8 @@ your activity and workflow types, the domain name and the task list name.
292285#. Finally, make the class executable by providing it a :code-java: `main ` method, which will register the
293286   domain, the activity type, and the workflow type in turn:
294287
295-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/HelloTypes .java
288+    .. literalinclude :: swf.java.hello_types.main.txt  
296289       :language:  java
297-        :lines:  78-82
298290       :dedent:  4
299291
300292You can :ref: `build  <swf-hello-build >` and :ref: `run  <swf-hello-run-register >` the application now
@@ -319,19 +311,20 @@ We'll implement a simple activity worker that drives a single activity.
319311
320312#. Open your text editor and create the file :file: `ActivityWorker.java `, adding a package
321313   declaration and imports according to the :ref: `common steps  <swf-hello-common >`.
314+    
315+    .. literalinclude :: swf.java.activity_worker.import.txt 
316+        :language:  java
322317
323318#. Add the :classname: `ActivityWorker ` class to the file, and give it a data member to hold a SWF
324319   client that we'll use to interact with |SWF |:
325320
326-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/ActivityWorker .java
321+    .. literalinclude :: swf.java.activity_worker.client.txt  
327322       :language:  java
328-        :lines:  22-24, 75
329323
330324#. Add the method that we'll use as an activity:
331325
332-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/ActivityWorker .java
326+    .. literalinclude :: swf.java.activity_worker.sayHello.txt  
333327       :language:  java
334-        :lines:  26-28
335328       :dedent:  4
336329
337330   The activity simply takes a string, combines it into a greeting and returns the result. Although
@@ -341,9 +334,8 @@ We'll implement a simple activity worker that drives a single activity.
341334#. Add a :methodname: `main ` method that we'll use as the activity task polling method. We'll start
342335   it by adding some code to poll the task list for activity tasks:
343336
344-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/ActivityWorker .java
337+    .. literalinclude :: swf.java.activity_worker.poll_method.txt  
345338       :language:  java
346-        :lines:  30-42, 74
347339       :dedent:  4
348340
349341   The activity receives tasks from |SWF | by calling the SWF client's
@@ -358,10 +350,9 @@ We'll implement a simple activity worker that drives a single activity.
358350   :methodname: `main ` method, right after the code that polls for the task and retrieves its task
359351   token.
360352
361-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/ActivityWorker .java
353+    .. literalinclude :: swf.java.activity_worker.process_tasks.txt  
362354       :language:  java
363-        :lines:  44-72
364-        :dedent:  12
355+        :dedent:  8
365356
366357   If the task token is not :code-java: `null `, then we can start running the activity method
367358   (:methodname: `sayHello `), providing it with the input data that was sent with the task.
@@ -397,26 +388,23 @@ schedule a new activity or not) and takes an appropriate action (such as schedul
397388
398389#. Add a few additional imports to the file:
399390
400-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/WorkflowWorker .java
391+    .. literalinclude :: swf.java.workflow_worker.import.txt  
401392       :language:  java
402-        :lines:  21-23
403393
404394#. Declare the :classname: `WorkflowWorker ` class, and create an instance of the
405395   :aws-java-class: `AmazonSimpleWorkflowClient <services/simpleworkflow/AmazonSimpleWorkflowClient> ` class
406396   used to access SWF methods.
407397
408-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/WorkflowWorker .java
398+    .. literalinclude :: swf.java.workflow_worker.client.txt  
409399       :language:  java
410-        :lines:  25-27, 139
411400
412401#. Add the :methodname: `main ` method. The method loops continuously, polling for decision tasks
413402   using the SWF client's :methodname: `pollForDecisionTask ` method. The
414403   :aws-java-class: `PollForDecisionTaskRequest <services/simpleworkflow/model/PollForDecisionTaskRequest> `
415404   provides the details.
416405
417-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/WorkflowWorker .java
406+    .. literalinclude :: swf.java.workflow_worker.main.txt  
418407       :language:  java
419-        :lines:  29-52
420408       :dedent:  4
421409
422410   Once a task is received, we call its :methodname: `getTaskToken ` method, which returns a string
@@ -428,9 +416,8 @@ schedule a new activity or not) and takes an appropriate action (such as schedul
428416#. Add the :methodname: `executeDecisionTask ` method, taking the task token (a :classname: `String `)
429417   and the :classname: `HistoryEvent ` list.
430418
431-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/WorkflowWorker .java
419+    .. literalinclude :: swf.java.workflow_worker.execute_decision_task_token.txt  
432420       :language:  java
433-        :lines:  60-67, 138
434421       :dedent:  4
435422
436423   We also set up some data members to keep track of things such as:
@@ -447,9 +434,8 @@ schedule a new activity or not) and takes an appropriate action (such as schedul
447434   objects that were sent with the task, based on the event type reported by the
448435   :methodname: `getEventType ` method.
449436
450-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/WorkflowWorker .java
437+    .. literalinclude :: swf.java.workflow_worker.execute_decision_task_history_events.txt  
451438       :language:  java
452-        :lines:  69-102
453439       :dedent:  8
454440
455441   For the purposes of our workflow, we are most interested in:
@@ -480,9 +466,8 @@ schedule a new activity or not) and takes an appropriate action (such as schedul
480466 #. After the :code-java: `switch ` statement, add more code to respond with an appropriate *decision *
481467   based on the task that was received.
482468
483-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/WorkflowWorker .java
469+    .. literalinclude :: swf.java.workflow_worker.task_decision.txt  
484470       :language:  java
485-        :lines:  104-132
486471       :dedent:  8
487472
488473   * If the activity hasn't been scheduled yet, we respond with a :classname: `ScheduleActivityTask `
@@ -505,9 +490,8 @@ schedule a new activity or not) and takes an appropriate action (such as schedul
505490   processing the task. Add this code at the end of the :methodname: `executeDecisionTask ` method
506491   that we've been writing:
507492
508-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/WorkflowWorker .java
493+    .. literalinclude :: swf.java.workflow_worker.return_decision_objects.txt  
509494       :language:  java
510-        :lines:  134-138
511495       :dedent:  8
512496
513497   The SWF client's :methodname: `respondDecisionTaskCompleted ` method takes the task token that
@@ -524,9 +508,8 @@ Finally, we'll write some code to start the workflow execution.
524508
525509#. Add the :classname: `WorkflowStarter ` class:
526510
527-    .. literalinclude :: example_code/ swf/src/main/java/aws/example/helloswf/WorkflowStarter .java
511+    .. literalinclude :: swf.java.workflow_starter.complete.txt  
528512       :language:  java
529-        :lines:  22-
530513
531514   The :classname: `WorkflowStarter ` class consists of a single method, :methodname: `main `, which
532515   takes an optional argument passed on the command-line as input data for the workflow.
0 commit comments