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.1.4 we can generate a Maven project with the SimulatedHeater.java, HeaterMessageProcessor.java, HeaterSimulationProcessor.java, and TemperatureChangeMessage.java already created.

This archetype is available from the public ScaleOut repository. To allow the Maven archetype:generate command to find the repository, create a profile in your Maven settings or in a local file. For complete documentation on connecting to the ScaleOut repository, see the JavaProjectConfigurationGuide.

For example, you can add the following to your ~/.m2/settings.xml:

<profiles>
  <profile>
      <id>archetype-generate</id>
      <repositories>
          <repository>
              <id>scaleout-release</id>
              <url>https://packages.scaleoutsoftware.com/repository/scaleout-release/</url>
          </repository>
      </repositories>
  </profile>
</profiles>
<activeProfiles>
    <activeProfile>archetype-generate</activeProfile>
</activeProfiles>

Alternatively, you can create a local settings file and use that settings file when generating the archetype. For example, “archetype-settings.xml”

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <profiles>
    <profile>
      <id>generate-archetype</id>
      <repositories>
        <repository>
          <id>scaleout-release</id>
          <url>https://packages.scaleoutsoftware.com/repository/scaleout-release/</url>
        </repository>
      </repositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>generate-archetype</activeProfile>
  </activeProfiles>
</settings>

Then, when generating the archetype, specify the settings file to the mvn command:

mvn -s /path/to/archetype-settings.xml archetype:generate ...

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-simulation-digitaltwin \
  -DarchetypeVersion=3.1.4 \
  -DgroupId=com.example.heater \
  -DartifactId=heater \
  -DtwinClassName=SimulatedHeater \
  -DinteractiveMode=false

Note

On Windows, the archetype:generate command may require quotes around each property. i.e. “-DarchetypeGroupId=com.scaleoutsoftware.archetypes”.

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

  • SimulatedHeaterSimulationProcessor.java

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