Deploying Java Models
This section describes how to deploy digital twin models to an on-premises deployment of ScaleOut StreamServer instead of to the ScaleOut Digital Twins™ service. As described in the topic Building a model, a digital twin model consists of four classes: a digital twin state object, message, a message processor, and a simulation processor (when the model is used for simulation). Please refer to this section for step-by-step instructions on building a digital twin model.
Prerequisites
The highest supported JDK is 21. The lowest supported JDK is 8.
As a prerequisite, be sure that Java is installed and the JAVA_HOME environment variable is set. You will need either Gradle or Maven to download the required JARs.
The first step is to create a Java project and set up the classpath using your preferred build tool (Gradle or Maven). The ScaleOut JARs are published to Maven Central.
Once the project is initialized, add the real-time digital twin APIs as dependencies.
Adding Hosting Gradle Dependency
compile group: 'com.scaleoutsoftware.digitaltwin', name: "hosting", version: '3.2.10'
Adding Hosting Maven Dependency
<dependencies>
<!-- ... -->
<!-- your dependencies -->
<!-- ... -->
<dependency>
<groupId>com.scaleoutsoftware.digitaltwin</groupId>
<artifactId>hosting</artifactId>
<version>3.2.10</version>
</dependency>
</dependencies>
Deploying the Model
Package the model as described in the Package the Model ScaleOut Digital Twin Builder topic.
Once the model has been packaged, deploy the model with the helper JavaActionHandler (located in the installation directory):
java -jar JavaActionHandler-3.2.10.jar -t deploy_dt_model -dt_model_name TestModel -file /path/to/TestModel.zip
Sending A Message
After deploying the model to ScaleOut StreamServer, you can send a message to an instance of a digital twin using the AppEndpoint
API. The AppEndpoint’s send
method signature can send a single message or multiple messages.
The following ‘Main’ demonstrates how to send a message to an instance with id “Twin_ID_23”:
public class Main {
public static void main(String[] args) throws Exception {
// send a message to model "MyDigitalTwin" with the ID "Twin_ID_23"
SendingResult result = AppEndpoint.send(
"MyDigitalTwin", // the model that will recieve this message
"Twin_ID_23", // the ID of the digital twin instance
"{\"myMessageType\":\"MyType\", // the message
\"incomingStringStateChange\":\"MyStringChange\",
\"incomingIntegerStateChange\":50,
\"timestamp\":1426325213}");
// validate the result
switch (result) {
case Handled:
System.out.println("StreamServer created a new instance of our DigitalTwin and the message was handled.");
break;
case NotHandled:
System.out.println("Message was not handled and no DigitalTwin was created.");
break;
}
}
}