當前位置: 首頁>>代碼示例>>Java>>正文


Java ClientBootstrap.setOption方法代碼示例

本文整理匯總了Java中org.jboss.netty.bootstrap.ClientBootstrap.setOption方法的典型用法代碼示例。如果您正苦於以下問題:Java ClientBootstrap.setOption方法的具體用法?Java ClientBootstrap.setOption怎麽用?Java ClientBootstrap.setOption使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jboss.netty.bootstrap.ClientBootstrap的用法示例。


在下文中一共展示了ClientBootstrap.setOption方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: start

import org.jboss.netty.bootstrap.ClientBootstrap; //導入方法依賴的package包/類
public void start(String ip, int port) {
	
	// Configure the client.
	System.setProperty("java.net.preferIPv4Stack", "true");  
       System.setProperty("java.net.preferIPv6Addresses", "false"); 
       bootstrap = new ClientBootstrap(
			new NioClientSocketChannelFactory(
					Executors.newCachedThreadPool(),
					Executors.newCachedThreadPool()));
	// Set up the event pipeline factory.
	// bootstrap.setPipelineFactory(new MessageServerPipelineFactory());
	bootstrap.getPipeline().addLast("decoder", new PackageDecoder());
	bootstrap.getPipeline().addLast("encoder", new PackageEncoder());
	bootstrap.getPipeline().addLast("handler", new ClientHandler());
	
	bootstrap.setOption("tcpNoDelay", true);  
       bootstrap.setOption("keepAlive", true); 
       bootstrap.setOption("child.linger", 1);
       
	// Start the connection attempt.
	channelFuture = bootstrap.connect(new InetSocketAddress(ip, port));
	// Wait until the connection is closed or the connection attempt fails.
	channelFuture.awaitUninterruptibly();
	
	channel = channelFuture.awaitUninterruptibly().getChannel();
}
 
開發者ID:qizhenghao,項目名稱:HiBangClient,代碼行數:27,代碼來源:HiBangClient.java

示例2: doOpen

import org.jboss.netty.bootstrap.ClientBootstrap; //導入方法依賴的package包/類
@Override
protected void doOpen() throws Throwable {
    NettyHelper.setNettyLoggerFactory();
    bootstrap = new ClientBootstrap(channelFactory);
    // config
    // @see org.jboss.netty.channel.socket.SocketChannelConfig
    bootstrap.setOption("keepAlive", true);
    bootstrap.setOption("tcpNoDelay", true);
    bootstrap.setOption("connectTimeoutMillis", getTimeout());
    final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        public ChannelPipeline getPipeline() {
            NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this);
            ChannelPipeline pipeline = Channels.pipeline();
            pipeline.addLast("decoder", adapter.getDecoder());
            pipeline.addLast("encoder", adapter.getEncoder());
            pipeline.addLast("handler", nettyHandler);
            return pipeline;
        }
    });
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:22,代碼來源:NettyClient.java

示例3: 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

示例4: connect

