it.wldt.adapter.mqtt.physical.topic.incoming.PropertyIncomingTopic 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.incoming;
import it.wldt.adapter.physical.event.PhysicalAssetPropertyWldtEvent;
import it.wldt.exception.EventBusException;
import java.util.Collections;
import java.util.function.Function;
/**
* Represents an MQTT topic for incoming property updates in the context of a Digital Twin.
* This class extends DigitalTwinIncomingTopic and provides specialized functionality
* for handling property updates with a specific key and payload type.
*
* @param The type of the payload associated with the property.
* @author Marco Picone, Ph.D. - [email protected], Marta Spadoni University of Bologna
*/
public class PropertyIncomingTopic extends DigitalTwinIncomingTopic {
/**
* Constructs a PropertyIncomingTopic with the specified MQTT topic, property key,
* and a function to convert the MQTT message payload into the property value.
*
* @param topic The MQTT topic associated with incoming property updates.
* @param propertyKey The key of the property.
* @param propertyValueProducer A function to convert the MQTT message payload into the property value.
*/
public PropertyIncomingTopic(String topic, String propertyKey, Function propertyValueProducer) {
super(topic, topicMsgPayload -> {
try {
return Collections.singletonList(new PhysicalAssetPropertyWldtEvent<>(propertyKey, propertyValueProducer.apply(topicMsgPayload)));
} catch (EventBusException e) {
e.printStackTrace();
}
return null;
});
}
}