Java Code Examples for org.jboss.netty.channel.ChannelFuture#isCancelled()

The following examples show how to use org.jboss.netty.channel.ChannelFuture#isCancelled() . 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: RPCService.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: NettyClientFactory.java    From migration-tool with Apache License 2.0 5 votes vote down vote up
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;
}