import org.jboss.netty.bootstrap.ClientBootstrap; //導入方法依賴的package包/類
/**
  * Starts the BGP peer.
  *
  * @param connectToSocket the socket to connect to
  */
 private void connect(InetSocketAddress connectToSocket)
     throws InterruptedException {

     ChannelFactory channelFactory =
         new NioClientSocketChannelFactory(
                 Executors.newCachedThreadPool(),
                 Executors.newCachedThreadPool());
     ChannelPipelineFactory pipelineFactory = () -> {
         ChannelPipeline pipeline = Channels.pipeline();
         pipeline.addLast("BgpPeerFrameDecoderTest",
                 peerFrameDecoder);
         pipeline.addLast("BgpPeerChannelHandlerTest",
                 peerChannelHandler);
         return pipeline;
     };

     peerBootstrap = new ClientBootstrap(channelFactory);
     peerBootstrap.setOption("child.keepAlive", true);
     peerBootstrap.setOption("child.tcpNoDelay", true);
     peerBootstrap.setPipelineFactory(pipelineFactory);
     peerBootstrap.connect(connectToSocket);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:28,代碼來源:BgpControllerImplTest.java

示例5: connectFrom

import org.jboss.netty.bootstrap.ClientBootstrap; //導入方法依賴的package包/類
private Channel connectFrom(InetSocketAddress connectToSocket, SocketAddress localAddress)
     throws InterruptedException {

     ChannelFactory channelFactory =
         new NioClientSocketChannelFactory(
                 Executors.newCachedThreadPool(),
                 Executors.newCachedThreadPool());
     ChannelPipelineFactory pipelineFactory = () -> {
         ChannelPipeline pipeline = Channels.pipeline();
         pipeline.addLast("BgpPeerFrameDecoderTest",
                 peerFrameDecoder);
         pipeline.addLast("BgpPeerChannelHandlerTest",
                 peerChannelHandler);
         return pipeline;
     };

     peerBootstrap = new ClientBootstrap(channelFactory);
     peerBootstrap.setOption("child.keepAlive", true);
     peerBootstrap.setOption("child.tcpNoDelay", true);
     peerBootstrap.setPipelineFactory(pipelineFactory);
     Channel channel = peerBootstrap.connect(connectToSocket, localAddress).getChannel();
     return channel;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:24,代碼來源:BgpControllerImplTest.java

示例6: startClients

import org.jboss.netty.bootstrap.ClientBootstrap; //導入方法依賴的package包/類
/**
 * Connect to remote servers.  We'll initiate the connection to
 * any nodes with a lower ID so that there will be a single connection
 * between each pair of nodes which we'll use symmetrically
 */
protected void startClients(ChannelPipelineFactory pipelineFactory) {
    final ClientBootstrap bootstrap =
            new ClientBootstrap(
                 new NioClientSocketChannelFactory(bossExecutor,
                                                   workerExecutor));
    bootstrap.setOption("child.reuseAddr", true);
    bootstrap.setOption("child.keepAlive", true);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.sendBufferSize", SEND_BUFFER_SIZE);
    bootstrap.setOption("child.connectTimeoutMillis", CONNECT_TIMEOUT);
    bootstrap.setPipelineFactory(pipelineFactory);
    clientBootstrap = bootstrap;

    ScheduledExecutorService ses = 
            syncManager.getThreadPool().getScheduledExecutor();
    reconnectTask = new SingletonTask(ses, new ConnectTask());
    reconnectTask.reschedule(0, TimeUnit.SECONDS);
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:24,代碼來源:RPCService.java

示例7: init

import org.jboss.netty.bootstrap.ClientBootstrap; //導入方法依賴的package包/類
public void init() throws SyncException {
    cg = new DefaultChannelGroup("Cluster Bootstrap");

    bossExecutor = Executors.newCachedThreadPool();
    workerExecutor = Executors.newCachedThreadPool();

    bootstrap =
            new ClientBootstrap(new NioClientSocketChannelFactory(bossExecutor,
                                                                  workerExecutor));
    bootstrap.setOption("child.reuseAddr", true);
    bootstrap.setOption("child.keepAlive", true);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.sendBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.receiveBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.connectTimeoutMillis", 
                        RPCService.CONNECT_TIMEOUT);
    pipelineFactory = new BootstrapPipelineFactory(this);
    bootstrap.setPipelineFactory(pipelineFactory);
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:22,代碼來源:Bootstrap.java

示例8: startUp

import org.jboss.netty.bootstrap.ClientBootstrap; //導入方法依賴的package包/類
@Override
public void startUp(FloodlightModuleContext context) 
        throws FloodlightModuleException {
    shutdown = false;
    bossExecutor = Executors.newCachedThreadPool();
    workerExecutor = Executors.newCachedThreadPool();
    
    final ClientBootstrap bootstrap =
            new ClientBootstrap(
                 new NioClientSocketChannelFactory(bossExecutor,
                                                   workerExecutor));
    bootstrap.setOption("child.reuseAddr", true);
    bootstrap.setOption("child.keepAlive", true);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.sendBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.receiveBufferSize", 
                        RPCService.SEND_BUFFER_SIZE);
    bootstrap.setOption("child.connectTimeoutMillis", 
                        RPCService.CONNECT_TIMEOUT);
    pipelineFactory = new RemoteSyncPipelineFactory(this);
    bootstrap.setPipelineFactory(pipelineFactory);
    clientBootstrap = bootstrap;
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:25,代碼來源:RemoteSyncManager.java

示例9: doOpen

import org.jboss.netty.bootstrap.ClientBootstrap; //導入方法依賴的package包/類
@Override
protected void doOpen() throws Throwable {
    NettyHelper.setNettyLoggerFactory();
    bootstrap = new ClientBootstrap(channelFactory);
    // config
    // @see org.jboss.netty.channel.socket.SocketChannelConfig
    bootstrap.setOption("keepAlive", true);
    bootstrap.setOption("tcpNoDelay", true);
    bootstrap.setOption("connectTimeoutMillis", getTimeout());
    //下麵才是正確的
    //bootstrap.setOption("connectTimeoutMillis", getConnectTimeout());
    //netty handler
    final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        public ChannelPipeline getPipeline() {
            NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this);
            ChannelPipeline pipeline = Channels.pipeline();
            pipeline.addLast("decoder", adapter.getDecoder());
            pipeline.addLast("encoder", adapter.getEncoder());
            pipeline.addLast("handler", nettyHandler);
            return pipeline;
        }
    });
}
 
