Java Code Examples for org.jboss.netty.channel.ChannelFuture#await()
The following examples show how to use
org.jboss.netty.channel.ChannelFuture#await() .
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: NettyChannel.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Override public void send(Object message, boolean sent) throws RemotingException { super.send(message, sent); boolean success = true; int timeout = 0; try { // com.alibaba.dubbo.remoting.transport.AbstractPeer#received ChannelFuture future = channel.write(message); if (sent) { timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); success = future.await(timeout); } Throwable cause = future.getCause(); if (cause != null) { throw cause; } } catch (Throwable e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e); } if (!success) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit"); } }
Example 2
Source File: NettyChannel.java From dubbox with Apache License 2.0 | 6 votes |
public void send(Object message, boolean sent) throws RemotingException { super.send(message, sent); boolean success = true; int timeout = 0; try { ChannelFuture future = channel.write(message); if (sent) { timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); success = future.await(timeout); } Throwable cause = future.getCause(); if (cause != null) { throw cause; } } catch (Throwable e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e); } if(! success) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit"); } }
Example 3
Source File: NettyChannel.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
public void send(Object message, boolean sent) throws RemotingException { super.send(message, sent); boolean success = true; int timeout = 0; try { ChannelFuture future = channel.write(message); if (sent) { timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); success = future.await(timeout); } Throwable cause = future.getCause(); if (cause != null) { throw cause; } } catch (Throwable e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e); } if(! success) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit"); } }
Example 4
Source File: NettyChannel.java From dubbo3 with Apache License 2.0 | 6 votes |
public void send(Object message, boolean sent) throws RemotingException { super.send(message, sent); boolean success = true; int timeout = 0; try { ChannelFuture future = channel.write(message); if (sent) { timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); success = future.await(timeout); } Throwable cause = future.getCause(); if (cause != null) { throw cause; } } catch (Throwable e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e); } if(! success) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit"); } }
Example 5
Source File: NettyChannel.java From dubbox with Apache License 2.0 | 6 votes |
public void send(Object message, boolean sent) throws RemotingException { super.send(message, sent); boolean success = true; int timeout = 0; try { ChannelFuture future = channel.write(message); if (sent) { timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); success = future.await(timeout); } Throwable cause = future.getCause(); if (cause != null) { throw cause; } } catch (Throwable e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e); } if(! success) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit"); } }
Example 6
Source File: NettyChannel.java From dubbox with Apache License 2.0 | 6 votes |
public void send(Object message, boolean sent) throws RemotingException { super.send(message, sent); boolean success = true; int timeout = 0; try { ChannelFuture future = channel.write(message); if (sent) { timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); success = future.await(timeout); } Throwable cause = future.getCause(); if (cause != null) { throw cause; } } catch (Throwable e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e); } if(! success) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit"); } }
Example 7
Source File: PinpointClientFactoryTest.java From pinpoint with Apache License 2.0 | 5 votes |
@Test public void reconnectFail() throws InterruptedException { // confirm simplified error message when api called. int availableTcpPort = SocketUtils.findAvailableTcpPort(47000); InetSocketAddress remoteAddress = new InetSocketAddress("127.0.0.1", availableTcpPort); ChannelFuture reconnect = clientFactory.reconnect(remoteAddress); reconnect.await(); Assert.assertFalse(reconnect.isSuccess()); Assert.assertTrue(ConnectException.class.isInstance(reconnect.getCause())); Thread.sleep(1000); }
Example 8
Source File: TcpProviderPoc.java From parallec with Apache License 2.0 | 4 votes |
public void request() throws Exception { // Parse options. String host = "localhost"; int port = 10081; int connectTimeoutMillis = 2000; // Configure the client. ClientBootstrap bootstrap = new ClientBootstrap( new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); final TelnetClientHandler handler = new TelnetClientHandler(); // Configure the pipeline factory. bootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() { ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("framer", new DelimiterBasedFrameDecoder(1024, Delimiters.lineDelimiter())); pipeline.addLast("stringDecoder", stringDecoder); pipeline.addLast("stringEncoder", stringEncoder); pipeline.addLast("handler", handler); return pipeline; } }); bootstrap.setOption("connectTimeoutMillis",connectTimeoutMillis); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("keepAlive", true); // Start the connection attempt. ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port)); // Wait until the connection attempt succeeds or fails. Channel channel = future.awaitUninterruptibly().getChannel(); // Read commands from the stdin. ChannelFuture lastWriteFuture = null; String command = "hadoopMonitorFromClient"; // Sends the line to server. lastWriteFuture = channel.write(command + "\r\n"); // Wait until all messages are flushed before closing the channel. if (lastWriteFuture != null) { lastWriteFuture.await(); } // note that we need to wait for the response before // wait time before close the channel too early that msg will not be // received. while (!handler.channelCompleted) { Thread.sleep(1l); } // Close the connection. Make sure the close operation ends because // all I/O operations are asynchronous in Netty. channel.close().awaitUninterruptibly(); // Shut down all thread pools to exit. bootstrap.releaseExternalResources(); }