I've created SSHD-322, 323, and 324 regarding what was discussed in this
thread.

Thanks,
Darren


On Thu, May 1, 2014 at 1:32 AM, Guillaume Nodet <gno...@apache.org> wrote:

> 2014-04-30 23:51 GMT+02:00 Darren Shepherd <darren.s.sheph...@gmail.com>:
>
> > 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.
> >
>
> Right, that's missing.  Another side effect of a refactoring.
> I think we need to add a registerChannel() public method.  Feel free to
> raise a JIRA.
>
> Unfortunately, I don't see any good workaround for that, as we have too
> many private fields.
>
>
> >
> > 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?
> >
>
> I think there is one.
> If you subclass the ClientConnectionService and use it instead of the
> default one,
> it will receive the unregisterChannel() calls which means the channel have
> been closed.
>
> Please raise JIRA, I think we're missing a ChannelListener interface which
> would be easier to use.
>
>
> >
> > Darren
> >
> > On Wed, Apr 30, 2014 at 2:32 PM, Guillaume Nodet <gno...@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.sheph...@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
> > >>
> >
>

Reply via email to