開發者ID:spccold,項目名稱:dubbo-comments,代碼行數:25,代碼來源:NettyClient.java

示例10: ServiceClient

import org.jboss.netty.bootstrap.ClientBootstrap; //導入方法依賴的package包/類
private ServiceClient(String host, int port) {
	this.host = host;
	this.port = port;
	// Configure the client.
	bootstrap = new ClientBootstrap(channelFactory);
	bootstrap.setOption("tcpNoDelay", Boolean.parseBoolean(AppProperties
			.get("rpc_client_tcpNoDelay", "true")));
	bootstrap.setOption("keepAlive", Boolean.parseBoolean(AppProperties
			.get("rpc_client_keepAlive", "true")));
	bootstrap.setOption("connectTimeoutMillis", AppProperties.getAsInt(
			"rpc_client_connectTimeoutMillis", 1000 * 30));
	bootstrap.setOption("receiveBufferSize", AppProperties.getAsInt(
			"rpc_client_receiveBufferSize", 1024 * 1024));
	bootstrap.setOption("soLinger",
			AppProperties.getAsInt("rpc_client_soLinger", -1));
	bootstrap.setPipelineFactory(new RpcClientPipelineFactory());
	connAmout = AppProperties.getAsInt("rpc_client_connectionAmount", 1);
	this.channelMap = new ConcurrentHashMap<Integer, Channel>();
	initConns();
}
 
開發者ID:jbeetle,項目名稱:BJAF3.x,代碼行數:21,代碼來源:ServiceClient.java

示例11: doOpen

import org.jboss.netty.bootstrap.ClientBootstrap; //導入方法依賴的package包/類
@Override
protected void doOpen() throws Throwable {
    NettyHelper.setNettyLoggerFactory();
    bootstrap = new ClientBootstrap(channelFactory);
    // config
    // @see org.jboss.netty.channel.socket.SocketChannelConfig
    bootstrap.setOption("keepAlive", true);
    bootstrap.setOption("tcpNoDelay", true);
    bootstrap.setOption("connectTimeoutMillis", getTimeout());
    final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        public ChannelPipeline getPipeline() {
            NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this);
            ChannelPipeline pipeline = Channels.pipeline();
            pipeline.addLast("decoder", adapter.getDecoder());
            pipeline.addLast("encoder", adapter.getEncoder());
            pipeline.addLast("handler", nettyHandler);
            return pipeline;
        }
    });
}
 
開發者ID:MOBX,項目名稱:Thor,代碼行數:23,代碼來源:NettyClient.java

示例12: connectAsync

import org.jboss.netty.bootstrap.ClientBootstrap; //導入方法依賴的package包/類
public <T extends NiftyClientChannel> ListenableFuture<T> connectAsync(NiftyClientConnector<T> clientChannelConnector, @Nullable Duration connectTimeout,
		@Nullable Duration receiveTimeout, @Nullable Duration readTimeout, @Nullable Duration sendTimeout, int maxFrameSize,
		@Nullable HostAndPort socksProxyAddress) {
	checkNotNull(clientChannelConnector, "clientChannelConnector is null");

	ClientBootstrap bootstrap = createClientBootstrap(socksProxyAddress);
	bootstrap.setOptions(nettyClientConfig.getBootstrapOptions());

	if (connectTimeout != null) {
		bootstrap.setOption("connectTimeoutMillis", connectTimeout.toMillis());
	}

	bootstrap.setPipelineFactory(clientChannelConnector.newChannelPipelineFactory(maxFrameSize, nettyClientConfig));
	ChannelFuture nettyChannelFuture = clientChannelConnector.connect(bootstrap);
	nettyChannelFuture.addListener(new ChannelFutureListener() {
		@Override
		public void operationComplete(ChannelFuture future) throws Exception {
			Channel channel = future.getChannel();
			if (channel != null && channel.isOpen()) {
				allChannels.add(channel);
			}
		}
	});
	return new TNiftyFuture<>(clientChannelConnector, receiveTimeout, readTimeout, sendTimeout, nettyChannelFuture);
}
 
開發者ID:Treydone,項目名稱:mandrel,代碼行數:26,代碼來源:NiftyClient.java

