private GenericFutureListener negotiationFutureListener;
public AsyncSshHandler(final AuthenticationHandler authenticationHandler, final SshClient sshClient,
- final Future<?> negotiationFuture) throws IOException {
+ final Future<?> negotiationFuture) {
this(authenticationHandler, sshClient);
this.negotiationFuture = negotiationFuture;
}
*
* @param authenticationHandler authentication handler
* @param sshClient started SshClient
- * @throws IOException if the I/O operation fails
*/
public AsyncSshHandler(final AuthenticationHandler authenticationHandler,
- final SshClient sshClient) throws IOException {
+ final SshClient sshClient) {
this.authenticationHandler = Preconditions.checkNotNull(authenticationHandler);
this.sshClient = Preconditions.checkNotNull(sshClient);
}
- public static AsyncSshHandler createForNetconfSubsystem(final AuthenticationHandler authenticationHandler)
- throws IOException {
+ public static AsyncSshHandler createForNetconfSubsystem(final AuthenticationHandler authenticationHandler) {
return new AsyncSshHandler(authenticationHandler, DEFAULT_CLIENT);
}
* @param authenticationHandler authentication handler
* @param negotiationFuture negotiation future
* @return {@code AsyncSshHandler}
- * @throws IOException if the I/O operation fails
*/
public static AsyncSshHandler createForNetconfSubsystem(final AuthenticationHandler authenticationHandler,
- final Future<?> negotiationFuture) throws IOException {
+ final Future<?> negotiationFuture) {
return new AsyncSshHandler(authenticationHandler, DEFAULT_CLIENT, negotiationFuture);
}
session = future.getSession();
final AuthFuture authenticateFuture = authenticationHandler.authenticate(session);
+ final ClientSession localSession = session;
authenticateFuture.addListener(future1 -> {
if (future1.isSuccess()) {
- handleSshAuthenticated(session, ctx);
+ handleSshAuthenticated(localSession, ctx);
} else {
// Exception does not have to be set in the future, add simple exception in such case
final Throwable exception = future1.getException() == null
// TODO we should also read from error stream and at least log from that
+ ClientChannel localChannel = channel;
sshReadAsyncListener = new AsyncSshHandlerReader(() -> AsyncSshHandler.this.disconnect(ctx, ctx.newPromise()),
- msg -> ctx.fireChannelRead(msg), channel.toString(), channel.getAsyncOut());
+ ctx::fireChannelRead, localChannel.toString(), localChannel.getAsyncOut());
// if readAsyncListener receives immediate close,
// it will close this handler and closing this handler sets channel variable to null
this.connectPromise = promise;
if (negotiationFuture != null) {
-
negotiationFutureListener = future -> {
if (future.isSuccess()) {
- connectPromise.setSuccess();
+ promise.setSuccess();
}
};
//complete connection promise with netconf negotiation future
}
@Override
- public void close(final ChannelHandlerContext ctx, final ChannelPromise promise) throws Exception {
+ public void close(final ChannelHandlerContext ctx, final ChannelPromise promise) {
disconnect(ctx, promise);
}
if (session != null && !session.isClosed() && !session.isClosing()) {
session.close(false).addListener(future -> {
- if (!future.isClosed()) {
- session.close(true);
+ synchronized (this) {
+ if (!future.isClosed()) {
+ session.close(true);
+ }
+ session = null;
}
- session = null;
});
}