All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.wldt.adapter.mqtt.physical.topic.incoming.EventIncomingTopic Maven / Gradle / Ivy

The newest version!
package it.wldt.adapter.mqtt.physical.topic.incoming;

import it.wldt.adapter.physical.event.PhysicalAssetEventWldtEvent;
import it.wldt.exception.EventBusException;

import java.util.Collections;
import java.util.function.Function;

/**
 * Represents an MQTT topic for incoming events in the context of a Digital Twin.
 * This class extends DigitalTwinIncomingTopic and provides specialized functionality
 * for handling events with a specific key and payload type.
 *
 * @param  The type of the payload associated with the event.
 * @author Marco Picone, Ph.D. - [email protected], Marta Spadoni University of Bologna
 */
public class EventIncomingTopic extends DigitalTwinIncomingTopic {

    /**
     * Constructs an EventIncomingTopic with the specified MQTT topic, event key, and a function
     * to produce the event body from the MQTT message payload.
     *
     * @param topic              The MQTT topic associated with incoming events.
     * @param eventKey           The key associated with the incoming event.
     * @param eventBodyProducer  A function to produce the event body from the MQTT message payload.
     */
    public EventIncomingTopic(String topic, String eventKey, FunctioneventBodyProducer) {
        super(topic, topicMsgPayload -> {
            try {
                return Collections.singletonList(new PhysicalAssetEventWldtEvent<>(eventKey, eventBodyProducer.apply(topicMsgPayload)));
            } catch (EventBusException e) {
                e.printStackTrace();
            }
            return null;
        } );
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy