TimingProxyClientTcpTransportHandler extends TransportHandler implements ProxyableTransportHandler,
        TimeableTransportHandler { @Override public void initialize() throws IOException { controlSocket = new Socket(); controlSocket.connect(new InetSocketAddress(proxyControlHostName, proxyControlPort), (int) timeout); dataSocket = new Socket(); dataSocket.connect(new InetSocketAddress(proxyDataHostName, proxyDataPort), (int) timeout); if (!dataSocket.isConnected()) { throw new IOException("Could not connect to " + proxyDataHostName + ":" + proxyDataPort); } controlSocket.getOutputStream().write((hostname + "\n").getBytes()); controlSocket.getOutputStream().write((Integer.toString(port) + "\n").getBytes()); controlSocket.getOutputStream().flush(); setStreams(new PushbackInputStream(dataSocket.getInputStream()), dataSocket.getOutputStream()); } TimingProxyClientTcpTransportHandler(Connection connection);  TimingProxyClientTcpTransportHandler(long timeout, String hostname, int port); @Override byte[] fetchData(); @Override void setProxy(String dataChannelHost, int dataChanelPort, String controlChannelHost, int controlChanelPort); @Override void closeConnection(); @Override void initialize(); @Override boolean isClosed(); @Override void closeClientConnection(); SocketState getSocketState(); @Override Long getLastMeasurement();  }
@Test @Category(IntegrationTests.class) public void testInitialize() throws IOException { ServerSocketChannel serverSocketChannel = null; try { serverSocketChannel = ServerSocketChannel.open(); serverSocketChannel.socket().bind(new InetSocketAddress(0)); serverSocketChannel.configureBlocking(false); handler = new TimingProxyClientTcpTransportHandler(100, "127.0.0.1", serverSocketChannel.socket() .getLocalPort()); handler.setProxy("127.0.0.1", 4444, "127.0.0.1", 5555); handler.initialize(); SocketChannel acceptChannel = serverSocketChannel.accept(); assertNotNull(acceptChannel); assertTrue(handler.isInitialized()); } finally { if (serverSocketChannel != null) { try { serverSocketChannel.close(); } catch (IOException ex) { } } } }