Java Code Examples for org.jboss.netty.channel.ChannelFuture#isDone()
The following examples show how to use
org.jboss.netty.channel.ChannelFuture#isDone() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestTSOChannelHandlerNetty.java From phoenix-omid with Apache License 2.0 | 5 votes |
@Test(timeOut = 10_000) public void testNettyChannelWriting() throws Exception { // ------------------------------------------------------------------------------------------------------------ // Prepare test // ------------------------------------------------------------------------------------------------------------ // Connect channel handler channelHandler.reconnect(); // Create client and connect it ClientBootstrap nettyClient = createNettyClientBootstrap(); ChannelFuture channelF = nettyClient.connect(new InetSocketAddress("localhost", 1434)); // Basic checks for connection while (!channelF.isDone()) /** do nothing */ ; assertTrue(channelF.isSuccess()); assertTrue(channelF.getChannel().isConnected()); Channel channel = channelF.getChannel(); // Eventually the channel group of the server should have 2 elements while (channelHandler.channelGroup.size() != 2) /** do nothing */ ; // Write first handshake request TSOProto.HandshakeRequest.Builder handshake = TSOProto.HandshakeRequest.newBuilder(); // NOTE: Add here the required handshake capabilities when necessary handshake.setClientCapabilities(TSOProto.Capabilities.newBuilder().build()); channelF.getChannel().write(TSOProto.Request.newBuilder().setHandshakeRequest(handshake.build()).build()); // ------------------------------------------------------------------------------------------------------------ // Test channel writing // ------------------------------------------------------------------------------------------------------------ testWritingTimestampRequest(channel); testWritingCommitRequest(channel); testWritingFenceRequest(channel); }
Example 2
Source File: NettyClientFactory.java From migration-tool with Apache License 2.0 | 5 votes |
public Client createClient(String targetIP, int targetPort, int connectTimeout) throws Exception { ClientBootstrap bootstrap = new ClientBootstrap(nioClient); bootstrap.setOption("tcpNoDelay", Boolean.parseBoolean(System.getProperty("nfs.rpc.tcp.nodelay", "true"))); bootstrap.setOption("reuseAddress", Boolean.parseBoolean(System.getProperty("nfs.rpc.tcp.reuseaddress", "true"))); if (connectTimeout < 1000) { bootstrap.setOption("connectTimeoutMillis", 1000); } else { bootstrap.setOption("connectTimeoutMillis", connectTimeout); } NettyClientHandler handler = new NettyClientHandler(this); bootstrap.setPipelineFactory(new NettyClientPipelineFactory(handler)); ChannelFuture future = bootstrap.connect(new InetSocketAddress(targetIP, targetPort)); future.awaitUninterruptibly(connectTimeout); if (!future.isDone()) { log.error("Create connection to " + targetIP + ":" + targetPort + " timeout!"); throw new Exception("Create connection to " + targetIP + ":" + targetPort + " timeout!"); } if (future.isCancelled()) { log.error("Create connection to " + targetIP + ":" + targetPort + " cancelled by user!"); throw new Exception("Create connection to " + targetIP + ":" + targetPort + " cancelled by user!"); } if (!future.isSuccess()) { log.error("Create connection to " + targetIP + ":" + targetPort + " error", future.getCause()); throw new Exception("Create connection to " + targetIP + ":" + targetPort + " error", future.getCause()); } NettyClient client = new NettyClient(future, connectTimeout); handler.setClient(client); return client; }
Example 3
Source File: TestTSOChannelHandlerNetty.java From phoenix-omid with Apache License 2.0 | 4 votes |
@Test(timeOut = 10_000) public void testNettyConnectionToTSOFromClient() throws Exception { ClientBootstrap nettyClient = createNettyClientBootstrap(); ChannelFuture channelF = nettyClient.connect(new InetSocketAddress("localhost", 1434)); // ------------------------------------------------------------------------------------------------------------ // Test the client can't connect cause the server is not there // ------------------------------------------------------------------------------------------------------------ while (!channelF.isDone()) /** do nothing */ ; assertFalse(channelF.isSuccess()); // ------------------------------------------------------------------------------------------------------------ // Test creation of a server connection // ------------------------------------------------------------------------------------------------------------ channelHandler.reconnect(); assertTrue(channelHandler.listeningChannel.isOpen()); // Eventually the channel group of the server should contain the listening channel assertEquals(channelHandler.channelGroup.size(), 1); // ------------------------------------------------------------------------------------------------------------ // Test that a client can connect now // ------------------------------------------------------------------------------------------------------------ channelF = nettyClient.connect(new InetSocketAddress("localhost", 1434)); while (!channelF.isDone()) /** do nothing */ ; assertTrue(channelF.isSuccess()); assertTrue(channelF.getChannel().isConnected()); // Eventually the channel group of the server should have 2 elements while (channelHandler.channelGroup.size() != 2) /** do nothing */ ; // ------------------------------------------------------------------------------------------------------------ // Close the channel on the client side and test we have one element less in the channel group // ------------------------------------------------------------------------------------------------------------ channelF.getChannel().close().await(); // Eventually the channel group of the server should have only one element while (channelHandler.channelGroup.size() != 1) /** do nothing */ ; // ------------------------------------------------------------------------------------------------------------ // Open a new channel and test the connection closing on the server side through the channel handler // ------------------------------------------------------------------------------------------------------------ channelF = nettyClient.connect(new InetSocketAddress("localhost", 1434)); while (!channelF.isDone()) /** do nothing */ ; assertTrue(channelF.isSuccess()); // Eventually the channel group of the server should have 2 elements again while (channelHandler.channelGroup.size() != 2) /** do nothing */ ; channelHandler.closeConnection(); assertFalse(channelHandler.listeningChannel.isOpen()); assertEquals(channelHandler.channelGroup.size(), 0); // Wait some time and check the channel was closed TimeUnit.SECONDS.sleep(1); assertFalse(channelF.getChannel().isOpen()); // ------------------------------------------------------------------------------------------------------------ // Test server re-connections with connected clients // ------------------------------------------------------------------------------------------------------------ // Connect first time channelHandler.reconnect(); assertTrue(channelHandler.listeningChannel.isOpen()); // Eventually the channel group of the server should contain the listening channel assertEquals(channelHandler.channelGroup.size(), 1); // Check the client can connect channelF = nettyClient.connect(new InetSocketAddress("localhost", 1434)); while (!channelF.isDone()) /** do nothing */ ; assertTrue(channelF.isSuccess()); // Eventually the channel group of the server should have 2 elements while (channelHandler.channelGroup.size() != 2) /** do nothing */ ; // Re-connect and check that client connection was gone channelHandler.reconnect(); assertTrue(channelHandler.listeningChannel.isOpen()); // Eventually the channel group of the server should contain the listening channel assertEquals(channelHandler.channelGroup.size(), 1); // Wait some time and check the channel was closed TimeUnit.SECONDS.sleep(1); assertFalse(channelF.getChannel().isOpen()); // ------------------------------------------------------------------------------------------------------------ // Test closeable interface with re-connection trial // ------------------------------------------------------------------------------------------------------------ channelHandler.close(); assertFalse(channelHandler.listeningChannel.isOpen()); assertEquals(channelHandler.channelGroup.size(), 0); }