Class SitemapSubscriptionService

java.lang.Object
org.openhab.core.io.rest.sitemap.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 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 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

      protected void addSitemapProvider(SitemapProvider provider)
    • removeSitemapProvider

      protected void removeSitemapProvider(SitemapProvider provider)
    • createSubscription

      public @Nullable String createSubscription(SitemapSubscriptionService.SitemapSubscriptionCallback callback)
      Creates a new subscription with the given id.
      Parameters:
      callback - an instance that should receive the events
      Returns:
      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
      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 @Nullable 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 @Nullable 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
    • 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
      Returns:
      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
      Parameters:
      event - the received event (not null)