Interface Inbox
Inbox is a service interface providing a container for discovered Things
(e.g. found by a DiscoveryService) as DiscoveryResults.
A DiscoveryResult entry in this container is not a full configured Thing and therefore no
Thing exists for it. A DiscoveryResult can be marked to be ignored, so that a specific Thing
is not considered to get part of the system.
This container offers a listener registry for InboxListeners which are notified if a DiscoveryResult
is added, updated or removed.
- Author:
- Michael Grammling - Initial contribution, Laurent Garnier - Added parameter newThingId to method approve
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionadd(@Nullable DiscoveryResult result) Adds the specifiedDiscoveryResultto thisInboxand sends an ADDED event to any registeredInboxListener.voidaddInboxListener(@Nullable InboxListener listener) Adds anInboxListenerto the listeners' registry.@Nullable ThingCreates newThingand adds it to theThingRegistry.getAll()Returns allDiscoveryResults in thisInbox.booleanRemoves theDiscoveryResultassociated with the specifiedThingID from thisInboxand sends a REMOVED event to any registeredInboxListener.voidremoveInboxListener(@Nullable InboxListener listener) Removes anInboxListenerfrom the listeners' registry.voidsetFlag(ThingUID thingUID, @Nullable DiscoveryResultFlag flag) Sets the flag for a given thingUID result.
The flag signals e.g. if the result isDiscoveryResultFlag.NEWor has been marked asDiscoveryResultFlag.IGNORED.stream()Returns a stream of allDiscoveryResults in thisInbox.
-
Method Details
-
add
Adds the specifiedDiscoveryResultto thisInboxand sends an ADDED event to any registeredInboxListener.If there is already a
DiscoveryResultwith the sameThingID in thisInbox, the specifiedDiscoveryResultis synchronized with the existing one, while keeping theDiscoveryResultFlagand overriding the specific properties. In that case an UPDATED event is sent to any registeredInboxListener.This method returns silently, if the specified
DiscoveryResultisnull.- Parameters:
result- the discovery result to be added to this inbox (could be null)- Returns:
CompletableFuturefuture that completes totrueif the specified discovery result could be added or updated, otherwise tofalse
-
remove
Removes theDiscoveryResultassociated with the specifiedThingID from thisInboxand sends a REMOVED event to any registeredInboxListener.This method returns silently, if the specified
ThingID isnull, empty, invalid, or no associatedDiscoveryResultexists in thisInbox.- Parameters:
thingUID- the Thing UID pointing to the discovery result to be removed from this inbox (could be null or invalid)- Returns:
- true if the specified discovery result could be removed, otherwise false
-
getAll
List<DiscoveryResult> getAll()Returns allDiscoveryResults in thisInbox.- Returns:
- all discovery results in this inbox (not null, could be empty)
-
stream
Stream<DiscoveryResult> stream()Returns a stream of allDiscoveryResults in thisInbox.- Returns:
- stream of all discovery results in this inbox
-
setFlag
Sets the flag for a given thingUID result.
The flag signals e.g. if the result isDiscoveryResultFlag.NEWor has been marked asDiscoveryResultFlag.IGNORED. In the latter case the result object should be regarded as known by the system so that further processing should be skipped.If the specified flag is
null,DiscoveryResultFlag.NEWis set by default.- Parameters:
flag- the flag of the given thingUID result to be set (could be null)
-
addInboxListener
Adds anInboxListenerto the listeners' registry.When a
DiscoveryResultis ADDED, UPDATED or REMOVED, the specified listener is notified.This method returns silently if the specified listener is
nullor has already been registered before.- Parameters:
listener- the listener to be added (could be null)
-
removeInboxListener
Removes anInboxListenerfrom the listeners' registry.When this method returns, the specified listener is no longer notified about an ADDED, UPDATED or REMOVED
DiscoveryResult.This method returns silently if the specified listener is
nullor has not been registered before.- Parameters:
listener- the listener to be removed (could be null)
-
approve
Creates newThingand adds it to theThingRegistry.- Parameters:
thingUID- the UID of the Thinglabel- the label of the ThingnewThingId- the thing ID of the Thing to be created; if not null, it will replace the thing ID from parameter thingUID- Returns:
- the approved Thing
-