Java Code Examples for org.jboss.netty.channel.ChannelFuture#getCause()
The following examples show how to use
org.jboss.netty.channel.ChannelFuture#getCause() .
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: DefaultPinpointClientHandler.java From pinpoint with Apache License 2.0 | 6 votes |
public void sendPing() { if (!state.isEnableCommunication()) { return; } logger.debug("{} sendPing() started.", objectUniqName); PingPayloadPacket pingPacket = new PingPayloadPacket(pingIdGenerator.incrementAndGet(), (byte) 0, state.getCurrentStateCode().getId()); ChannelFuture future = write0(pingPacket); future.awaitUninterruptibly(); if (!future.isSuccess()) { Throwable cause = future.getCause(); throw new PinpointSocketException("send ping failed. Error:" + cause.getMessage(), cause); } logger.debug("{} sendPing() completed.", objectUniqName); }
Example 3
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 4
Source File: RPCService.java From floodlight_with_topoguard with Apache License 2.0 | 6 votes |
@Override public void operationComplete(ChannelFuture cf) throws Exception { if (!cf.isSuccess()) { synchronized (connections) { NodeConnection c = connections.remove(node.getNodeId()); if (c != null) c.nuke(); cf.getChannel().close(); } String message = "[unknown error]"; if (cf.isCancelled()) message = "Timed out on connect"; if (cf.getCause() != null) message = cf.getCause().getMessage(); logger.debug("[{}->{}] Could not connect to RPC " + "node: {}", new Object[]{syncManager.getLocalNodeId(), node.getNodeId(), message}); } else { logger.trace("[{}->{}] Channel future successful", syncManager.getLocalNodeId(), node.getNodeId()); } }
Example 5
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 6
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 7
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 8
Source File: NettyTransport.java From Elasticsearch with Apache License 2.0 | 5 votes |
protected NodeChannels connectToChannelsLight(DiscoveryNode node) { InetSocketAddress address = ((InetSocketTransportAddress) node.address()).address(); ChannelFuture connect = clientBootstrap.connect(address); connect.awaitUninterruptibly((long) (connectTimeout.millis() * 1.5)); if (!connect.isSuccess()) { throw new ConnectTransportException(node, "connect_timeout[" + connectTimeout + "]", connect.getCause()); } Channel[] channels = new Channel[1]; channels[0] = connect.getChannel(); channels[0].getCloseFuture().addListener(new ChannelCloseListener(node)); return new NodeChannels(channels, channels, channels, channels, channels); }
Example 9
Source File: NettyRpcConnection.java From voyage with Apache License 2.0 | 5 votes |
/** * 尝试连接 */ public void connect() { ChannelFuture future = bootstrap.connect(inetAddr); try{ boolean ret = future.awaitUninterruptibly(Constants.TIMEOUT_CONNECTION_MILLSECOND, TimeUnit.MILLISECONDS); if (ret && future.isSuccess()) { Channel newChannel = future.getChannel(); newChannel.setInterestOps(Channel.OP_READ_WRITE); try { // 关闭旧的连接 Channel oldChannel = NettyRpcConnection.this.channel; if (oldChannel != null) { logger.info("Close old netty channel {} on create new netty channel {}", oldChannel, newChannel); oldChannel.close(); } } finally { if (!isConnected()) { try { logger.info("Close new netty channel {}, because the client closed.", newChannel); newChannel.close(); } finally { NettyRpcConnection.this.channel = null; } } else { NettyRpcConnection.this.channel = newChannel; } } } else if (null != future.getCause()) { logger.error("connect fail", future.getCause()); throw new RuntimeException("connect error", future.getCause()); } else { logger.error("connect fail,connstr: "+this.getConnStr()); throw new RuntimeException("connect error"); } }finally{ if (! isConnected()) { future.cancel(); } } }
Example 10
Source File: ChannelFutureAggregator.java From canal with Apache License 2.0 | 5 votes |
@Override public void operationComplete(ChannelFuture future) { // profiling after I/O operation if (future != null && future.getCause() != null) { result.channelError = future.getCause(); } profiler().profiling(result); }
Example 11
Source File: InvokeFuture.java From voyage with Apache License 2.0 | 5 votes |
/** * 发送请求 */ public void send() { ChannelFuture writeFuture = channel.write(request); //阻塞等待,若超时则返回已完成和失败 boolean ret = writeFuture.awaitUninterruptibly(1000, TimeUnit.MILLISECONDS); if (ret && writeFuture.isSuccess()) { return; } else if(writeFuture.getCause() != null) { invokeMap.remove(request.getRequestID()); throw new RpcException(writeFuture.getCause()); } else { invokeMap.remove(request.getRequestID()); throw new RpcException("sendRequest error"); } }
Example 12
Source File: ChannelFutureAggregator.java From canal-1.1.3 with Apache License 2.0 | 5 votes |
@Override public void operationComplete(ChannelFuture future) { // profiling after I/O operation if (future != null && future.getCause() != null) { result.channelError = future.getCause(); } profiler().profiling(result); }
Example 13
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 14
Source File: WriteFailFutureListener.java From pinpoint with Apache License 2.0 | 5 votes |
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { if (logger.isWarnEnabled()) { final Throwable cause = future.getCause(); logger.warn("{} channel:{} Caused:{}", failMessage, future.getChannel(), cause.getMessage(), cause); } } else { if (successMessage != null) { if (logger.isDebugEnabled()) { logger.debug("{} channel:{}", successMessage, future.getChannel()); } } } }
Example 15
Source File: NettyClient.java From dubbox with Apache License 2.0 | 4 votes |
protected void doConnect() throws Throwable { long start = System.currentTimeMillis(); ChannelFuture future = bootstrap.connect(getConnectAddress()); try{ boolean ret = future.awaitUninterruptibly(getConnectTimeout(), TimeUnit.MILLISECONDS); if (ret && future.isSuccess()) { Channel newChannel = future.getChannel(); newChannel.setInterestOps(Channel.OP_READ_WRITE); try { // 关闭旧的连接 Channel oldChannel = NettyClient.this.channel; // copy reference if (oldChannel != null) { try { if (logger.isInfoEnabled()) { logger.info("Close old netty channel " + oldChannel + " on create new netty channel " + newChannel); } oldChannel.close(); } finally { NettyChannel.removeChannelIfDisconnected(oldChannel); } } } finally { if (NettyClient.this.isClosed()) { try { if (logger.isInfoEnabled()) { logger.info("Close new netty channel " + newChannel + ", because the client closed."); } newChannel.close(); } finally { NettyClient.this.channel = null; NettyChannel.removeChannelIfDisconnected(newChannel); } } else { NettyClient.this.channel = newChannel; } } } else if (future.getCause() != null) { throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + ", error message is:" + future.getCause().getMessage(), future.getCause()); } else { throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + " client-side timeout " + getConnectTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start) + "ms) from netty client " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion()); } }finally{ if (! isConnected()) { future.cancel(); } } }
Example 16
Source File: NettyClient.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
protected void doConnect() throws Throwable { long start = System.currentTimeMillis(); ChannelFuture future = bootstrap.connect(getConnectAddress()); try{ boolean ret = future.awaitUninterruptibly(getConnectTimeout(), TimeUnit.MILLISECONDS); if (ret && future.isSuccess()) { Channel newChannel = future.getChannel(); newChannel.setInterestOps(Channel.OP_READ_WRITE); try { // 关闭旧的连接 Channel oldChannel = NettyClient.this.channel; // copy reference if (oldChannel != null) { try { if (logger.isInfoEnabled()) { logger.info("Close old netty channel " + oldChannel + " on create new netty channel " + newChannel); } oldChannel.close(); } finally { NettyChannel.removeChannelIfDisconnected(oldChannel); } } } finally { if (NettyClient.this.isClosed()) { try { if (logger.isInfoEnabled()) { logger.info("Close new netty channel " + newChannel + ", because the client closed."); } newChannel.close(); } finally { NettyClient.this.channel = null; NettyChannel.removeChannelIfDisconnected(newChannel); } } else { NettyClient.this.channel = newChannel; } } } else if (future.getCause() != null) { throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + ", error message is:" + future.getCause().getMessage(), future.getCause()); } else { throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + " client-side timeout " + getConnectTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start) + "ms) from netty client " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion()); } }finally{ if (! isConnected()) { future.cancel(); } } }
Example 17
Source File: NettyClient.java From dubbox with Apache License 2.0 | 4 votes |
protected void doConnect() throws Throwable { long start = System.currentTimeMillis(); ChannelFuture future = bootstrap.connect(getConnectAddress()); try{ boolean ret = future.awaitUninterruptibly(getConnectTimeout(), TimeUnit.MILLISECONDS); if (ret && future.isSuccess()) { Channel newChannel = future.getChannel(); newChannel.setInterestOps(Channel.OP_READ_WRITE); try { // 关闭旧的连接 Channel oldChannel = NettyClient.this.channel; // copy reference if (oldChannel != null) { try { if (logger.isInfoEnabled()) { logger.info("Close old netty channel " + oldChannel + " on create new netty channel " + newChannel); } oldChannel.close(); } finally { NettyChannel.removeChannelIfDisconnected(oldChannel); } } } finally { if (NettyClient.this.isClosed()) { try { if (logger.isInfoEnabled()) { logger.info("Close new netty channel " + newChannel + ", because the client closed."); } newChannel.close(); } finally { NettyClient.this.channel = null; NettyChannel.removeChannelIfDisconnected(newChannel); } } else { NettyClient.this.channel = newChannel; } } } else if (future.getCause() != null) { throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + ", error message is:" + future.getCause().getMessage(), future.getCause()); } else { throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + " client-side timeout " + getConnectTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start) + "ms) from netty client " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion()); } }finally{ if (! isConnected()) { future.cancel(); } } }
Example 18
Source File: NettyClient.java From anima with GNU General Public License v3.0 | 4 votes |
@Override public void doConnect() throws Throwable { long start = System.currentTimeMillis(); ChannelFuture future = bootstrap.connect(getConnectAddress()); try{ boolean ret = future.awaitUninterruptibly(getConnectTimeout(), TimeUnit.MILLISECONDS); if (ret && future.isSuccess()) { Channel newChannel = future.getChannel(); newChannel.setInterestOps(Channel.OP_READ_WRITE); try { Channel oldChannel = NettyClient.this.channel; if (oldChannel != null) { try { if (logger.isInfoEnabled()) { logger.info("Close old netty channel " + oldChannel + " on create new netty channel " + newChannel); } oldChannel.close(); } finally { NettyChannel.removeChannelIfDisconnected(oldChannel); } } } finally { if (NettyClient.this.isClosed()) { try { if (logger.isInfoEnabled()) { logger.info("Close new netty channel " + newChannel + ", because the client closed."); } newChannel.close(); } finally { NettyClient.this.channel = null; NettyChannel.removeChannelIfDisconnected(newChannel); } } else { NettyClient.this.channel = newChannel; } } } else if (future.getCause() != null) { throw new RemotingException(this, "client failed to connect to server " + getRemoteAddress() + ", error message is:" + future.getCause().getMessage(), future.getCause()); } else { throw new RemotingException(this, "client failed to connect to server " + getRemoteAddress() + " client-side timeout " + getConnectTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start) + "ms) from netty client"); } }finally{ if (! isConnected()) { future.cancel(); } } }
Example 19
Source File: NettyClient.java From dubbox with Apache License 2.0 | 4 votes |
protected void doConnect() throws Throwable { long start = System.currentTimeMillis(); ChannelFuture future = bootstrap.connect(getConnectAddress()); try{ boolean ret = future.awaitUninterruptibly(getConnectTimeout(), TimeUnit.MILLISECONDS); if (ret && future.isSuccess()) { Channel newChannel = future.getChannel(); newChannel.setInterestOps(Channel.OP_READ_WRITE); try { // 关闭旧的连接 Channel oldChannel = NettyClient.this.channel; // copy reference if (oldChannel != null) { try { if (logger.isInfoEnabled()) { logger.info("Close old netty channel " + oldChannel + " on create new netty channel " + newChannel); } oldChannel.close(); } finally { NettyChannel.removeChannelIfDisconnected(oldChannel); } } } finally { if (NettyClient.this.isClosed()) { try { if (logger.isInfoEnabled()) { logger.info("Close new netty channel " + newChannel + ", because the client closed."); } newChannel.close(); } finally { NettyClient.this.channel = null; NettyChannel.removeChannelIfDisconnected(newChannel); } } else { NettyClient.this.channel = newChannel; } } } else if (future.getCause() != null) { throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + ", error message is:" + future.getCause().getMessage(), future.getCause()); } else { throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + " client-side timeout " + getConnectTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start) + "ms) from netty client " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion()); } }finally{ if (! isConnected()) { future.cancel(); } } }
Example 20
Source File: NettyClient.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
@Override protected void doConnect() throws Throwable { long start = System.currentTimeMillis(); ChannelFuture future = bootstrap.connect(getConnectAddress()); try { boolean ret = future.awaitUninterruptibly(getConnectTimeout(), TimeUnit.MILLISECONDS); if (ret && future.isSuccess()) { Channel newChannel = future.getChannel(); newChannel.setInterestOps(Channel.OP_READ_WRITE); try { // Close old channel Channel oldChannel = NettyClient.this.channel; // copy reference if (oldChannel != null) { try { if (logger.isInfoEnabled()) { logger.info("Close old netty channel " + oldChannel + " on create new netty channel " + newChannel); } oldChannel.close(); } finally { NettyChannel.removeChannelIfDisconnected(oldChannel); } } } finally { if (NettyClient.this.isClosed()) { try { if (logger.isInfoEnabled()) { logger.info("Close new netty channel " + newChannel + ", because the client closed."); } newChannel.close(); } finally { NettyClient.this.channel = null; NettyChannel.removeChannelIfDisconnected(newChannel); } } else { NettyClient.this.channel = newChannel; } } } else if (future.getCause() != null) { throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + ", error message is:" + future.getCause().getMessage(), future.getCause()); } else { throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + " client-side timeout " + getConnectTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start) + "ms) from netty client " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion()); } } finally { if (!isConnected()) { future.cancel(); } } }