I am using the SSH Ganymed library alias Trilead alias Orion.
I am trying to understand the exact behaviour of the session as I would need to keep an ssh connection opened for a long time (maybe for ever) and to close it just when my jvm goes down or something like this.
So, my problem is this. Assuming I do something like this:
Connection conn = new Connection(this.hostName, this.port);
conn.addConnectionMonitor(new ConnectionMonitor()
{
@Override
public void connectionLost(Throwable reason)
{
System.out.println("Connection Lost " reason.getMessage());
}
});
conn.connect(null, 1000, 20000);
conn.authenticateWithPublicKey(this.user, keyfile, this.password);
Thread.sleep(30000); //sleep the Thread for 30 seconds
Session sess = conn.openSession();
sess.execCommand("ls");
conn.close();
And, in those 30 seconds when the thread is sleeping, I disconnect my network interface for emulating a network issue.
1)The disconnect event is not intercepted by the connectionMonitor and the Connection Lost message is not printed 2)When
Session sess = conn.openSession();
is executed, the process blocks and nothing happens until i don't not connect the network interface again. This is because, looking at the Ganymed code, it seems that since the disconnection event is not detected the session is opened and there's a lock opening the session until it does succeed.
So my questions are: 1)Is this behaviour wanted or is this a bug? 2)Is there any way to set a timeout in Connection.openSession() method as well as the Connection.connect() method?
Thanks in advance.