Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

[Bose Soundtouch] Improved thing status check #5968

Conversation

alex-kostadinov
Copy link
Contributor

There is an issue that things representing BOSE SoundTouch players (SoundTouch 20 for example) don't go OFFLINE shortly after the ethernet or power cable is disconnected.

The reason is that doing session.getRemote().sendString("HELLO") does not promise that the remote party actually responds. This actually results in the fact that it takes random time for the thing to go OFFLINE (e.g. 20 minutes).

So, in order to reliably check the player's status, we PING the player by doing session.getRemote().sendPing() and make use of WebSocketFrameListener#onWebSocketFrame(Frame frame) which notifies about a received respective PONG. If two consecutively sent PINGs don't get a respective PONG, thing goes OFFLINE.

Copy link
Contributor

@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.

Thanks, I have left a few small comments.

@@ -76,6 +82,8 @@
private CommandExecutor commandExecutor;

private PresetContainer presetContainer;

private final Counter missedPongsCount = new Counter(MAX_MISSED_PONGS_COUNT);
Copy link
Contributor

Choose a reason for hiding this comment

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

I find it rather irritating that the "missed pongs" counter counts backwards. If it has value "2", the natural interpretation would imho be that we are missing 2 pongs already.
Wouldn't a simple int fully do the job here, starting at 0 and increasing it on every miss?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that a simple int would do the job and fit our purposes better.

this.session.getRemote().sendPing(null);
this.missedPongsCount.countDown();
} catch (IOException | NullPointerException | UnsupportedOperationException e) {
logger.warn("Sending websocket PING failed.");
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be no warning here, only debug.
Furthermore, the message only applies to the IOException and NullPointerException, while the UnsupportedOperationException actually means that we missed some pongs (but actually not for the ping that we just sent, right? So does that make sense here at all?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll change the debug and the try/catch behavior here together with the removal of the Counter.


public synchronized void countDown() {
if (currentValue == 0) {
throw new UnsupportedOperationException("Cannot count down below 0!");
Copy link
Contributor

Choose a reason for hiding this comment

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

UnsupportedOperationException seems an unsuitable choice here. IllegalStateException might be better, but imho simply removing this class and using an int as a counter and comparing it against the max would be much better readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agree.

…heck.

Signed-off-by: Alexander Kostadinov <alexander.g.kostadinov@gmail.com>
@alex-kostadinov alex-kostadinov force-pushed the feature/bose/implement-ws-ping-pong branch from c04c164 to 4269087 Compare July 30, 2018 10:29
@alex-kostadinov
Copy link
Contributor Author

@kaikreuzer Requested changes are pushed.

Copy link
Contributor

@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.

Thanks!

@kaikreuzer kaikreuzer merged commit fadc8ef into eclipse-archived:master Jul 30, 2018
@alex-kostadinov alex-kostadinov deleted the feature/bose/implement-ws-ping-pong branch July 31, 2018 04:14
Simiil pushed a commit to Simiil/smarthome that referenced this pull request Jul 31, 2018
…heck. (eclipse-archived#5968)

Signed-off-by: Alexander Kostadinov <alexander.g.kostadinov@gmail.com>
clinique pushed a commit to clinique/smarthome that referenced this pull request Sep 17, 2018
…heck. (eclipse-archived#5968)

Signed-off-by: Alexander Kostadinov <alexander.g.kostadinov@gmail.com>
@htreu htreu added this to the 0.10.0 milestone Oct 30, 2018
@kaikreuzer kaikreuzer changed the title Bose Soundtouch - Websocket PING/PONG mechanism for reliable thing status check [Bose Soundtouch] Improved thing status check Dec 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants