Java Action Example Workflow

This example highlights the steps involved in creating and configuring a Java Action to run inside a workflow. For users proficient in java programming, these actions may be useful when a certain amount of work needs to be completed in java code before continuing flow into another action.

For this example, a Flux Java Action (Einstein) is used to calculate the sum of PI (˜3.14) and E (˜2.72). This calculation is done inside the Java Action listener “MyJavaListener”. The result of this calculation is then put into the flow context for the proceeding Console Action (Printer) to display the result on the console.

Running this Example from the Example .ffc File

To get started, login to the Flux Operations Console and head to the Repository tab. 

Click on 'Workflows' to go to the Workflow Repository and from there click on 'Upload' to import the example to the Repository. When the file browser displays, navigate to '/examples/end_users/java_action' inside your Flux installation folder and select the file named 'Java Action.ffc' that's located in the Java Action's example folder. After clicking 'Open' on the file browser window, the workflow will be uploaded to the Repository.

You can now select the Java Action example workflow from the Repository and click 'Edit' to review and edit the workflow in the web-based designer. Go to 'Running the Workflow' below to execute the workflow.

Creating This Example from Scratch

The following steps are required to create this flowchart from scratch.

Creating Actions

Once you are in the web-based designer, locate the actions and triggers used in this example in the 'Actions & Triggers' tabs (shown below) to the left of the workspace. You can drag & drop the actions and triggers into your workspace and arrange them as needed.       

The actions that are used in this example can be found in the following categories:

  • Action Name: “Java Action”, Category: “Java”, Quantity: 1
  • Action Name: “Console Action” , Category: “Core”, Quantity: 1

Setting up Flows

To create the flows that go from an action/trigger to the next just follow the 3 simple steps provided below. This example includes the necessary actions. 

  1. First, make sure the 'Connect the flows' icon is selected. 

2. Click and hold on the action or trigger you wish to draw the flow from.

3. Drag your cursor to the action or trigger  you wish to draw the flow to and release.

       

Renaming Actions

It is always a good idea to give the actions and triggers more descriptive names. Giving actions specific names will help you in remembering what each action/trigger in your workflow is doing. Follow the steps below to edit an action’s name.

To edit an action's name:

Double-click on an action/trigger. The properties window for that action will be displayed:

      

  1. Edit the 'Name' field, type in the name you wish to give the action.
  2. Click 'Ok'.

Action Names

In this example the actions have been renamed to the following:

· “Java Action” to “Einstein”.

· “Console Action” to “Printer”.

Editing Action Properties

Java Action

Once a Java Action executes in a workflow, the Java Action’s listener class is invoked. This listener class must implement flux.ActionListener and override the actionFired(KeyFlowContext) method. For this example the java class “MyJavaListener”, located in “example/end_users/java_action” under your Flux installation directory, is implemented for you. This class takes the sum of the numbers “PI” and “E” and puts the result into the flow context. To register this listener with the Java Action, click the “Einstein” Java Action within your drawing canvas. The action’s “Action Properties” panel represented below in Figure 9 will appear to the right of the Designer.

     

The 'Listener' field inside the “Action Properties” panel can be edited to include the listener's information, in this example 'examples.end_users.java_action.MyJavaListener' is used. Once completed, the java class “MyJavaListener” will be registered with the Java Action.

NOTE: The Java Action you wish to register with the Flux engine must be within the engine’s class path.

Setting up a Runtime Data Map

A runtime data map is used in this example, on the flow from the “Einstein” Java Action to the “Printer” Console Action. This runtime data map provides a way for “Printer” to display the result of the calculation made by “Einstein”. You can create runtime data maps on flows by right clicking the flow as shown below and selecting 'Flow Properties'. 

      

Once the Flow Properties dialog is opened, click on the 'Add' shown next to the 'Runtime Data Map' to open the runtime data map editor. If you already have a runtime data map 'Edit' will be shown instead of 'Add'. You can now click on 'Add Data Mapping' on the runtime data map editor to add a new runtime data map.       

In the FROM section of this example's runtime data map, 'Flow Context' is selected and the field's value is 'calculation'. The word 'calculation' is the name the calculation from “MyJavaListener” is mapped. In the TO section of the data map, 'Action Property Target' is selected, and the action's property to which the calculation is being mapped to is the Console action's 'Message'. 

      

Once the runtime data map is complete, click the 'Save' button to save the data map.

Saving the Workflow

After editing your workflows, remember to save your changes to the Repository. To do so, just click on 'Save to Repository' on the bottom right corner of the workspace.

Running the Workflow

Next, export your workflow to the engine. You can do this step by clicking on 'Export to Engine' on the bottom right of the workspace. You may also export a workflow straight from the Workflows Repository by selecting teh workflow you wish to export and clicking on 'Start'.

A confirmation window will appear if the workflow was successfully exported. Click the 'Close' button on the confirmation message. If there is an error message, look over this example carefully, and correct any mistakes made.

Once the workflow has run, view the console from which your engine is running. The sum of the numbers PI and E will be printed out to that console.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.