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


Java ClientBootstrap.setPipelineFactory方法代码示例

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


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

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

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

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

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

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

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

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

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

示例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());
    final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
    bootstrap.setPipelineFactory(() -> {
        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:linux-china,项目名称:dubbo3,代码行数:20,代码来源: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: 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

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

示例13: HttpTunnelSoakTester

import org.jboss.netty.bootstrap.ClientBootstrap; //导入方法依赖的package包/类
public HttpTunnelSoakTester() {
	scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
	executor = Executors.newCachedThreadPool();
	ServerSocketChannelFactory serverChannelFactory = new NioServerSocketChannelFactory(
			executor, executor);
	HttpTunnelServerChannelFactory serverTunnelFactory = new HttpTunnelServerChannelFactory(
			serverChannelFactory);

	serverBootstrap = new ServerBootstrap(serverTunnelFactory);
	serverBootstrap.setPipelineFactory(createServerPipelineFactory());

	ClientSocketChannelFactory clientChannelFactory = new NioClientSocketChannelFactory(
			executor, executor);
	HttpTunnelClientChannelFactory clientTunnelFactory = new HttpTunnelClientChannelFactory(
			clientChannelFactory);

	clientBootstrap = new ClientBootstrap(clientTunnelFactory);
	clientBootstrap.setPipelineFactory(createClientPipelineFactory());
	configureProxy();

	channels = new DefaultChannelGroup();
}
 
开发者ID:reines,项目名称:httptunnel,代码行数:23,代码来源:HttpTunnelSoakTester.java

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

示例15: main

import org.jboss.netty.bootstrap.ClientBootstrap; //导入方法依赖的package包/类
public static void main(String args[]) {
    // Client服务启动器
    ClientBootstrap bootstrap = new ClientBootstrap(
            new NioClientSocketChannelFactory(
                    Executors.newCachedThreadPool(),
                    Executors.newCachedThreadPool()));
    // 设置一个处理服务端消息和各种消息事件的类(Handler)
    bootstrap.setPipelineFactory(() -> Channels.pipeline(new HelloClientHandler()));
    // 连接到本地的8000端口的服务端
    bootstrap.connect(new InetSocketAddress("127.0.0.1", 8000));
}
 
开发者ID:lihengming,项目名称:java-codes,代码行数:12,代码来源:HelloClient.java


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