Class ProcessingContext<T extends DigitalTwinBase<T>>
java.lang.Object
com.scaleoutsoftware.digitaltwin.abstractions.ProcessingContext<T>
- Type Parameters:
T- the type of the digital twin
- All Implemented Interfaces:
Serializable
public abstract class ProcessingContext<T extends DigitalTwinBase<T>>
extends Object
implements Serializable
Context object that allows the user to send a message to a DataSource.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract AzureDigitalTwinsProviderReturns anAzureDigitalTwinsProvideror null if no AzureDigitalTwinsProvider configuration can be found.abstract DateRetrieves the current time.abstract StringRetrieve the unique Identifier for a DataSource (matches the Device/Datasource/Real-time twin ID)abstract StringRetrieve the model for a DigitalTwin (matches the model of a Device/Datasource/real-time twin)abstract SharedDataRetrieve aSharedDataaccessor for globally shared data.abstract SharedDataRetrieve aSharedDataaccessor for this model's shared data.abstract SimulationControllerRetrieve the runningSimulationControlleror null if no simulation is running.abstract CompletableFuture<Void> logMessage(Level severity, String message) Log a message to the real-time digital twin UI.abstract CompletableFuture<DeleteResult> removeRealTimeTwin(String targetTwinModel, String targetTwinId) Delete the target real-time twin instance.abstract CompletableFuture<Void> sendAlert(AlertMessage alert) This method sends an alert message to configured systems.abstract CompletableFuture<SendingResult> sendToDataSource(byte[] payload) Sends a message to a data source.abstract CompletableFuture<SendingResult> sendToDigitalTwin(String model, String id, byte[] payload) This method sends a serialized JSON message to a real-time digital twinabstract TimerActionResultstartTimer(String timerName, Duration interval, TimerType timerType, TimerHandler<T> timerHandler, Class<? extends TimerHandler<T>> timerHandlerClass) Starts a new timer for the digital twinabstract TimerActionResultStops the specified timer.
-
Constructor Details
-
ProcessingContext
public ProcessingContext()Default constructor.
-
-
Method Details
-
sendToDataSource
Sends a message to a data source. This will route messages through the connector back to the data source.
if the datasource is simulation instance, then the message will be sent to the simulation model's implementation of the
MessageProcessor.- Parameters:
payload- the message (as a serialized JSON string)- Returns:
- the sending result
-
sendToDigitalTwin
public abstract CompletableFuture<SendingResult> sendToDigitalTwin(String model, String id, byte[] payload) This method sends a serialized JSON message to a real-time digital twin
Note, the message contents must be serialized so that the registered message type of the digital twin model will be sufficient to deserialize the message.
- Parameters:
model- the model of the digital twinid- the id of the digital twinpayload- the serialized JSON message- Returns:
- the sending result
-
sendAlert
This method sends an alert message to configured systems.
If the message cannot be sent then the returned CompletableFuture will complete exceptionally.
- Parameters:
alert- the alert message.- Returns:
- the sending result.
-
getAzureDigitalTwinsProvider
Returns anAzureDigitalTwinsProvideror null if no AzureDigitalTwinsProvider configuration can be found.- Returns:
- a
AzureDigitalTwinsProvideror null.
-
getDataSourceId
Retrieve the unique Identifier for a DataSource (matches the Device/Datasource/Real-time twin ID)- Returns:
- the digital twin id
-
getDigitalTwinModel
Retrieve the model for a DigitalTwin (matches the model of a Device/Datasource/real-time twin)- Returns:
- the digital twin model
-
logMessage
Log a message to the real-time digital twin UI. Note: the only supported severity levels are: INFO, WARN, and SEVERE- Parameters:
severity- the severity of the log messagemessage- the message to log- Returns:
- A future that will complete successfully with no result or exceptionally.
-
removeRealTimeTwin
public abstract CompletableFuture<DeleteResult> removeRealTimeTwin(String targetTwinModel, String targetTwinId) Delete the target real-time twin instance.- Parameters:
targetTwinModel- the model of the real-time twin instancetargetTwinId- the id of the real-time twin instance- Returns:
- a completable future that will complete with a
DeleteResultindicating the status of the operation, or exceptionally indicating that an error occurred.
-
startTimer
public abstract TimerActionResult startTimer(String timerName, Duration interval, TimerType timerType, TimerHandler<T> timerHandler, Class<? extends TimerHandler<T>> timerHandlerClass) Starts a new timer for the digital twin- Parameters:
timerName- the timer nameinterval- the timer intervaltimerType- the timer typetimerHandler- the time handler callbacktimerHandlerClass- the timer handler callback class- Returns:
- returns
TimerActionResult.Successif the timer was started,TimerActionResult.FailedTooManyTimersif too many timers exist, orTimerActionResult.FailedInternalErrorif an unexpected error occurs.
-
stopTimer
Stops the specified timer.- Parameters:
timerName- the timer name.- Returns:
- returns
TimerActionResult.Successif the timer was stopped,TimerActionResult.FailedNoSuchTimerif no timer exists with that name, orTimerActionResult.FailedInternalErrorif an unexpected error occurs.
-
getCurrentTime
Retrieves the current time. If the model (simulation or real-time) is running inside of a simulation then the simulation time will be returned.- Returns:
- The current time (real time, or simulation if running under simulation).
-
getSimulationController
Retrieve the runningSimulationControlleror null if no simulation is running.- Returns:
- the
SimulationControlleror null if no simulation is running.
-