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


Java ClientBootstrap.releaseExternalResources方法代码示例

本文整理汇总了Java中org.jboss.netty.bootstrap.ClientBootstrap.releaseExternalResources方法的典型用法代码示例。如果您正苦于以下问题:Java ClientBootstrap.releaseExternalResources方法的具体用法?Java ClientBootstrap.releaseExternalResources怎么用?Java ClientBootstrap.releaseExternalResources使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jboss.netty.bootstrap.ClientBootstrap的用法示例。


在下文中一共展示了ClientBootstrap.releaseExternalResources方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import org.jboss.netty.bootstrap.ClientBootstrap; //导入方法依赖的package包/类
public void run() {
  // Configure the client.
  ChannelFactory factory = new NioClientSocketChannelFactory(
      Executors.newCachedThreadPool(), Executors.newCachedThreadPool(), 1, 1);
  ClientBootstrap bootstrap = new ClientBootstrap(factory);

  // Set up the pipeline factory.
  bootstrap.setPipelineFactory(setPipelineFactory());

  bootstrap.setOption("tcpNoDelay", true);
  bootstrap.setOption("keepAlive", true);

  // Start the connection attempt.
  ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));

  if (oneShot) {
    // Wait until the connection is closed or the connection attempt fails.
    future.getChannel().getCloseFuture().awaitUninterruptibly();

    // Shut down thread pools to exit.
    bootstrap.releaseExternalResources();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:SimpleTcpClient.java

示例2: prepare

import org.jboss.netty.bootstrap.ClientBootstrap; //导入方法依赖的package包/类
public void prepare(Map stormConf, TopologyContext context,
        			final OutputCollector collector) {
	_collector = collector;
	ChannelFactory factory = new NioClientSocketChannelFactory(
									Executors.newCachedThreadPool(),
									Executors.newCachedThreadPool());
	_bootstrap = new ClientBootstrap(factory);
	
	_bootstrap.setPipelineFactory(getPipelineFactory());
	_bootstrap.setOptions(_options);
	
    ChannelFuture future = _bootstrap.connect(new InetSocketAddress(_host, _port));
    
    int connectTimeout = DEFAULT_CONNECT_TIMEOUT;
       Object connectTimeoutConfig = stormConf.get(Config.NIMBUS_TASK_LAUNCH_SECS);
       if (connectTimeoutConfig != null) {
       	connectTimeout = ((Number)connectTimeoutConfig).intValue()*1000/2;
       }
       
    future.awaitUninterruptibly(connectTimeout);
    if (!future.isSuccess()) {
    	_bootstrap.releaseExternalResources();
    	throw new RuntimeException("Could not connect to '"+_host+":"+_port, future.getCause());
    }
    _channel = future.getChannel();  
}
 
开发者ID:danigiri,项目名称:storm-sockets,代码行数:27,代码来源:SocketBolt.java

示例3: createChannel

import org.jboss.netty.bootstrap.ClientBootstrap; //导入方法依赖的package包/类
/**
 * Creates a new channel to given host and port.<br>
 *
 * @param host
 * @param port
 * @return
 * @throws Exception
 */
private Channel createChannel(String host, int port) throws Exception {
    // Important notice; use NioClientSocketChannelFactory instead
    // of NioServerSocketChannelFactory
    ChannelFactory channelFactory = new NioClientSocketChannelFactory(
            Executors.newCachedThreadPool(),
            Executors.newCachedThreadPool());
    ClientBootstrap bootstrap = new ClientBootstrap(channelFactory);
    //bootstrap.setPipelineFactory(new SipClientPipelineFactory(false,false));
    bootstrap.setPipelineFactory(new SipPipelineFactory(sipServerHandler));
    ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));

    // open / connect to channel
    Channel c = future.await().getChannel();
    if (!future.isSuccess()) {
        log.warn(String.format("createChannel. Establishing connection failed[%s]",
                future.getCause().getMessage()));
        bootstrap.releaseExternalResources();
    }
    return c;
}
 
开发者ID:elasticsoftwarefoundation,项目名称:elasterix,代码行数:29,代码来源:SipChannelFactoryImpl.java

