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:3.0.0 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=3.0.0 \
  -DgroupId=com.example.heater \
  -DartifactId=heater \
  -DtwinClassName=SimulatedHeater \
  -DinteractiveMode=false

What these options do:

Property

Description

groupId

Your organization or namespace

artifactId

Name of the generated project directory

twinClassName

The class representing each SimulatedHeater

This command generates a new folder (thermostat) containing:

  • Java class stubs for your Digital Twin classes

  • A pre-configured scaleoutPackage.json metadata file

  • A Maven project file (pom.xml) with preconfigured dependencies

  • A 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.