Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix item channel links not properly initialized #1634

Merged
merged 4 commits into from
Sep 24, 2020

Conversation

wborn
Copy link
Member

@wborn wborn commented Sep 10, 2020

I've tested the ChannelLinkNotifier by @splatch (#1385 (comment)) and it solves the channel linking issues for me.

I made a few small changes:

  • add @NonNullByDefault
  • tune logging
  • addRegistryChangeListener before notifying handlers to prevent events getting lost (if channels can be unlinked during this call synchronization may be necessary too)
  • removeRegistryChangeListener on @Deactivate

With the channels being properly linked, adding Things via the inbox and adding them to the model works a lot better. :-)

Fixes #1596

@wborn wborn requested a review from a team September 10, 2020 22:47
@wborn wborn added rebuild Triggers the Jenkins PR build and removed rebuild Triggers the Jenkins PR build labels Sep 10, 2020
@cweitkamp
Copy link
Contributor

Code Looks great. Thanks to both of you. To avoid future regressions do you think it is possible to add an integration test - in a simple way - for this feature?

@wborn
Copy link
Member Author

wborn commented Sep 11, 2020

I haven't added any tests because I first wanted to know from the other @openhab/core-maintainers if we still think this is the way to go (and it was getting late 😉).

@cweitkamp
Copy link
Contributor

As I said, I like it and I agree on it 😉.

@kaikreuzer
Copy link
Member

And I already stated in #1385 (comment) that I like it 😎 .

@wborn
Copy link
Member Author

wborn commented Sep 14, 2020

There may be issues with this implementation when you link multiple items to one thing channel. If you remove one of the links it will send a "channelUnlinked" event to the handler. Which may use the event to stop a channel update mechanism (polling).

I think the handler should only be informed of these changes if:

  • the number of linked items to the channel changed from 0 to at least 1 -> channelLinked
  • the number of linked items to the channel changed from at least 1 to 0 -> channelUnlinked

It looks like this may already have been an issue with the old implementation.

Similarly it will call "channelLinked" multiple times when the ChannelLinkNotifier is activated and there are several item channel links for the same thing channel.

Another improvement may be to use a scheduler for these events to reduce the impact of thing handlers hijacking threads for long running tasks. It was also used in the old implementation.

@splatch
Copy link
Contributor

splatch commented Sep 14, 2020

Another improvement may be to use a scheduler for these events to reduce the impact of thing handlers hijacking threads for long running tasks. It was also used in the old implementation.

Looking at issue and how it looks a like I believe that we should rather focus on keeping link identifier as part of notification. If we have channel linked which is related to link which have been just created or removed the divider is link and not channel.

There might be cases when binding wants to keep distinct subscriptions for each and every link due to let say latency or better concurrency. Letting binding developer decide how to handle above scenario is better than building an extra logic in framework notifier itself.

Best,
Łukasz

@wborn wborn force-pushed the fix-channel-linking branch from 28f2e42 to 3a315dd Compare September 15, 2020 10:37
@wborn
Copy link
Member Author

wborn commented Sep 15, 2020

I've now added some pretty decent integration test coverage as well.

@splatch adding such details would be breaking API changes and I was under the impression the details of links and items were hidden from handlers on purpose. But perhaps the other @openhab/core-maintainers can also comment on that.

@splatch
Copy link
Contributor

splatch commented Sep 17, 2020

adding such details would be breaking API changes and I was under the impression the details of links and items were hidden from handlers on purpose.

@wborn Given that this is one of less popular framework features coming next major release is great opportunity to introduce breaking change. If a whole intention is to keep handler unaware of items and links then idea of having link notifications in handler was wrong in first place.
Given that Link bridges Item together with Channel it seems to play key role in keeping both separated, yet it can't and shouldn't stay hidden or belong just to an item.

@kaikreuzer
Copy link
Member

I think the handler should only be informed of these changes if:
the number of linked items to the channel changed from 0 to at least 1 -> channelLinked
the number of linked items to the channel changed from at least 1 to 0 -> channelUnlinked

Yes, I fully agree.

the details of links and items were hidden from handlers on purpose

