本文整理匯總了Java中org.jboss.netty.channel.ChannelFuture.getCause方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelFuture.getCause方法的具體用法?Java ChannelFuture.getCause怎麽用?Java ChannelFuture.getCause使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jboss.netty.channel.ChannelFuture
的用法示例。
在下文中一共展示了ChannelFuture.getCause方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: send
import org.jboss.netty.channel.ChannelFuture; //導入方法依賴的package包/類
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");
}
}
示例2: operationComplete
import org.jboss.netty.channel.ChannelFuture; //導入方法依賴的package包/類
@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());
}
}
示例3: send
import org.jboss.netty.channel.ChannelFuture; //導入方法依賴的package包/類
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);
//FIXME sent為true的話 要等待數據寫完才返回,失敗拋出異常 add by jileng
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");
}
}
示例4: send
import org.jboss.netty.channel.ChannelFuture; //導入方法依賴的package包/類
public void send(Object message, boolean sent) throws RemotingException {
super.send(message, sent); //調用父類的send方法進行異常判斷
boolean success = true;
int timeout = 0;
try {
//NIO框架通知執行寫操作
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");
}
}
示例5: send
import org.jboss.netty.channel.ChannelFuture; //導入方法依賴的package包/類
/**
* 發送請求
*/
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");
}
}
示例6: connect
import org.jboss.netty.channel.ChannelFuture; //導入方法依賴的package包/類
/**
* 嘗試連接
*/
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();
}
}
}
示例7: connectToChannelsLight
import org.jboss.netty.channel.ChannelFuture; //導入方法依賴的package包/類
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);
}
示例8: createClient
import org.jboss.netty.channel.ChannelFuture; //導入方法依賴的package包/類
protected Client createClient(String targetIP, int targetPort, int connectTimeout, String key) 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, key);
bootstrap.setPipelineFactory(new NettyClientPipelineFactory(handler));
ChannelFuture future = bootstrap.connect(new InetSocketAddress(targetIP, targetPort));
future.awaitUninterruptibly(connectTimeout);
if (!future.isDone()) {
LOGGER.error("Create connection to " + targetIP + ":" + targetPort + " timeout!");
throw new Exception("Create connection to " + targetIP + ":" + targetPort + " timeout!");
}
if (future.isCancelled()) {
LOGGER.error("Create connection to " + targetIP + ":" + targetPort + " cancelled by user!");
throw new Exception("Create connection to " + targetIP + ":" + targetPort + " cancelled by user!");
}
if (!future.isSuccess()) {
LOGGER.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, key, connectTimeout);
handler.setClient(client);
return client;
}
示例9: openChannel
import org.jboss.netty.channel.ChannelFuture; //導入方法依賴的package包/類
protected Channel openChannel(ChannelFuture channelFuture) throws Exception {
// blocking for channel to be done
if (LOG.isTraceEnabled()) {
LOG.trace("Waiting for operation to complete {} for {} millis", channelFuture, configuration.getConnectTimeout());
}
// here we need to wait it in other thread
final CountDownLatch channelLatch = new CountDownLatch(1);
channelFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture cf) throws Exception {
channelLatch.countDown();
}
});
try {
channelLatch.await(configuration.getConnectTimeout(), TimeUnit.MILLISECONDS);
} catch (InterruptedException ex) {
throw new CamelException("Interrupted while waiting for " + "connection to "
+ configuration.getAddress());
}
if (!channelFuture.isDone() || !channelFuture.isSuccess()) {
ConnectException cause = new ConnectException("Cannot connect to " + configuration.getAddress());
if (channelFuture.getCause() != null) {
cause.initCause(channelFuture.getCause());
}
throw cause;
}
Channel answer = channelFuture.getChannel();
if (LOG.isDebugEnabled()) {
LOG.debug("Creating connector to address: {}", configuration.getAddress());
}
return answer;
}
示例10: openChannel
import org.jboss.netty.channel.ChannelFuture; //導入方法依賴的package包/類
protected Channel openChannel(ChannelFuture channelFuture) throws Exception {
// blocking for channel to be done
if (LOG.isTraceEnabled()) {
LOG.trace("Waiting for operation to complete {} for {} millis", channelFuture, configuration.getConnectTimeout());
}
// here we need to wait it in other thread
final CountDownLatch channelLatch = new CountDownLatch(1);
channelFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture cf) throws Exception {
channelLatch.countDown();
}
});
try {
channelLatch.await(configuration.getConnectTimeout(), TimeUnit.MILLISECONDS);
} catch (InterruptedException ex) {
throw new CamelException("Interrupted while waiting for " + "connection to "
+ configuration.getAddress());
}
if (!channelFuture.isDone() || !channelFuture.isSuccess()) {
ConnectException cause = new ConnectException("Cannot connect to " + configuration.getAddress());
if (channelFuture.getCause() != null) {
cause.initCause(channelFuture.getCause());
}
throw cause;
}
Channel answer = channelFuture.getChannel();
// to keep track of all channels in use
allChannels.add(answer);
if (LOG.isDebugEnabled()) {
LOG.debug("Creating connector to address: {}", configuration.getAddress());
}
return answer;
}
示例11: operationComplete
import org.jboss.netty.channel.ChannelFuture; //導入方法依賴的package包/類
@Override
public void operationComplete(ChannelFuture future) throws Exception {
// if it was not a success then thrown an exception
if (!future.isSuccess()) {
Exception e = new CamelExchangeException("Cannot write response to " + remoteAddress, exchange, future.getCause());
consumer.getExceptionHandler().handleException(e);
}
// should channel be closed after complete?
Boolean close;
if (exchange.hasOut()) {
close = exchange.getOut().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class);
} else {
close = exchange.getIn().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class);
}
// check the setting on the exchange property
if (close == null) {
close = exchange.getProperty(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class);
}
// should we disconnect, the header can override the configuration
boolean disconnect = consumer.getConfiguration().isDisconnect();
if (close != null) {
disconnect = close;
}
if (disconnect) {
if (LOG.isTraceEnabled()) {
LOG.trace("Closing channel when complete at address: {}", remoteAddress);
}
NettyHelper.close(future.getChannel());
}
}
示例12: doConnect
import org.jboss.netty.channel.ChannelFuture; //導入方法依賴的package包/類
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();
}
}
}
示例13: doConnect
import org.jboss.netty.channel.ChannelFuture; //導入方法依賴的package包/類
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 (log.isInfoEnabled()) {
log.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 (log.isInfoEnabled()) {
log.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();
}
}
}