Table of Contents:
Introduction
In this tutorial we will create a process that uses location-based events and custom Java logic as part of the process.
Just as in Tutorial 3, there are 4 nodes:
- One moving node called “M” (M0 )
- Three static nodes, called “S”. (S1-S3 ).
In this tutorial, M will run a process that first waits for M to reach a specific coordinate on the map. Then, if the coordinate is reached, M runs a task to collect sensor data. This sensor data task is defined using custom Java code that produces a sensor value and sets a process variable with it. After obtaining the sensor value, the process waits for a new connection and sends the sensor data process variable as a message once the connection is established.
Location signals
To set up an Intermediate Signal Catching Event for location-based signals, the following has to be done:
- Similar to connection signals (Tutorial 3), set up a signal definition for the process. The signal definition must have the name “Device Nearby”, you can use the signal templates to quickly define one. The catching event must refer to this signal.
- In addition to above, an execution listener must be added to the signal catching event. To do this, select the signal catching event, and click on “Execution listeners”, and select the STEP-ONE coordinate listener template. Then, replace the x,y values with your desired coordinates, in this example, use “150,200”. See video below for an example.
Custom Java Logic
To imitate a sensor device reading, let’s use some custom Java code as part of the process. For this, we will create a subclass of Simulated Work Task-s default implementation (ee.mass.epm.sim.task.SimulatedTask).
The new subclass implemetation should be within the Java/Gradle project of STEP-ONE, e.g. :
step-one/step-one-main/src/main/java/ee/mass/epm/samples/SensorReadTask.java
The implementation looks like:
package ee.mass.epm.samples;
import ee.mass.epm.sim.task.SimulatedTask;
import org.flowable.engine.delegate.DelegateExecution;
public class SensorReadTask extends SimulatedTask {
@Override
public void execute(DelegateExecution execution) {
super.execute(execution);
execution.setVariable("sensorValue", Math.random() );
}
}
The execute() method is invoked when the process arrives at this Task. Using execution.setVariable( ), we are setting a process variable. In this case, we are using a random value. But we could instead obtain some values from the simulation environment, from ONE-s energy modelling system, etc. It is also possible to read the values of other existing process variables through the DelegateExecution object.
To specify the usage of this class in a Process Task, take the Simulated Work Task from the STEP-ONE palette, but update the “Class” property to the path of your custom Java code, e.g. for this example, we would use ee.mass.epm.samples.SensorReadTask as the new Class value.
We are using a subclass of SimulatedTask because this gives us easy control over how long the task will take in simulation clock time ( with the worksize parameter). For more advanced use cases it may not always be good to use SimulatedTask as the base implementation.
Sending the sensor value
After setting the process variable from the Java task, create an Intermediary Signal Catching Event for New connections, and then add a Send BP Message task to send the variable sensorValue to the connected peer. This can be done following the example of Tutorial 3.
Running the tutorial
When running this tutorial example, use the Processes Info (by clicking on M0 in the Nodes list and selecting “processes info”) to observe how M0-s process variables change as it passes the specified coordinate (150,200). In the below video, this happens at the 194th timestep.