it.wldt.adapter.mqtt.physical.topic.outgoing.DigitalTwinOutgoingTopic Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mqtt-physical-adapter Show documentation
Show all versions of mqtt-physical-adapter Show documentation
Physical adapter to connect with the MQTT protocol
The newest version!
package it.wldt.adapter.mqtt.physical.topic.outgoing;
import it.wldt.adapter.mqtt.physical.topic.MqttQosLevel;
import it.wldt.adapter.mqtt.physical.topic.MqttTopic;
import it.wldt.adapter.physical.event.PhysicalAssetActionWldtEvent;
/**
* Represents an MQTT topic for outgoing messages in the context of a Digital Twin.
* This class extends MqttTopic and provides functionality for handling outgoing messages
* with a specific publish function.
*
* @author Marco Picone, Ph.D. - [email protected], Marta Spadoni University of Bologna
*/
public class DigitalTwinOutgoingTopic extends MqttTopic {
/**
* The function used for publishing the data
*/
private final MqttPublishFunction publishFunction;
/**
* Constructs a DigitalTwinOutgoingTopic with the specified MQTT topic and a publish function.
*
* @param topic The MQTT topic associated with outgoing messages.
* @param publishFunction The function to generate the MQTT message payload from the outgoing event.
*/
public DigitalTwinOutgoingTopic(String topic, MqttPublishFunction publishFunction) {
super(topic);
this.publishFunction = publishFunction;
}
/**
* Constructs a DigitalTwinOutgoingTopic with the specified MQTT topic and a publish function.
*
* @param topic The MQTT topic associated with outgoing messages.
* @param mqttQosLevel The Quality of Service (QoS) level associated with the topic.
* @param isRetained The retained flag.
* @param publishFunction The function to generate the MQTT message payload from the outgoing event.
*/
public DigitalTwinOutgoingTopic(String topic, MqttQosLevel mqttQosLevel, boolean isRetained, MqttPublishFunction publishFunction) {
super(topic, mqttQosLevel, isRetained);
this.publishFunction = publishFunction;
}
/**
* Applies the publish function to generate the MQTT message payload from the provided
* PhysicalAssetActionWldtEvent.
*
* @param actionWldtEvent The event containing the action payload.
* @return The MQTT message payload generated by the publish function.
*/
public String applyPublishFunction(PhysicalAssetActionWldtEvent> actionWldtEvent){
return this.publishFunction.apply(actionWldtEvent);
}
/**
* Gets the publish function associated with this DigitalTwinOutgoingTopic.
*
* @return The publish function.
*/
public MqttPublishFunction getPublishFunction() {
return publishFunction;
}
}