this.clientCapabilities = capabilities;
}
+ public long getConnectionTimeoutMillis() {
+ return connectionTimeoutMillis;
+ }
+
@Override
public NetconfClientSessionNegotiator getSessionNegotiator(
final NetconfSessionListenerFactory<NetconfClientSessionListener> sessionListenerFactory,
final Promise<NetconfClientSession> promise) {
ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
negotiatorFactory.getSessionNegotiator(() -> sessionListener, ch, promise));
+ ch.config().setConnectTimeoutMillis((int)negotiatorFactory.getConnectionTimeoutMillis());
}
}
import static org.mockito.Mockito.verify;
import io.netty.channel.Channel;
+import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelPipeline;
import io.netty.util.concurrent.Promise;
doReturn("").when(channel).toString();
doReturn(pipeline).when(pipeline).addFirst(any(ChannelHandler.class));
doReturn(pipeline).when(pipeline).addLast(anyString(), any(ChannelHandler.class));
+ ChannelConfig channelConfig = mock(ChannelConfig.class);
+ doReturn(channelConfig).when(channel).config();
+ doReturn(1L).when(negotiatorFactory).getConnectionTimeoutMillis();
+ doReturn(channelConfig).when(channelConfig).setConnectTimeoutMillis(1);
Promise<NetconfClientSession> promise = mock(Promise.class);
doReturn("").when(promise).toString();
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
-import io.netty.channel.ChannelOption;
import io.netty.util.concurrent.DefaultPromise;
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.Future;
if (this.address.isUnresolved()) {
this.address = new InetSocketAddress(this.address.getHostName(), this.address.getPort());
}
- this.bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout);
final ChannelFuture connectFuture = this.bootstrap.connect(this.address);
// Add listener that attempts reconnect by invoking this method again.
connectFuture.addListener(new BootstrapConnectListener());
import io.netty.util.concurrent.GenericFutureListener;
import java.io.IOException;
import java.net.SocketAddress;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.channel.ClientChannel;
private void startSsh(final ChannelHandlerContext ctx, final SocketAddress address) throws IOException {
LOG.debug("Starting SSH to {} on channel: {}", address, ctx.channel());
- final ConnectFuture sshConnectionFuture = sshClient.connect(authenticationHandler.getUsername(), address);
+ final ConnectFuture sshConnectionFuture = sshClient.connect(authenticationHandler.getUsername(), address)
+ .verify(ctx.channel().config().getConnectTimeoutMillis(), TimeUnit.MILLISECONDS);
sshConnectionFuture.addListener(future -> {
if (future.isConnected()) {
handleSshSessionCreated(future, ctx);
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
+import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop;
import java.io.IOException;
import java.net.SocketAddress;
+import java.util.concurrent.TimeUnit;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.channel.ChannelSubsystem;
import org.apache.sshd.client.channel.ClientChannel;
private SocketAddress localAddress;
@Mock
private EventLoop eventLoop;
+ @Mock
+ private ChannelConfig channelConfig;
private AsyncSshHandler asyncSshHandler;
}
}, MoreExecutors.directExecutor());
doReturn(connectFuture).when(sshClient).connect("usr", remoteAddress);
+ doReturn(channelConfig).when(channel).config();
+ doReturn(1).when(channelConfig).getConnectTimeoutMillis();
+ doReturn(connectFuture).when(connectFuture).verify(1,TimeUnit.MILLISECONDS);
}
@Test