Class AbstractTypedEventSubscriber<T extends Event>

  • Type Parameters:
    T - The specific event type this class subscribes to.
    All Implemented Interfaces:
    EventSubscriber
    Direct Known Subclasses:
    ThingLinkManager

    @NonNullByDefault
    public abstract class AbstractTypedEventSubscriber<T extends Event>
    extends Object
    implements EventSubscriber
    The AbstractTypedEventSubscriber is an abstract implementation of the EventSubscriber interface which helps to subscribe to a specific event type. To receive an event - casted to the specific event type - the #receiveTypedEvent(T) method must be implemented. This implementation provides no event filter. To filter events based on the topic or some content the getEventFilter() method can be overridden.
    Author:
    Stefan Bußweiler - Initial contribution
    • Constructor Detail

      • AbstractTypedEventSubscriber

        protected AbstractTypedEventSubscriber​(String eventType)
        Constructs a new typed event subscriber. Must be called in the subclass.
        Parameters:
        eventType - the event type
    • Method Detail

      • getEventFilter

        public @Nullable EventFilter getEventFilter()
        Description copied from interface: EventSubscriber
        Gets an EventFilter in order to receive specific events if the filter applies. If there is no filter all subscribed event types are received.
        Specified by:
        getEventFilter in interface EventSubscriber
        Returns:
        the event filter, or null
      • receive

        public void receive​(Event event)
        Description copied from interface: EventSubscriber
        Callback method for receiving Events from the openHAB event bus. This method is called for every event where the event subscriber is subscribed to and the event filter applies.
        Specified by:
        receive in interface EventSubscriber
        Parameters:
        event - the received event (not null)
      • receiveTypedEvent

        protected abstract void receiveTypedEvent​(T event)
        Callback method for receiving typed events of type T.
        Parameters:
        event - the received event