当前位置: 首页>>代码示例>>Java>>正文


Java ChannelFuture.getCause方法代码示例

本文整理汇总了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");
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:25,代码来源:NettyChannel.java

示例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());
    }
}
 
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:24,代码来源:RPCService.java

示例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");
    }
}
 
开发者ID:spccold,项目名称:dubbo-comments,代码行数:27,代码来源:NettyChannel.java

示例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");
    }
}
 
开发者ID:DoubleSmile,项目名称:dubbo-learning,代码行数:27,代码来源:NettyChannel.java

示例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");
	}
}
 
开发者ID:zhaoshiling1017,项目名称:voyage,代码行数:18,代码来源:InvokeFuture.java

示例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();
           }
       }
}
 
开发者ID:zhaoshiling1017,项目名称:voyage,代码行数:43,代码来源:NettyRpcConnection.java

示例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);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:13,代码来源:NettyTransport.java

示例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;
}
 
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:30,代码来源:NettyClientFactory.java

示例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;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:36,代码来源:ClientModeTCPNettyServerBootstrapFactory.java

示例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;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:39,代码来源:NettyProducer.java

示例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());
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:34,代码来源:ServerResponseFutureListener.java

示例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();
        }
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:53,代码来源:NettyClient.java

示例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();
        }
    }
}
 
开发者ID:nince-wyj,项目名称:jahhan,代码行数:53,代码来源:NettyClient.java


注:本文中的org.jboss.netty.channel.ChannelFuture.getCause方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。