Package org.openhab.core.io.rest.sitemap
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 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.- Author:
- Kai Kreuzer - Initial contribution
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface -
Field Summary
Fields inherited from interface org.openhab.core.events.EventSubscriber
ALL_EVENT_TYPES -
Constructor Summary
ConstructorsConstructorDescriptionSitemapSubscriptionService(Map<String, Object> config, ItemUIRegistry itemUIRegistry, TimeZoneProvider timeZoneProvider, org.osgi.framework.BundleContext bundleContext) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSitemapProvider(SitemapProvider provider) voidorg.eclipse.emf.common.util.EList<Widget> collectWidgets(String sitemapName, @Nullable String pageId) @Nullable StringCreates a new subscription with the given id.protected voidbooleanChecks whether a subscription with a given id (still) exists.@Nullable StringRetrieves the current page id for a subscription.@Nullable StringgetSitemapName(String subscriptionId) Retrieves the current sitemap name for a subscription.Gets the event types to which the event subscriber is subscribed to.voidmodelChanged(String modelName, EventType type) Performs dispatch of all binding configs and fires allItemRegistryChangeListeners ifmodelNameends with "items".protected voidvoidCallback method for receivingEvents from the openHAB event bus.voidremoveSitemapProvider(SitemapProvider provider) voidremoveSubscription(String subscriptionId) Removes an existing subscriptionvoidupdateSubscriptionLocation(String subscriptionId, String sitemapName, @Nullable String pageId) Updates the subscription to send events for the provided page id (or whole sitemap ifpageIdis null).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.openhab.core.events.EventSubscriber
getEventFilter
-
Constructor Details
-
SitemapSubscriptionService
public SitemapSubscriptionService(Map<String, Object> config, ItemUIRegistry itemUIRegistry, TimeZoneProvider timeZoneProvider, org.osgi.framework.BundleContext bundleContext)
-
-
Method Details
-
deactivate
protected void deactivate() -
modified
-
addSitemapProvider
-
removeSitemapProvider
-
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
Removes an existing subscription- Parameters:
subscriptionId- the id of the subscription to remove
-
exists
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
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
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
-
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 ifpageIdis null).- Parameters:
subscriptionId- the subscription to updatesitemapName- the current sitemap namepageId- the current page id or null for whole sitemap subscription
-
collectWidgets
-
modelChanged
Description copied from interface:ModelRepositoryChangeListenerPerforms dispatch of all binding configs and fires allItemRegistryChangeListeners ifmodelNameends with "items".- Specified by:
modelChangedin interfaceModelRepositoryChangeListener
-
checkAliveClients
public void checkAliveClients() -
getSubscribedEventTypes
Description copied from interface:EventSubscriberGets the event types to which the event subscriber is subscribed to.- Specified by:
getSubscribedEventTypesin interfaceEventSubscriber- Returns:
- subscribed event types (not null)
-
receive
Description copied from interface:EventSubscriberCallback method for receivingEvents 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:
receivein interfaceEventSubscriber- Parameters:
event- the received event (not null)
-