Correct. The purpose of these methods was only for the handler to know, whether a certain channel is at all in use as it might otherwise skip expensive internal operations or unnecessary communication.

@wborn
Copy link
Member Author

wborn commented Sep 19, 2020

After some more thoughts I think it might still be necessary to send "channelLinked" events for already linked channels. That may be the only way for newly linked items to receive the current channel state.

@wborn wborn force-pushed the fix-channel-linking branch from 6d0f49e to 3c002e3 Compare September 19, 2020 12:58
Fixes openhab#1596

Signed-off-by: Wouter Born <github@maindrain.net>
Signed-off-by: Wouter Born <github@maindrain.net>
* Send at most one channelLinked event per linked thing channel when activating ChannelLinkNotifier
* Send channelUnlinked event only if all items are unlinked

Signed-off-by: Wouter Born <github@maindrain.net>
Signed-off-by: Wouter Born <github@maindrain.net>
@wborn wborn force-pushed the fix-channel-linking branch from 86b8c47 to add33ad Compare September 19, 2020 15:38
@wborn wborn requested review from a team and removed request for a team September 23, 2020 07:03
@robnielsen
Copy link

robnielsen commented Sep 23, 2020

The Insteon binding relies on channelLinked and channelUnlinked methods to build the bridge between OH and the Insteon network. It was reported in the OH community that the Insteon binding isn't working with 3.0.0-shapshot . I was able to reproduce the same behavior with things defined in .things files and items defined in .items files, not the UI.

wborn added a commit to wborn/openhab-addons that referenced this pull request Sep 23, 2020
With these changes and working channelLink events (openhab/openhab-core#1634) the feed itest works again.

Signed-off-by: Wouter Born <github@maindrain.net>
wborn added a commit to wborn/openhab-addons that referenced this pull request Sep 23, 2020
With these changes and working channelLink events (openhab/openhab-core#1634) the feed itest works again.

Signed-off-by: Wouter Born <github@maindrain.net>
wborn added a commit to wborn/openhab-addons that referenced this pull request Sep 23, 2020
With these changes and working channelLink events (openhab/openhab-core#1634) the ntp itest works again.

Signed-off-by: Wouter Born <github@maindrain.net>
Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, many thanks!

@kaikreuzer kaikreuzer merged commit 2dd1a03 into openhab:master Sep 24, 2020
kaikreuzer pushed a commit to openhab/openhab-addons that referenced this pull request Sep 24, 2020
With these changes and working channelLink events (openhab/openhab-core#1634) the feed itest works again.

Signed-off-by: Wouter Born <github@maindrain.net>
kaikreuzer pushed a commit to openhab/openhab-addons that referenced this pull request Sep 24, 2020
With these changes and working channelLink events (openhab/openhab-core#1634) the ntp itest works again.

Signed-off-by: Wouter Born <github@maindrain.net>
@wborn wborn deleted the fix-channel-linking branch September 24, 2020 06:44
@wborn wborn added this to the 3.0 milestone Oct 6, 2020
marcfischerboschio pushed a commit to marcfischerboschio/openHABaddon that referenced this pull request Apr 20, 2022
With these changes and working channelLink events (openhab/openhab-core#1634) the feed itest works again.

Signed-off-by: Wouter Born <github@maindrain.net>
marcfischerboschio pushed a commit to marcfischerboschio/openHABaddon that referenced this pull request Apr 20, 2022
With these changes and working channelLink events (openhab/openhab-core#1634) the ntp itest works again.

Signed-off-by: Wouter Born <github@maindrain.net>
splatch pushed a commit to ConnectorIO/copybara-hab-core that referenced this pull request Jul 11, 2023
* Fix item channel links not properly initialized
* Add ChannelLinkNotifierOSGiTest
* Send at most one channelLinked event per linked thing channel when activating ChannelLinkNotifier
* Send channelUnlinked event only if all items are unlinked
* Use Registry stream instead of getAll

Fixes openhab#1596

Signed-off-by: Wouter Born <github@maindrain.net>
GitOrigin-RevId: 2dd1a03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Item channel links not properly initialized
5 participants