Package org.openhab.core.thing.link
Class ItemChannelLinkRegistry
java.lang.Object
org.openhab.core.common.registry.AbstractRegistry<ItemChannelLink,String,ItemChannelLinkProvider>
org.openhab.core.thing.link.AbstractLinkRegistry<ItemChannelLink,ItemChannelLinkProvider>
org.openhab.core.thing.link.ItemChannelLinkRegistry
- All Implemented Interfaces:
ProviderChangeListener<ItemChannelLink>
,Registry<ItemChannelLink,
,String> RegistryChangeListener<Item>
,EventSubscriber
@NonNullByDefault
public class ItemChannelLinkRegistry
extends AbstractLinkRegistry<ItemChannelLink,ItemChannelLinkProvider>
implements RegistryChangeListener<Item>, EventSubscriber
- Author:
- Dennis Nobel - Initial contribution, Markus Rathgeb - Linked items returns only existing items, Markus Rathgeb - Rewrite collection handling to improve performance, Andrew Fiddian-Green - Apply channel default tags to items
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields inherited from interface org.openhab.core.events.EventSubscriber
ALL_EVENT_TYPES
-
Constructor Summary
ConstructorsConstructorDescriptionItemChannelLinkRegistry
(@Nullable Map<String, @Nullable Object> configuration, ThingRegistry thingRegistry, ItemRegistry itemRegistry, ItemBuilderFactory itemBuilderFactory, org.osgi.framework.BundleContext bundleContext) -
Method Summary
Modifier and TypeMethodDescriptionvoid
If a new item is added to the item registry and we already have prior "pre- orphaned" links to it, then update the tags from the default tags of the prior linked channels.protected void
getBoundChannels
(String itemName) Returns a set of bound channels for the given item name.getBoundThings
(String itemName) Returns a set of bound things for the given item name.getLinkedItemNames
(UID uid) Returns the item names, which are bound to the given UID.getLinkedItems
(UID uid) Returns a set of bound items for the given channel UID.Get all orphan links (item or channel missing)Subscribe to system start level events.protected void
protected void
protected void
protected void
notifyListenersAboutUpdatedElement
(ItemChannelLink oldElement, ItemChannelLink element) int
purge()
Remove all orphaned (item or channel missing) links that are editablevoid
Re-initialize (one off) all the channel default tags when startup is complete.void
If the item has gone then clear the 'tagsLinked' flag.int
removeLinksForItem
(String itemName) Remove all links related to an itemint
removeLinksForThing
(ThingUID thingUID) Remove all links related to a thingprotected void
setEventPublisher
(EventPublisher eventPublisher) protected void
protected void
setReadyService
(ReadyService readyService) protected void
unsetEventPublisher
(EventPublisher eventPublisher) protected void
protected void
unsetReadyService
(ReadyService readyService) void
Either this class applied channel default tags to the item, or something else updated the item (including possibly updating its tags), so in any case do NOT try to re-apply the channel default tags.Methods inherited from class org.openhab.core.thing.link.AbstractLinkRegistry
getLinks, getLinks, isLinked, isLinked, isLinked, onAddElement, onRemoveElement, onUpdateElement
Methods inherited from class org.openhab.core.common.registry.AbstractRegistry
activate, add, added, addProvider, addRegistryChangeListener, beforeUpdateElement, forEach, forEach, forEach, get, getAll, getEventPublisher, getManagedProvider, getProvider, getProvider, getValueAndProvider, notifyListeners, notifyListeners, postEvent, remove, removed, removeProvider, removeRegistryChangeListener, setManagedProvider, stream, unsetManagedProvider, update, updated, waitForCompletedAsyncActivationTasks
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
-
Field Details
-
USE_TAGS
- See Also:
-
-
Constructor Details
-
ItemChannelLinkRegistry
public ItemChannelLinkRegistry(@Nullable Map<String, @Nullable Object> configuration, ThingRegistry thingRegistry, ItemRegistry itemRegistry, ItemBuilderFactory itemBuilderFactory, org.osgi.framework.BundleContext bundleContext)
-
-
Method Details
-
modified
-
deactivate
protected void deactivate()- Overrides:
deactivate
in classAbstractRegistry<ItemChannelLink,
String, ItemChannelLinkProvider>
-
getBoundChannels
Returns a set of bound channels for the given item name.- Parameters:
itemName
- item name- Returns:
- an unmodifiable set of bound channels for the given item name
-
getLinkedItemNames
Description copied from class:AbstractLinkRegistry
Returns the item names, which are bound to the given UID.- Overrides:
getLinkedItemNames
in classAbstractLinkRegistry<ItemChannelLink,
ItemChannelLinkProvider> - Parameters:
uid
- UID- Returns:
- a non-null unmodifiable collection of item names that are linked to the given UID.
-
getLinkedItems
Returns a set of bound items for the given channel UID.- Parameters:
uid
- channel UID- Returns:
- an unmodifiable set of bound items for the given channel UID
-
getBoundThings
Returns a set of bound things for the given item name.- Parameters:
itemName
- item name- Returns:
- an unmodifiable set of bound things for the given item name
-
setManagedProvider
-
unsetManagedProvider
-
setEventPublisher
- Overrides:
setEventPublisher
in classAbstractRegistry<ItemChannelLink,
String, ItemChannelLinkProvider>
-
setReadyService
- Overrides:
setReadyService
in classAbstractRegistry<ItemChannelLink,
String, ItemChannelLinkProvider>
-
unsetReadyService
- Overrides:
unsetReadyService
in classAbstractRegistry<ItemChannelLink,
String, ItemChannelLinkProvider>
-
unsetEventPublisher
- Overrides:
unsetEventPublisher
in classAbstractRegistry<ItemChannelLink,
String, ItemChannelLinkProvider>
-
removeLinksForThing
Remove all links related to a thing- Parameters:
thingUID
- the UID of the thing- Returns:
- the number of removed links
-
removeLinksForItem
Remove all links related to an item- Parameters:
itemName
- the name of the item- Returns:
- the number of removed links
-
purge
public int purge()Remove all orphaned (item or channel missing) links that are editable- Returns:
- the number of removed links
- See Also:
-
getOrphanLinks
Get all orphan links (item or channel missing)- Returns:
- a map with orphan links as key and reason they are broken as value
- See Also:
-
notifyListenersAboutAddedElement
- Overrides:
notifyListenersAboutAddedElement
in classAbstractRegistry<ItemChannelLink,
String, ItemChannelLinkProvider>
-
notifyListenersAboutRemovedElement
- Overrides:
notifyListenersAboutRemovedElement
in classAbstractRegistry<ItemChannelLink,
String, ItemChannelLinkProvider>
-
notifyListenersAboutUpdatedElement
protected void notifyListenersAboutUpdatedElement(ItemChannelLink oldElement, ItemChannelLink element) - Overrides:
notifyListenersAboutUpdatedElement
in classAbstractRegistry<ItemChannelLink,
String, ItemChannelLinkProvider>
-
added
If a new item is added to the item registry and we already have prior "pre- orphaned" links to it, then update the tags from the default tags of the prior linked channels.- Specified by:
added
in interfaceRegistryChangeListener<Item>
- Parameters:
item
- the element that has been added
-
removed
If the item has gone then clear the 'tagsLinked' flag.- Specified by:
removed
in interfaceRegistryChangeListener<Item>
- Parameters:
item
- the element that has been removed
-
updated
Either this class applied channel default tags to the item, or something else updated the item (including possibly updating its tags), so in any case do NOT try to re-apply the channel default tags. Since that might cause an infinite loop.- Specified by:
updated
in interfaceRegistryChangeListener<Item>
- Parameters:
oldItem
- the element that has been updateditem
- the new element
-
getSubscribedEventTypes
Subscribe to system start level events.- Specified by:
getSubscribedEventTypes
in interfaceEventSubscriber
- Returns:
- subscribed event types (not null)
-
receive
Re-initialize (one off) all the channel default tags when startup is complete.- Specified by:
receive
in interfaceEventSubscriber
- Parameters:
event
- the received event (not null)
-