AWS Flow Framework
Developer Guide (Java) (API Version 2012-01-25)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Setting up the Development Environment

The following sections explain how to set up your development environment for the AWS Flow Framework.

Prerequisites

To develop applications that use the AWS Flow Framework, you will need the AWS SDK for Java. You can download the SDK from the following URL:

http://aws.amazon.com/sdkforjava/

We highly recommend that you use the Eclipse development environment and the AWS Toolkit for Eclipse.

For instructions on how to install the Toolkit, go to the Getting Started Guide for the Toolkit.

Be sure to install the Amazon Simple Workflow Service (SWF) Tools. Among other things, this plug-in processes the annotations for the AWS Flow Framework and generates the client classes.

Install the AWS Toolkit for Eclipse including the SWF Tools

Setting Up an Eclipse Project

To configure an Eclipse Java project for the AWS Flow Framework, follow the steps below. These steps were tested with Eclipse 3.6 and JDK 1.6.

When you create your Java project, be sure to configure Eclipse to show the Java perspective, which includes the Package Explorer.

To configure an Eclipse Java project for the AWS Flow Framework

  1. Enable annotation processing in your project. In the Package Explorer, right-click the project and select: Properties.

    In the Properties dialog, navigate to Java Compiler > Annotation Processing.

    Select Enable project specific settings, then select Enable annotation processing

    Enable annotation processing in Eclipse IDE

    Click Apply, then click OK. You may need to rebuild your project in order for the new settings to take effect.

  2. Setup AspectJ for your project. AWS Flow Framework has a dependency on AspectJ; however, you don't need to learn AspectJ to use AWS Flow Framework. AspectJ is used internally by AWS Flow Framework.

    You can use either of the following methods to satisfy the dependency on AspectJ. We recommend load time weaving because of additional workarounds you need to perform if you choose compile team weaving.

  3. Eclipse Java Project Setup with AspectJ load time weaving (Recommended)

    1. Add the AspectJ Java agent as a JVM parameter. You can set JVM parameters in more than one way. One approach is as follows:

      On the Window menu, select Preferences. In the Preferences dialog, navigate to Java > Installed JREs

      Installed Java Runtime Environments

      Pick the JRE that you will use for your project, click Edit, then add the following line in the text box labeled Default VM Argument.

      -javaagent:<local directory containing the AWS SDK for Java>/third-party/aspectj-1.6/aspectjweaver.jar

      Set up AspectJ load time weaving.

    2. Add a folder named META-INF in your sources folder and create a file named aop.xml. The contents of this file should be as follows:

      
      <aspectj>
        <aspects>
        <!-- declare two existing aspects to the weaver -->
          <aspect name="com.amazonaws.services.simpleworkflow.flow.aspectj.AsynchronousAspect"/>
          <aspect name="com.amazonaws.services.simpleworkflow.flow.aspectj.ExponentialRetryAspect"/>
        </aspects>
        <weaver options="-verbose">
          <include within="<expression to match your types>"/>
        </weaver>
      </aspectj>
      
      

      For the AWS Flow SDK samples, we used the following for "<expression to match your types>":

      com.amazonaws.services.simpleworkflow.flow.examples..*
    3. Add the AWS Flow Framework jar file: aws-java-sdk-1.3.8.jar to the Build Path of your project.

      In Package Explorer, right-click your package, and select:

      Build Path > Configure Build Path > Libraries > Add External Jars.

      Your JAR file may have a different version than the one shown above and in the screen shot (1.3.8).

  4. Eclipse Project Setup with AspectJ compile time weaving

    Use this method if you are not using load time weaving.

    1. Install AspectJ developer tools for Eclipse: http://www.eclipse.org/ajdt/whatsnew213/. Install the tools using the Help | Install New Software from the Eclipse IDE.

      AspectJ Developer Tools Components

    2. Convert your project to an AspectJ Project. In Package Explorer, right-click on your project and select Configure > Convert to AspectJ Project. Converting the project is required in order for certain AWS Flow Framework annotations, such as @Asynchronous, to work.

    3. Add aws-java-sdk-1.3.8.jar to the Aspect Path for your project so that aspects defined in these jars will be weaved into your classes. (AspectJ Tools > Configure AspectJ Build Path > AspectJ Build > Add External Jars).

    4. Add aws-java-sdk-1.3.8.jar to the Build Path of your project: in Package Explorer, right-click your package and select Build Path > Configure Build Path. In the Properties dialog, select the Libraries tab, click Add External Jars, then navigate to and select the JAR file.

      Add AWS SDK Jar to Project Build Path

Note

The AspectJ Eclipse plug-in has an issue that prevents generated code from being compiled. You can work around this issue by disabling and reenabling AspectJ capabilities on the project. (AspectJ Tools > Remove AspectJ Capability > Disable AspectJ followed by Configure > Convert to AspectJ Project).

If you are building your project from the command line, ensure that aws-java-sdk-flow-build-tools-1.3.8.jar is in the classpath. This jar file contains the AWS Flow Framework annotation processor that must be run to generate code. For an example, see the build.xml file included in the samples folder.

Developing a Workflow

After you have set up the development environment, you can start developing workflows with the AWS Flow Framework. The typical steps involved in developing a workflow are as follows:

  1. Define activity and workflow contracts. First, analyze your application requirements and identify the workflow and activities that are needed to fulfill them. For example, in a media processing application, you may need to download a file, process it, and upload the processed file to an Amazon Simple Storage Service (S3) bucket. For this application, you may define a file processing workflow and activities to download the file, perform processing on it, upload the processed file, and delete files from the local disk. In AWS Flow Framework, workflow and activities are defined using Java interfaces. As a result, you can decouple the implementation from its consumers. For example, you can define a FileProcessingWorkflow interface and provide different implementations for different types of processing, such as video encoding, compression, and thumbnails, each of which may have different control flows and call different activity methods. The use of interfaces also makes it simple to test your workflows using mock implementations.

  2. Generate clients. After you have defined the workflow and activity contracts, you can generate clients for them using AWS Flow Framework. If you are using Eclipse and you have configured your project as described above, the clients will be generated for you automatically. The Amazon SWF client libraries eliminate the need for you to program the details of creating requests, marshaling data, and similar tasks. Instead, you instantiate a client class and call methods on the resulting object. The methods in the client classes mirror those of the contract interface, and the client creates the appropriate request to send to Amazon SWF. Clients are generated for the workflow and the activities.

  3. Implement activity and workflow interfaces. The workflow implementation provides business logic, while each activity implements a single logical processing step in the application. The workflow implementation calls the activities using the generated client. In the media processing example, the coordination logic calls the activities in a sequence: download a file, process it, upload the processed file, and then delete the local copies of the files. Each activity implements a single step in the image processing workflow.

  4. Implement host programs for activity and workflow implementations. After you have implemented your workflow and activities, you need to create host programs. A host program is responsible for getting tasks from Amazon SWF and dispatching them to the appropriate implementation method. AWS Flow Framework provides worker classes that make implementing these host programs trivial.

  5. Test your workflow. Amazon SWF provides JUnit integration that you can use to test your workflows inline and locally.

  6. Deploy the workers. You can now deploy your workers as desired—for example, you can deploy them to instances in the cloud or in your own data centers. Once deployed, the workers start polling Amazon SWF for tasks.

  7. Start executions. You can start an execution of your workflow from any program using the generated workflow client. You can also use the Amazon SWF console to start and view workflow executions in your Amazon SWF account.

The AWS SDK for Java contains samples for the AWS Flow Framework, including a file processing workflow, that you can browse and run by following the instructions in the included readme.html file.