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 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
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
-
Field Summary
Fields inherited from interface org.openhab.core.events.EventSubscriber
ALL_EVENT_TYPES
-
Constructor Summary
ConstructorDescriptionSitemapSubscriptionService
(Map<String, Object> config, ItemUIRegistry itemUIRegistry, org.osgi.framework.BundleContext bundleContext) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addSitemapProvider
(SitemapProvider provider) void
@Nullable String
Creates a new subscription with the given id.protected void
boolean
Checks whether a subscription with a given id (still) exists.@Nullable String
Retrieves the current page id for a subscription.@Nullable String
getSitemapName
(String subscriptionId) Retrieves the current sitemap name for a subscription.Gets the event types to which the event subscriber is subscribed to.void
modelChanged
(String modelName, EventType type) Performs dispatch of all binding configs and fires allItemRegistryChangeListener
s ifmodelName
ends with "items".protected void
void
Callback method for receivingEvent
s from the openHAB event bus.protected void
removeSitemapProvider
(SitemapProvider provider) void
removeSubscription
(String subscriptionId) Removes an existing subscriptionvoid
Updates the subscription to send events for the provided page id.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.openhab.core.events.EventSubscriber
getEventFilter
-
Constructor Details
-
SitemapSubscriptionService
public SitemapSubscriptionService(Map<String, Object> config, ItemUIRegistry itemUIRegistry, 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
-
setPageId
Updates the subscription to send events for the provided page id.- Parameters:
subscriptionId
- the subscription to updatesitemapName
- the current sitemap namepageId
- the current page id
-
modelChanged
Description copied from interface:ModelRepositoryChangeListener
Performs dispatch of all binding configs and fires allItemRegistryChangeListener
s ifmodelName
ends with "items".- Specified by:
modelChanged
in interfaceModelRepositoryChangeListener
-
checkAliveClients
public void checkAliveClients() -
getSubscribedEventTypes
Description copied from interface:EventSubscriber
Gets the event types to which the event subscriber is subscribed to.- Specified by:
getSubscribedEventTypes
in interfaceEventSubscriber
- Returns:
- subscribed event types (not null)
-
receive
Description copied from interface:EventSubscriber
Callback method for receivingEvent
s 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 interfaceEventSubscriber
- Parameters:
event
- the received event (not null)
-