X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-ssh%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fnetty%2FEchoClient.java;h=bdaee7957d277ef7bff5c9aafb81e1e0fcd85cb5;hp=5d0c71aa62e0e05d57768c320367b690a50395a3;hb=462f9ceb7da71750eead2a15f47e6229980954ad;hpb=022c6b13e92d53db58fbcb3d754e3164357030b8 diff --git a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/EchoClient.java b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/EchoClient.java index 5d0c71aa62..bdaee7957d 100644 --- a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/EchoClient.java +++ b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/EchoClient.java @@ -25,29 +25,36 @@ import org.slf4j.LoggerFactory; * traffic between the echo client and server by sending the first message to * the server. */ -public class EchoClient implements Runnable { - private static final Logger logger = LoggerFactory.getLogger(EchoClient.class); +public class EchoClient extends Thread { + private static final Logger LOG = LoggerFactory.getLogger(EchoClient.class); - private final ChannelHandler clientHandler; + private final ChannelInitializer channelInitializer; - public EchoClient(ChannelHandler clientHandler) { - this.clientHandler = clientHandler; + + public EchoClient(final ChannelHandler clientHandler) { + channelInitializer = new ChannelInitializer() { + @Override + public void initChannel(LocalChannel ch) throws Exception { + ch.pipeline().addLast(clientHandler); + } + }; + } + + public EchoClient(ChannelInitializer channelInitializer) { + this.channelInitializer = channelInitializer; } + @Override public void run() { // Configure the client. EventLoopGroup group = new NioEventLoopGroup(); try { Bootstrap b = new Bootstrap(); + b.group(group) .channel(LocalChannel.class) - .handler(new ChannelInitializer() { - @Override - public void initChannel(LocalChannel ch) throws Exception { - ch.pipeline().addLast(clientHandler); - } - }); + .handler(channelInitializer); // Start the client. LocalAddress localAddress = new LocalAddress("foo"); @@ -56,11 +63,11 @@ public class EchoClient implements Runnable { // Wait until the connection is closed. f.channel().closeFuture().sync(); } catch (Exception e) { - logger.error("Error in client", e); + LOG.error("Error in client", e); throw new RuntimeException("Error in client", e); } finally { // Shut down the event loop to terminate all threads. - logger.info("Client is shutting down"); + LOG.info("Client is shutting down"); group.shutdownGracefully(); } }