示例4: connect

import org.jboss.netty.bootstrap.ClientBootstrap; //导入方法依赖的package包/类
public void connect(){

		bootstrap = new ClientBootstrap( new NioClientSocketChannelFactory(
				Executors.newCachedThreadPool(),
				Executors.newCachedThreadPool()));
		bootstrap.setOption("tcpNoDelay", false);
		bootstrap.setOption("keepAlive", true);

		final NettyClientHandler handler = new NettyClientHandler(this, timer);
		
		bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
			
			public ChannelPipeline getPipeline() throws Exception {
				ChannelPipeline pipeline =  Channels.pipeline();
				pipeline.addLast("handler", handler);

				if(openCompression){
                    pipeline.addLast("zlibEncoder", new ZlibEncoder(ZlibWrapper.GZIP, compressionLevel));
                }

				if (isFlowControl) {
					logger.debug("flowControl,flowThreshold={}", flowThreshold);
					pipeline.addLast("flowControl", new FLowControlHandler(flowThreshold));
				}

                pipeline.addLast("encoder", new StringEncoder());
				return pipeline;
			}
		});
		
		bootstrap.setOption("remoteAddress", new InetSocketAddress(host, port));
		try {
			ChannelFuture future = bootstrap.connect().sync();
			channel = future.getChannel();
		} catch (Exception e) {
			logger.error("", e);
			bootstrap.releaseExternalResources();
			System.exit(-1);//第一次连接出现异常直接退出,不走重连
		}
	}
 
开发者ID:DTStack,项目名称:jlogstash-output-plugin,代码行数:41,代码来源:Netty.java

示例5: connect

import org.jboss.netty.bootstrap.ClientBootstrap; //导入方法依赖的package包/类
public void connect(){

		bootstrap = new ClientBootstrap( new NioClientSocketChannelFactory(
				Executors.newCachedThreadPool(),
				Executors.newCachedThreadPool()));
		bootstrap.setOption("tcpNoDelay", false);
		bootstrap.setOption("keepAlive", true);

		final NettyClientHandler handler = new NettyClientHandler(this, timer);
		
		bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
			
			public ChannelPipeline getPipeline() throws Exception {
				ChannelPipeline pipeline =  Channels.pipeline();
				pipeline.addLast("handler", handler);
				pipeline.addLast("encoder", new StringEncoder());
				return pipeline;
			}
		});
		
		bootstrap.setOption("remoteAddress", new InetSocketAddress(host, port));
		try {
			ChannelFuture future = bootstrap.connect().sync();
			channel = future.getChannel();
		} catch (Exception e) {
			logger.error(ExceptionUtil.getErrorMessage(e));
			bootstrap.releaseExternalResources();
			System.exit(-1);//第一次连接出现异常直接退出,不走重连
		}
	}
 
开发者ID:DTStack,项目名称:jlogstash-input-plugin,代码行数:31,代码来源:NettySend.java

示例6: establishConnection

import org.jboss.netty.bootstrap.ClientBootstrap; //导入方法依赖的package包/类
protected void establishConnection() throws IOException
{
    // Configure the client.
    bootstrap = new ClientBootstrap(
                    new NioClientSocketChannelFactory(
                        Executors.newCachedThreadPool(),
                        Executors.newCachedThreadPool()));

    bootstrap.setOption("tcpNoDelay", true);

    // Configure the pipeline factory.
    if(encryptionOptions.enabled)
    {
        bootstrap.setPipelineFactory(new SecurePipelineFactory());
    }
    else
    {
        bootstrap.setPipelineFactory(new PipelineFactory());
    }
    ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));

    // Wait until the connection attempt succeeds or fails.
    channel = future.awaitUninterruptibly().getChannel();
    if (!future.isSuccess())
    {
        bootstrap.releaseExternalResources();
        throw new IOException("Connection Error", future.getCause());
    }
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:30,代码来源:SimpleClient.java

示例7: main

