Class SitemapSubscriptionService

  • All Implemented Interfaces:
    EventSubscriber, ModelRepositoryChangeListener

    public class SitemapSubscriptionService
    extends Object
    implements ModelRepositoryChangeListener, EventSubscriber
    This is a service that provides the possibility to manage subscriptions to sitemaps. As such subscriptions are stateful, they need to be created and removed upon disposal. The subscription mechanism makes sure that only events for widgets of the currently active sitemap page are sent as events to the subscriber. For this to work correctly, the subscriber needs to make sure that setPageId is called whenever it switches to a new page.
    Kai Kreuzer - Initial contribution
    • Method Detail

      • deactivate

        protected void deactivate()
      • addSitemapProvider

        protected void addSitemapProvider​(SitemapProvider provider)
      • removeSitemapProvider

        protected void removeSitemapProvider​(SitemapProvider provider)
      • removeSubscription

        public void removeSubscription​(String subscriptionId)
        Removes an existing subscription
        subscriptionId - the id of the subscription to remove
      • exists

        public boolean exists​(String subscriptionId)
        Checks whether a subscription with a given id (still) exists.
        subscriptionId - the id of the subscription to check
        true, if it exists, false otherwise
      • getPageId

        public @Nullable String getPageId​(String subscriptionId)
        Retrieves the current page id for a subscription.
        subscriptionId - the subscription to get the page id for
        the id of the currently active page or null if no page is currently set for the subscription
      • getSitemapName

        public @Nullable String getSitemapName​(String subscriptionId)
        Retrieves the current sitemap name for a subscription.
        subscriptionId - the subscription to get the sitemap name for
        the name of the current sitemap or null if no sitemap is currently set for the subscription
      • setPageId

        public void setPageId​(String subscriptionId,
                              String sitemapName,
                              String pageId)
        Updates the subscription to send events for the provided page id.
        subscriptionId - the subscription to update
        sitemapName - the current sitemap name
        pageId - the current page id
      • checkAliveClients

        public void checkAliveClients()
      • 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
        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
        event - the received event (not null)