-
Notifications
You must be signed in to change notification settings - Fork 65
Fix resource leaking and make the code more testable #41
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
Conversation
@peterjhill please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is great. I added some comments. The main one is whether or not we should make the createNetconfSession a no-op, since it no longer seems to do anything interesting.
private int port; | ||
private int connectionTimeout; | ||
private int commandTimeout; | ||
private final JSch sshClient; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call making all these final
|
||
this.sshClient = new JSch(); | ||
this.sshClient = (sshClient != null) ? sshClient : new JSch(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love using ternary expressions..
@@ -189,8 +187,6 @@ private String createHelloRPC(List<String> capabilities) { | |||
*/ | |||
private NetconfSession createNetconfSession() throws NetconfException { | |||
if (!isConnected()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like we don't do anything interesting in this method anymore, now that you in line 138 do the
this.sshClient = (sshClient != null) ? sshClient : new JSch();
should we make the createNeconfSession a no-op and deprecate it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use createNetconfSession
in connect()
method and sshClient initialization is a different thing than session creation. no-op means no-operations, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ha! when i was looking at the github ui, it looked like the create netconf session method code ended below line 192.
got it!. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, yeah. GitHub sometimes is very confusing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
@ydnath looks good to me..
Thanks @Vladislav-Kisliy
@@ -189,8 +187,6 @@ private String createHelloRPC(List<String> capabilities) { | |||
*/ | |||
private NetconfSession createNetconfSession() throws NetconfException { | |||
if (!isConnected()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ha! when i was looking at the github ui, it looked like the create netconf session method code ended below line 192.
got it!. 👍
isConnected
method doesn't cover all cases. For example:If a device has opened the ssh port however doesn't have netconf subsystem, a connection gets stuck for a long period of time.