import org.jboss.netty.bootstrap.ClientBootstrap; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    // Print usage if no argument is specified.
    if (args.length != 2) {
        System.err.println(
                "Usage: " + ChatClient.class.getSimpleName() +
                " <host> <port> ");
        return;
    }

    // Parse options.
    final String host = args[0];
    final int port = Integer.parseInt(args[1]);

    // Configure the client.
    ClientBootstrap bootstrap = new ClientBootstrap(
            new NioClientSocketChannelFactory(
                    Executors.newCachedThreadPool(),
                    Executors.newCachedThreadPool()));

    // Set up the pipeline factory.
    bootstrap.setPipelineFactory(new ChatClientPipelineFactory());

    // Start the connection attempt.
    ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));

    // Wait until the connection is closed or the connection attempt fails.
    future.getChannel().getCloseFuture().awaitUninterruptibly();

    // Shut down thread pools to exit.
    bootstrap.releaseExternalResources();
}
 
开发者ID:whg333,项目名称:nettyProtobufChat,代码行数:32,代码来源:ChatClient.java

示例8: connect

import org.jboss.netty.bootstrap.ClientBootstrap; //导入方法依赖的package包/类
private boolean connect(){
//     socket = new Socket("192.168.20.12", 8085);
//     System.out.println("socket connect success!");
//     reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//     writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            
        bootstrap = new ClientBootstrap(
                new NioClientSocketChannelFactory(
                        Executors.newCachedThreadPool(),
                        Executors.newCachedThreadPool()));

        // Set up the pipeline factory.
        bootstrap.setPipelineFactory(new ChannelPipelineFactory(){
        	public ChannelPipeline getPipeline(){
        		return pipeline(
        		        new LengthFieldBasedFrameDecoder(max_frame_length_8kb, 0, frame_length_4b, 0, frame_length_4b, true, true),
        		        new ChatProtoBufDecoder(),
        		        new ChatProtoBufEncoder(),
        		        new ChatClientGuiHandler()
        		);
        	}
        });

        // Start the connection attempt.
        SocketAddress address = new InetSocketAddress(ipFiled.getText(), Integer.parseInt(portFiled.getText()));
        ChannelFuture future = bootstrap.connect(address);
        channel = future.awaitUninterruptibly().getChannel();
        if (!future.isSuccess()) {
            future.getCause().printStackTrace();
            bootstrap.releaseExternalResources();
			return false;
        }
        
        return true;
	}
 
开发者ID:whg333,项目名称:nettyProtobufChat,代码行数:36,代码来源:ChatClientGui.java

示例9: request

import org.jboss.netty.bootstrap.ClientBootstrap; //导入方法依赖的package包/类
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();
    
}
 
开发者ID:eBay,项目名称:parallec,代码行数:66,代码来源:TcpProviderPoc.java

示例10: remoteCapiConnect

import org.jboss.netty.bootstrap.ClientBootstrap; //导入方法依赖的package包/类
public static Channel remoteCapiConnect(InetSocketAddress remoteAddress, ChannelHandler handler) {

        ChannelFuture connectFuture = null;

        // configure client bootstrap
        final ClientBootstrap bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(Executors
                .newCachedThreadPool(), Executors.newCachedThreadPool()));

        try {

            // use Request-Response handler business logic
            bootstrap.setPipelineFactory(new RemoteCapiPipelineFactory(handler));

            // start the connection attempt
            connectFuture = bootstrap.connect(remoteAddress);

            connectFuture.await(CONNECT_TIMEOUT_SECONDS, TimeUnit.SECONDS);

        } catch (InterruptedException e) {
            return null;
        } finally {
            if (connectFuture.isSuccess()) {
                // shut down thread pools on channelClosed
                connectFuture.getChannel().getCloseFuture().addListener(new ChannelFutureListener() {
                    public void operationComplete(ChannelFuture closeFuture) throws Exception {
                    	new Thread() {
                    		@Override
                    		public void run() {
                                bootstrap.releaseExternalResources();
                    		}
                    	}.start();
                    }
                });
            } else {
                // shut down thread pools due to connection failure
                bootstrap.releaseExternalResources();

                return null;
            }
        }

        return connectFuture.getChannel();
    }
 
开发者ID:rmarins,项目名称:netty-isdn-transport,代码行数:44,代码来源:RemoteCapiHelper.java


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