示例13: Fetcher

import org.jboss.netty.bootstrap.ClientBootstrap; //導入方法依賴的package包/類
public Fetcher(URI uri, File file, ClientSocketChannelFactory factory) {
  this.uri = uri;
  this.file = file;

  String scheme = uri.getScheme() == null ? "http" : uri.getScheme();
  this.host = uri.getHost() == null ? "localhost" : uri.getHost();
  this.port = uri.getPort();
  if (port == -1) {
    if (scheme.equalsIgnoreCase("http")) {
      this.port = 80;
    } else if (scheme.equalsIgnoreCase("https")) {
      this.port = 443;
    }
  }

  bootstrap = new ClientBootstrap(factory);
  bootstrap.setOption("connectTimeoutMillis", 5000L); // set 5 sec
  bootstrap.setOption("receiveBufferSize", 1048576); // set 1M
  bootstrap.setOption("tcpNoDelay", true);

  ChannelPipelineFactory pipelineFactory = new HttpClientPipelineFactory(file);
  bootstrap.setPipelineFactory(pipelineFactory);
}
 
開發者ID:apache,項目名稱:incubator-tajo,代碼行數:24,代碼來源:Fetcher.java

示例14: DefaultClient

import org.jboss.netty.bootstrap.ClientBootstrap; //導入方法依賴的package包/類
/**
 * Creates a new instance that talks to a {@link DefaultServer} on the specified host and port.
 * 
 * @param clientId
 *            A unique id. No two clients with the same id can access the same
 *            {@link DefaultServer}
 * @param host
 *            The host the {@link DefaultServer} runs on
 * @param port
 *            The port the {@link DefaultServer} runs on
 */
public DefaultClient(final String clientId, final String host, final int port) {
	this.clientId = clientId;
	this.host = host;
	this.port = port;

	// Configure the client.
	bootstrap = new ClientBootstrap(
			new OioClientSocketChannelFactory(Executors.newCachedThreadPool(new DaemonThreadFactory())));

	// Set up the pipeline factory.
	bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
		@Override
		public ChannelPipeline getPipeline() throws Exception {
			return Channels.pipeline(
					new ObjectEncoder(ENCODER_ESTIMATED_LENGTH),
					new ObjectDecoder(DECODER_ESTIMATED_LENGTH, ClassResolvers.weakCachingResolver(null)),
					new ClientHandshakeHandler(new Handshake(clientId), HANDSHAKE_TIMEOUT_MILLIS),
					clientHandler);
		}
	});

	bootstrap.setOption("tcpNoDelay", true);
	bootstrap.setOption("keepAlive", true);
	bootstrap.setOption("soTimeout", 10000L);
}
 
開發者ID:mgm-tp,項目名稱:perfload-core,代碼行數:37,代碼來源:DefaultClient.java

示例15: open

import org.jboss.netty.bootstrap.ClientBootstrap; //導入方法依賴的package包/類
/**
	 * @param connectStatus 心跳檢測狀態是否正常
	 * @throws Throwable
	 */
	public void open(boolean connectStatus) throws Throwable {
		logger.info("open start,"+getConnStr());
		bootstrap = new ClientBootstrap(factory);
//		timer = new HashedWheelTimer();
		{
			bootstrap.setOption("tcpNoDelay", Boolean.parseBoolean(clientConfig.getTcpNoDelay()));
			bootstrap.setOption("reuseAddress", Boolean.parseBoolean(clientConfig.getReuseAddress()));
			bootstrap.setOption("SO_RCVBUF",1024*128);
			bootstrap.setOption("SO_SNDBUF",1024*128);
			bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
				public ChannelPipeline getPipeline() {
					ChannelPipeline pipeline = Channels.pipeline();
//					int readTimeout = clientConfig.getReadTimeout();
//					if (readTimeout > 0) {
//						pipeline.addLast("timeout", new ReadTimeoutHandler(timer,
//								readTimeout, TimeUnit.MILLISECONDS));
//					}
					pipeline.addLast("encoder", new RpcRequestEncode());
					pipeline.addLast("decoder", new RpcResponseDecode());
					pipeline.addLast("handler", NettyRpcConnection.this);
					return pipeline;
				}
			});
		}
		connected.set(connectStatus);
		logger.info("open finish,"+getConnStr());
	}
 
開發者ID:zhaoshiling1017,項目名稱:voyage,代碼行數:32,代碼來源:NettyRpcConnection.java


注:本文中的org.jboss.netty.bootstrap.ClientBootstrap.setOption方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。