In Atomic Domain Languages an Action is a named XML Element that describes fundamental unit of executable functionality.
Action steps can be classified into as definition and execute phase.
Action Definition
An Action Element can contain following modifiers or attributes:
- Name
- Documentation
<Action Name="RotateCameraAction" Documentation="Simple Action to Rotate IP-based Camera by x degrees"/>
An Action can be defined in:
- ThingFacet
- AppFacet
- Subscribe
- Sequence
An Action must describe executable code in any Atomic Domain Languages - Workflow, FacetScript, TQL, Subscribe, Sequence and any of their combinations.
NOTE: In case of ThingFacet or AppFacet an Action must start with a Workflow Language.
In case of ThingFacet an Action represents:
- Device State Change, for example, current reading sent by a Temperature Sensor
- Device Actuation Commands, for example, Changing the State of the device (Camera Rotation, Starting a Servo Motor, Reducing the flow of a Greenhouse Sprayer etc).
<Action name="NextRfidAction" documentation="Read next RFID tag"> <Workflow Limit="1" Live="1" Timeout="0"> <Task name="Main" while="true"> <Event name="Argument" as="ActionArgument"/> <Invoke name="ReadId" waitFor="Argument" get="[%:Event.Argument.URL.Value:%]" StopChar="0x0D" ReadTimeout="-1" WriteTimeout="-1" RepeatDelay="1"/> <Output name="Result" as="ActionResult"> <Value> <RFID>[%:[%:@Output:%]Invoke.ReadId.Message.Value:%]</RFID> </Value> </Output> </Task> </Workflow> </Action>
<Action name="SyncPresetAction" documentation="Synchronize camera state and preset"> <Workflow Limit="1" Live="1" Timeout="PT20S"> <Task name="Main" while="true"> <Event name="Argument" as="ActionArgument"/> <Invoke name="SetPreset" waitFor="Argument" skip-if="[%:[:AD:].Preset/no-value(Value):%]" delayAfter="PT5S" get="[%:[:AA:].URL.Value:%]/cgi-bin/decoder_control.cgi?[:UP:][%:amp:%]command=15[%:amp:%]sit=[%:[:AD:].Preset.Value:%]"/> <Output name="Result" as="ActionResult"> <Value> <State> [%:[%:@Output:%]/if([:POK:]) then 'ON' else 'OFF':%]</State> <Preset>[%:[%:@Output:%]/if([:POK:]) then '[%:[:AD:].Preset.Value:%]' else null():%]</Preset> </Value> </Output> </Task> </Workflow> </Action>
<Action name="TakePictureAction" documentation="Synchronize camera state and snapshot image"> <Workflow Limit="1" Live="1" Timeout="PT10S"> <Task name="Main" while="true"> <Event name="Argument" as="ActionArgument"/> <Invoke name="GetImage" waitFor="Argument" delay="PT1S" get="[%:[:AA:].URL.Value:%]/cgi-bin/video_snapshot.cgi?[:UP:]"/> <Output name="Result" as="ActionResult"> <Value> <State>[%:[%:@Output:%]/if([:IOK:]) then 'ON' else 'OFF':%]</State> <Image>[%:[%:@Output:%]/if([:IOK:]) then Invoke/GetImage/Message/Value/text() else '/img/no-image.jpg':%]</Image> </Value> </Output> </Task> </Workflow> </Action>
In case of AppFacet an Action represents:
- Triggering an external non-thing event like sending an Email, Tweet, triggering a build etc.
- Receiving data from external source like a Database update
<Action name="EmailAction" documentation="Send Email"> <Workflow Limit="1" Live="1" Timeout="0"> <Task name="Main" while="true"> <Event name="Argument" as="ActionArgument"/> <Invoke name="ReadValue" waitFor="Argument" post="smtp://[%:Event.Argument.Hostname.Value:%]" Hostname="[%:Event.Argument.Hostname.Value:%]"> <Message> <Value> <Port>[%:Event.Argument.Port.Value:%]</Port> <Username>[%:Event.Argument.Username.Value:%]</Username> <Password>[%:Event.Argument.Password.Value:%]</Password> <From>[%:Event.Argument.From.Value:%]</From> <To>[%:Event.Argument.To.Value:%]</To> <CC>[%:Event.Argument.CC.Value:%]</CC> <Subject>[%:Event.Argument.Subject.Value:%]</Subject> <Body>[%:Event.Argument.Body.Value:%]</Body> <StartTLS>[%:Event.Argument.StartTLS.Value:%]</StartTLS> </Value> </Message> </Invoke> </Task> </Workflow> </Action>
<Action Name="StartSimulatorAction" Documentation="Start the simulator"> <Workflow Limit="1" Live="1" Timeout="-1"> <Task name="Main"> <StartOsWindows>StartProcess.exe cmd.exe "/K c:\Users\Dev\Documents\atomiton\bitbucket\tqlsimulator\build\install\TQLSimulator\bin\TQLSimulator.bat local -runAsFleetEventsGen eventOptions=10"</StartOsWindows> <StartOsUnix>bash config/startupscript.sh</StartOsUnix> <StartOsMac>[:CmdOsUnix:]</StartOsMac> <StopOsWindows>TaskKill.exe /PID [%:Output.ActionArgument.currentSimulatorState/Known/text():%]</StopOsWindows> <StopOsUnix>kill [%:Output.ActionArgument.currentSimulatorState/Known/text():%]</StopOsUnix> <StopOsMac>[:CmdOsUnix:]</StopOsMac> <Event name="Argument" as="ActionArgument"/> <Invoke name="InvokeScript" waitFor="ActionArgument" skip-if="[%:Output.ActionArgument.currentSimulatorState/starts-with(Value, 'off'):%]" execute="[:Start[:OsTag:]:]"> </Invoke> <Output name="ActionResult"> <Value> <currentSimulatorState> [%:Invoke/InvokeScript/Message/Value/text():%] </currentSimulatorState> </Value> </Output> </Task> </Workflow> </Action>
Triggering an Action:
- Starting of an Action is asynchronous and triggered by external / internal event (change of state of a device).
An action is the specification of an executable statement and is the fundamental unit of processing or behavior in an Thing or App Model that represents some transformation in the modeled system, triggered by an external event.
An action forms an abstraction of a computational procedure which is an atomic execution and therefore completes without interruption. An action can either be completed in zero time and cannot be interrupted, once started or it can be a more complex collection of behavior that may run for a long duration. In this scenario, action may be interrupted by events, in which case, it does not run to completion. Zero time execution vs long lasting execution gets defined by the definition of the workflow.
An action of ThingFacet is a result of a device state change or intent to change the state of the device, and is realized by sending a message to an instance or modifying a value of an actionable attribute.
Action is defined as encapsulated workflow, which gets triggered on updates of actionable attributes in ThingModel and/or AppModel. Action can perform synchronous set of activities defined in the workflow.
Where can Action be used in TQL (only in ThingFacets and AppFacets?)
What is the general structure of an Action in TQL? (1 or more workflows?)