mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guillaume Nodet <gno...@apache.org>
Subject Re: how to tell if sshd ClientSession is closed
Date Wed, 30 Apr 2014 21:32:44 GMT
Sorry for that.  Feel free to raise a JIRA to add back a isClosed() method
or something similar.
As a workaround, one way would be to add a global session listener:

        client = SshClient.setUpDefaultClient();
        client.start();
        client.getSessionFactory().addListener(myListener);
        ...

The listener will be called whenever a session is closed, though you have
to maintain the state yourself.

A better option would be to subclass ClientSessionImpl and access the state
using

public class MyClientSessionImpl extends ClientSessionImpl {
  public isClosed() {
    return closeFuture.isClosed();
  }
  ...
}

You can then use your derived class using something like:

        client = SshClient.setUpDefaultClient();
        SessionFactory  factory = new SessionFactory() {
            @Override
            protected AbstractSession doCreateSession(IoSession ioSession)
throws Exception {
                return new MyClientSessionImpl(client, ioSession);
            }
        };
        factory.setClient(client);
        client.setSessionFactory(factory);
        client.start();

You can then use
    ((MyClientSessionImpl) session).isClosed()



2014-04-30 22:51 GMT+02:00 Darren Shepherd <darren.s.shepherd@gmail.com>:

> I'm upgrading from sshd-core 0.9.0 to 0.11.0 and previously there was
> a ClientSession.getState() method that I was using to tell if the
> session has been closed.  That method is gone now.  What can I use to
> tell if the ClientSession is open or closed?
>
> Darren
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message