This is the main interfaces of the state development.
public interface StatePlugin extends PluginInterface
All members of StatePlugin, including inherited members.Methods
|Modifier and Type||Method||Description|
|public List< IAttribute >||getInputAttributes()||Return the input attributes specified by this state.|
|public List< IAttribute >||getOutputAttributes()||Return the output attributes specified by this state.|
|public long||getStateId()||The state unique ID.|
|public String||getStateName()||The state name is used for display on the state editor.|
|public String||getStateNotes()||The detailed description about the state, and documentations on how to use the state including the follow-up transitions.|
|public boolean||isSelectable()||To indicate whether the state can be used as the follow-up state.|
|public void||loadStateAttributes(SmappStateEditorContext)||This method is called by the state editor only.|
|public SmappState||processMessage(SmappStateProcessingContext)||This method is called by the processing engine when the state is activated from external source, for example, incoming SMS message.|
|public void||processState(SmappStateProcessingContext, SmappStateProcessingAction)||This method is always called by the processing engine when the state is activated by the follow-up transition.|
|public boolean||supportEncryption()||Indicate whether this state support encryption.|
|public boolean||supportsDynTransition()||Indicates if the state supports dynamic (Dyn) transition.|
|public boolean||supportsFailTransition()||Indicate if the state uses the Fail follow-up transition type.|
|public boolean||supportsGoToApplication()||Indicate if the state supports transfer flow to another application.|
|public boolean||supportsOkTransition()||Indicate if the state uses the OK follow-up transition type.|
|public boolean||supportsSendSmsMessage()||Indicate if the state may send SMS message to the current consumer.|
|Modifier and Type||Member||Description|
|public void||setInstanceName(String)||A plugin may be instantiated multiple times with different set of attributes, the instanceName may be set externally to uniquely identify a particular instance.|
|public void||shutdown()||Stop this plugin instance.|
|public void||startup(HashMap< String, String >)||Initiate the startup process for this plugin instance.|
States need to implement this interface so that: it can be displayed on the Application Composer and State Editor, and invoked by the "Processing Engine" at application runtime. As such it should be regarded as the 'external' API. Any classes that extend this interface will be referred to as State for the purpose of this API documentations. Some methods are used only by the state editor or the processing engine, others may be used by both, as stated in each methods description.
An Application defines the process flow in the form of interconnected states. An application usually has more than one states, and can include more than one types of state. Therefore, states are the building blocks for composing an application. This StatePlugin is the interface that needs to be implemented by the states.
- Application can be invoked by many different external activation mechanisms, such as: incoming SMS message, scheduled event, or web service invocation. The first state in any applications is the "Application Start" state, that is automatically created by default and cannot be removed. So immediately after invoking the application, the first state, the "Application Start" state will be executed.
- When executing a state, the processing engine will call one of the following processing methods: the processMessage(SmappStateProcessingContext) and the processState(SmappStateProcessingContext, SmappStateProcessingAction), based on the activation mechanism, described in details below (see ACTIVATION).The method(s) need to be implemented by each state to encapsulate the business logic that the state represents.
- The state can be invoked by two methods: external activation or follow-up transition. The <u>external</u> occurs when the state processing has been temporarily paused (or hibernated) waiting for an external event, and the state is re-activated by the arrival of the external event. In this case, the processMessage() will be called.If the state is invoked by the follow-up transition, in this case from another state, the second method or processState() will be called.
- The first method (i.e., processMessage()) returns the follow-up transition object (SmappState) that will become the current state for the subsequent method (i.e.,
processState()).For example, let's say the application flow looks like the following:
state1 ->Send SMS state -> state2 ->state3When the flow reaches the Send SMS state, a message will be sent out and the flow will be paused waiting for a response. The current state remains as the Send SMS state. On arrival of the response message, first the processMessage() method will be called. This method will find the follow-up transition that match the incoming message, and return the corresponding state. Let's say it's "state2". Next, the processing engine will make "state2" as the current state and then call the processState() method of "state2".
- The processState() method does not return the follow-up transition object (or SmappState), but instead setting the input parameter (SmappStateProcessingAction), by calling the appropriate method, to communicate to the processing engine the intended follow-up transition.
- Using the above application flow example, the processState() method of "state2" specify "state3" as the follow-up transition state. So the processing engine will continue the process by calling the processState() method of "state3".
- This process of stepping through the flow will continue until one of the following conditions:
- reaching a state that set the processing engine to the waitForMessage status, such as after sending SMS out. The process will re-start on arrival of the message, and it will invoke the processMessage() method. The process then repeat from step 4 again.
- the state has no follow-up transition, so the processing engine will terminate
The state can be activated by two methods: external or follow-up. In most cases, the state is activated by the follow-up method. The <u>follow-up activation</u> occurs as a result of a follow-up transition from the previous connected state. In addition, the follow-up activation can also occur when the state performs the loop-back mechanism from the one of the processing methods: processMessage(SmappStateProcessingContext) or processState(SmappStateProcessingContext, SmappStateProcessingAction) methods, by conditionally returning the current state (or context.currentState). NOTE: please use the loop-back mechanism with caution because it could easily resulting in an infinite loop in the state processing. The follow-up activation calls the processState(SmappStateProcessingContext, SmappStateProcessingAction) method, and the state implements the required business logic in this method.
The <u>external activation</u> occurs when the state processing has been temporarily paused (or hibernated) waiting for an external event, and the state is re-activated by the arrival of the external event by invoking the the processMessageLogic(SmappStateProcessingContext) method. The external activation mechanism is used by states that support the Send SMS, such as: the base "Send SMS" state and the states that extend the com.sybase365.mobiliser.brand.plugins.smapp.state.AbstractDynamicMenu. For example, the "Send SMS" state sends an SMS message to the mobile device, and then goes into hibernation. When a reply message arrives, this will re-activate state using the external activation method that calls the processMessage(SmappStateProcessingContext) method. In addition, any state that implements the calls to the SmappStateProcessingAction - waitForMessage() in the processing methods will also need to ensure that external activation will happen and it can handle the external activation in the processMessage(SmappStateProcessingContext) method. Otherwise, the application will never continue and it will be terminated when the session timeout.
The processMessage(SmappStateProcessingContext) and processState(SmappStateProcessingContext, SmappStateProcessingAction) methods are referred to as the processing methods.
RETURNING FLOW BACK TO PROCESING ENGINE
- Follow-up transition - the state returns the SmappState from the (processMessage(SmappStateProcessingContext) method, that tells the processing engine which follow-up transition to follow and hence the corresponding follow-up state.
- Follow-up action - by setting the SmappStateProcessingAction object provided by processing engine as an input parameter to the processing methods. The SmappStateProcessingAction provides methods for setting the needed actions. For example, calling action.waitForMessage() tells the processing engine to wait for external activation before proceeding.The processState(SmappStateProcessingContext, SmappStateProcessingAction) does not return SmappState object. So it needs to use the input parameter SmappStateProcessingAction to tell the processing engine which follow-up transition to follow.When the follow-up action is used, the processing methods should return null.