Class SitemapSubscriptionService

All Implemented Interfaces:
EventSubscriber, ModelRepositoryChangeListener

@NonNullByDefault 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 or sitemap page are sent as events to the subscriber. For this to work correctly, the subscriber needs to make sure that updateSubscriptionLocation(java.lang.String, java.lang.String, java.lang.String) is called whenever it switches to a new page, unless a subscription for the whole sitemap is made. Subscribing to whole sitemaps is discouraged, since a large number of item updates may result in a high SSE traffic.
Kai Kreuzer - Initial contribution
  • Constructor Details

    • SitemapSubscriptionService

      public SitemapSubscriptionService(Map<String,Object> config, ItemUIRegistry itemUIRegistry, org.osgi.framework.BundleContext bundleContext)
  • Method Details

    • deactivate

      protected void deactivate()
    • modified

      protected void modified(Map<String,Object> config)
    • addSitemapProvider

      public void addSitemapProvider(SitemapProvider provider)
    • removeSitemapProvider

      public void removeSitemapProvider(SitemapProvider provider)
    • createSubscription

      public @Nullable String createSubscription(SitemapSubscriptionService.SitemapSubscriptionCallback callback)
      Creates a new subscription with the given id.
      callback - an instance that should receive the events
      a unique id that identifies the subscription or null if the limit of subscriptions is already reached
    • 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
    • updateSubscriptionLocation

      public void updateSubscriptionLocation(String subscriptionId, String sitemapName, @Nullable String pageId)
      Updates the subscription to send events for the provided page id (or whole sitemap if pageId is null).
      subscriptionId - the subscription to update
      sitemapName - the current sitemap name
      pageId - the current page id or null for whole sitemap subscription
    • collectWidgets

      public org.eclipse.emf.common.util.EList<Widget> collectWidgets(String sitemapName, @Nullable String pageId)
    • modelChanged

      public void modelChanged(String modelName, EventType type)
      Description copied from interface: ModelRepositoryChangeListener
      Performs dispatch of all binding configs and fires all ItemRegistryChangeListeners if modelName ends with "items".
      Specified by:
      modelChanged in interface ModelRepositoryChangeListener
    • checkAliveClients

      public void checkAliveClients()
    • getSubscribedEventTypes

      public Set<String> getSubscribedEventTypes()
      Description copied from interface: EventSubscriber
      Gets the event types to which the event subscriber is subscribed to.
      Specified by:
      getSubscribedEventTypes in interface EventSubscriber
      subscribed event types (not 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)