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

Improved the reconnect behaviour of CULNetworkHandlerImpl #4359

Merged
merged 3 commits into from
Feb 16, 2017

Conversation

dereulenspiegel
Copy link
Contributor

This Pull Request addresses the issues described in #4035. I replaced the current implementation of CULNetworkHandlerImpl with a nio based one to simplify handling of connection errors.
To enable this change slight changes in other components of the CUL transport were necessary. Mainly the responsibility of low level communication is now in the respective handler implementations and not in the AbstractCULHandler any more.

@teichsta
Copy link
Member

teichsta commented May 9, 2016

great thanks @dereulenspiegel!

Could the other CUL users please have a look at this one please?

@cyclingengineer @querdenker2k @johgoe @tarioch

@teichsta teichsta added this to the 1.9.0 milestone May 9, 2016
@tarioch
Copy link
Contributor

tarioch commented May 9, 2016

Looks quite good, small suggestion, in CULSerialHandlerImpl, can you remove/make local is und os, they are never accessed directly so therefore they aren't needed.

… variables any more, since no one needs access to them.
@dereulenspiegel
Copy link
Contributor Author

InputStream and OutputStream aren't class variables any more.

@teichsta
Copy link
Member

can any of the others @cyclingengineer @querdenker2k @johgoe confirm this working?

if (bw == null) {
log.error("Can't write message, BufferedWriter is NULL");
}
synchronized (bw) {
Copy link
Contributor

@johgoe johgoe May 16, 2016

Choose a reason for hiding this comment

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

New implementation CULSerialHandlerImpl is not synchronized. What happens in parallel write message events?

@johgoe
Copy link
Contributor

johgoe commented May 16, 2016

@teichsta, @dereulenspiegel The normal good case with a CUL is working, but I'm not sure about the parallel and error cases. See my comments in the code.
I guess these features should also move from the base class AbstractCULHandler to the inherited class CULSerialHandlerImpl.

…tion and now trying to reopen connection on connection error
@dereulenspiegel
Copy link
Contributor Author

The serial connection part wasn't original part of my changes. It was merely touched because I changed the logic in AbstractCULHandler.
I know added synchronization to BufferedReader and BufferedWriter in the serial implementation and I am now trying to reopen the serial connection on connection errors. However I am not sure if this useful, since a serial connection is vastly different from a network connection on lower levels. My guess is, that every connection error in the serial connection won't be recoverable in software.

@9037568
Copy link
Contributor

9037568 commented Dec 4, 2016

Is there a consensus that this is ready to be merged? ( @dereulenspiegel @tarioch @johgoe @querdenker2k @cyclingengineer )

My review of the changes shows only that the source needs to be run through the eclipse formatter...

@johgoe
Copy link
Contributor

johgoe commented Dec 4, 2016

From my point of view, its ok to merge this.

@tarioch
Copy link
Contributor

tarioch commented Dec 5, 2016

Good from my side as well

* @since 1.5.0
*/
public class CULNetworkHandlerImpl extends AbstractCULHandler<CULNetworkConfig> {
public class CULNetworkHandlerImpl extends AbstractCULHandler<CULNetworkConfig>implements Runnable {
Copy link
Contributor

Choose a reason for hiding this comment

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

a lack of space before implements suggests the Eclipse IDE formatting wasn't applied or the settings are incorrect.


try {
synchronized (bw) {
if (bw == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can't synchronize on a null object. If there is a chance that bw is null, then this code should be changed (and anywhere else where X can be null and there is a synchronized (X) construct).

Copy link
Contributor

Choose a reason for hiding this comment

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

@watou, would you be ok with merging this PR as is if I submit a separate PR to address the formatting and null synchronization issues?

Copy link
Contributor

Choose a reason for hiding this comment

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

@9037568 fine with me. Should this and your follow-on PR target 1.9.1 or is that too risky?

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably enough change there to not call it a patch release. Let's call it 1.10.0.

@watou watou removed this from the 1.9.0 milestone Jan 21, 2017
@JSurf
Copy link
Contributor

JSurf commented Feb 14, 2017

I had a chance to test the pull request against my setup (cul connected to ser2net). It seems to work fine and recovers great from ser2net restarts

@9037568 9037568 added this to the 1.10.0 milestone Feb 15, 2017
@9037568 9037568 merged commit 27cd7ed into openhab:master Feb 16, 2017
9037568 added a commit to 9037568/openhab that referenced this pull request Feb 16, 2017
9037568 added a commit that referenced this pull request Feb 17, 2017
* Apply Eclipse formatting.

Enhancement for #4359.

* Various cleanup of log messages, including string concatenation and log
levels.

* Fix synchronization issues.

Shouldn't be synchronizing on objects that are about to be modified.
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.

7 participants