mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Darren Shepherd <darren.s.sheph...@gmail.com>
Subject Re: how to tell if sshd ClientSession is closed
Date Wed, 30 Apr 2014 21:51:27 GMT
It looks like the listener will work just fine.

The next issue I ran into with upgrade between 0.9 and 0.11 is about
handling ChannelExec EOF and Close.  In 0.9 I subclassed ChannelExec
and then just registered the custom channel on the session.  It looks
like you can't directly register a custom channel anymore.

All I really need to do is listen for closed or eof on the
ChannelExec.  I found that if I run a remote command and that command
exits, the channel will close, but the session stays open.  In my
situation I need to close the session if the channel exec closes.

I really couldn't find anyway in the current API to handle close or
eof without calling waitFor().  I can't call waitFor because that is
blocking.  Previously I just extended the handleEof() method.

Is there a way to listen for eof and close on a Channel without blocking?


On Wed, Apr 30, 2014 at 2:32 PM, Guillaume Nodet <gnodet@apache.org> wrote:
> 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

View raw message