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.
    Author:
    Kai Kreuzer - Initial contribution
    • Constructor Detail

      • SitemapSubscriptionService

        public SitemapSubscriptionService()
    • Method Detail

      • deactivate

        protected void deactivate()
      • setItemUIRegistry

        protected void setItemUIRegistry​(ItemUIRegistry itemUIRegistry)
      • unsetItemUIRegistry

        protected void unsetItemUIRegistry​(ItemUIRegistry itemUIRegistry)
      • addSitemapProvider

        protected void addSitemapProvider​(SitemapProvider provider)
      • removeSitemapProvider

        protected void removeSitemapProvider​(SitemapProvider provider)
      • removeSubscription

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

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

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

        public String getSitemapName​(String subscriptionId)
        Retrieves the current sitemap name for a subscription.
        Parameters:
        subscriptionId - the subscription to get the sitemap name for
        Returns:
        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.
        Parameters:
        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
        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)