Define the Simulation Processor
Digital twin models can be used to implement a simulation. To do this, you will need to create Java classes for a DigitalTwinBase
, MessageProcessor
, and a SimulationProcessor
, an additional interface that is used to process time-ordered simulation events generated by the service.
Using the archetype from com.scaleoutsoftware.archetypes:scaleout-simulation-digitaltwin:1.0.6
we can generate a Maven project with the SimulatedHeater.java, HeaterMessageProcessor.java, HeaterSimulationProcessor.java, and TemperatureChangeMessage.java already created. To create the Thermostat project with the scaleout-realtime-digitaltwin archetype, execute the following command in your terminal:
mvn archetype:generate \
-DarchetypeGroupId=com.scaleoutsoftware.archetypes \
-DarchetypeArtifactId=scaleout-realtime-digitaltwin \
-DarchetypeVersion=1.0.6 \
-DgroupId=com.example.heater \
-DartifactId=heater \
-DmodelName=SimulatedHeater \
-DmessageName=TemperatureChangeMessage \
-DmessageProcessorName=HeaterMessageProcessor \
-DsimulationProcessorName=HeaterSimulationProcessor \
-DinteractiveMode=false
What these options do:
Property |
Description |
---|---|
|
Your organization or namespace |
|
Name of the generated project directory |
|
The class representing each SimulatedHeater |
|
Telemetry message detailing the temperature change |
|
Message processing logic for a SimulatedHeater |
|
The class that handles simulation events for a SimulatedHeater |
This command generates a new folder (thermostat
) containing:
Java class stubs for your Digital Twin classes
A pre-configured
model.json
metadata fileA Maven project file (
pom.xml
) with preconfigured dependenciesA build pipeline for packaging your project
Alternatively, you can create the project using your build tool of choice. The following class examples are using the package:
com.example.heater
Inside that package, create the following classes:
SimulatedHeater.java
HeaterSimulationProcessor.java
HeaterMessageProcessor.java
TemperatureChangeMessage.java
These classes will generate and send temperature change messages to the previously defined real-time thermostat digital twins. For test purposes, you can copy and paste the sample code in the following subtopics into these three files.