GenericFutureListener<Future<NetconfClientSession>> negotiationFutureListener;
@Override
- public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress,
+ public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress,
+ final SocketAddress localAddress,
final ChannelPromise channelPromise) throws Exception {
connectPromise = channelPromise;
ChannelPromise tcpConnectFuture = new DefaultChannelPromise(ch);
negotiationFutureListener = future -> {
if (future.isSuccess()) {
- connectPromise.setSuccess();
+ channelPromise.setSuccess();
}
};
tcpConnectFuture.addListener(future -> {
- if(future.isSuccess()) {
+ if (future.isSuccess()) {
//complete connection promise with netconf negotiation future
negotiationFuture.addListener(negotiationFutureListener);
} else {
- connectPromise.setFailure(future.cause());
+ channelPromise.setFailure(future.cause());
}
});
ctx.connect(remoteAddress, localAddress, tcpConnectFuture);
@Override
public void disconnect(final ChannelHandlerContext ctx, final ChannelPromise promise) throws Exception {
- // If we have already succeeded and the session was dropped after, we need to fire inactive to notify reconnect logic
- if(connectPromise.isSuccess()) {
+ if (connectPromise == null) {
+ return;
+ }
+
+ // If we have already succeeded and the session was dropped after, we need to fire inactive to notify
+ // reconnect logic
+ if (connectPromise.isSuccess()) {
ctx.fireChannelInactive();
}
//If connection promise is not already set, it means negotiation failed
//we must set connection promise to failure
- if(!connectPromise.isDone()) {
+ if (!connectPromise.isDone()) {
connectPromise.setFailure(new IllegalStateException("Negotiation failed"));
}