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


Java ChannelFactory類代碼示例

本文整理匯總了Java中org.jboss.netty.channel.ChannelFactory的典型用法代碼示例。如果您正苦於以下問題:Java ChannelFactory類的具體用法?Java ChannelFactory怎麽用?Java ChannelFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: run

import org.jboss.netty.channel.ChannelFactory; //導入依賴的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: connect

import org.jboss.netty.channel.ChannelFactory; //導入依賴的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

示例3: connectFrom

import org.jboss.netty.channel.ChannelFactory; //導入依賴的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

示例4: main

import org.jboss.netty.channel.ChannelFactory; //導入依賴的package包/類
public static void main(String[] args) {
    String hostname = "127.0.0.1";
    int port = 5044;
    if (args.length >= 2) {
        hostname = args[0];
        port = firstNonNull(Ints.tryParse(args[1]), 5044);
    }
    if (args.length >= 1) {
        port = firstNonNull(Ints.tryParse(args[1]), 5044);
    }

    final ChannelFactory factory =
            new NioServerSocketChannelFactory(
                    Executors.newCachedThreadPool(),
                    Executors.newCachedThreadPool());
    final ServerBootstrap b = new ServerBootstrap(factory);
    b.getPipeline().addLast("beats-frame-decoder", new BeatsFrameDecoder());
    b.getPipeline().addLast("beats-codec", new BeatsCodecHandler());
    b.getPipeline().addLast("logging", new LoggingHandler());
    System.out.println("Starting listener on " + hostname + ":" + port);
    b.bind(new InetSocketAddress(hostname, port));
}
 
開發者ID:Graylog2,項目名稱:graylog-plugin-beats,代碼行數:23,代碼來源:ConsolePrinter.java

示例5: doOpen

import org.jboss.netty.channel.ChannelFactory; //導入依賴的package包/類
@Override
protected void doOpen() throws Throwable {
    NettyHelper.setNettyLoggerFactory();
    //設置線程池(但是線程池中的線程都是守護線程,為的就是當JVM退出時候不用考慮守護線程是否已經結束)
    ExecutorService boss = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerBoss", true));
    ExecutorService worker = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerWorker", true));
    ChannelFactory channelFactory = new NioServerSocketChannelFactory(boss, worker, getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS));
    bootstrap = new ServerBootstrap(channelFactory); //Netty啟動類
    //定義NettyHandler(這個應該是通用的Handler,隻有在服務啟動的時候生效一次)
    final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
    channels = nettyHandler.getChannels();
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        public ChannelPipeline getPipeline() {
            NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec() ,getUrl(), NettyServer.this);
            ChannelPipeline pipeline = Channels.pipeline();

            pipeline.addLast("decoder", adapter.getDecoder()); //增加解碼處理器
            pipeline.addLast("encoder", adapter.getEncoder()); //增加編碼處理器
            pipeline.addLast("handler", nettyHandler); //增加具體操作的處理器
            return pipeline;
        }
    });
    // bind
    channel = bootstrap.bind(getBindAddress());
}
 
開發者ID:DoubleSmile,項目名稱:dubbo-learning,代碼行數:26,代碼來源:NettyServer.java

示例6: doOpen

import org.jboss.netty.channel.ChannelFactory; //導入依賴的package包/類
@Override
public void doOpen() throws Throwable {
    ExecutorService boss = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerBoss", false));
       ExecutorService worker = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerWorker", true));
       int ioThread = conf.getInt(Constants.IO_THREADS,Constants.DEFAULT_IO_THREADS);
       ChannelFactory channelFactory = new NioServerSocketChannelFactory(boss, worker, ioThread);
       bootstrap = new ServerBootstrap(channelFactory);
       
       final NettyHandler nettyHandler = new NettyHandler(getConf(), this);
       channels = nettyHandler.getChannels();
       bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
           public ChannelPipeline getPipeline() {
               NettyCodecAdapter adapter = new NettyCodecAdapter(conf,getCodec(), NettyServer.this);
               ChannelPipeline pipeline = Channels.pipeline();
               pipeline.addLast("decoder", adapter.getDecoder());
               pipeline.addLast("encoder", adapter.getEncoder());
               pipeline.addLast("handler", nettyHandler);
               return pipeline;
           }
       });
       // bind
       channel = bootstrap.bind(getBindAddress());
}
 
開發者ID:qiuhd2015,項目名稱:anima,代碼行數:24,代碼來源:NettyServer.java

示例7: NettyClientAsync

import org.jboss.netty.channel.ChannelFactory; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
NettyClientAsync(Map storm_conf, ChannelFactory factory, ScheduledExecutorService scheduler, String host, int port, ReconnectRunnable reconnector) {
    super(storm_conf, factory, scheduler, host, port, reconnector);

    BATCH_THREASHOLD_WARN = ConfigExtension.getNettyBufferThresholdSize(storm_conf);
    blockSend = isBlockSend(storm_conf);
    directlySend = isDirectSend(storm_conf);

    flush_later = new AtomicBoolean(false);
    flushCheckInterval = Utils.getInt(storm_conf.get(Config.STORM_NETTY_FLUSH_CHECK_INTERVAL_MS), 10);

    Runnable flusher = new Runnable() {
        @Override
        public void run() {
            flush();
        }
    };
    long initialDelay = Math.min(1000, max_sleep_ms * max_retries);
    scheduler.scheduleAtFixedRate(flusher, initialDelay, flushCheckInterval, TimeUnit.MILLISECONDS);

    clientChannelFactory = factory;

    start();
    LOG.info(this.toString());
}
 
開發者ID:kkllwww007,項目名稱:jstrom,代碼行數:26,代碼來源:NettyClientAsync.java

示例8: init

import org.jboss.netty.channel.ChannelFactory; //導入依賴的package包/類
public void init(ChannelPipelineFactory pipeline, int workerNum) {
  ChannelFactory factory = RpcChannelFactory.createServerChannelFactory(serviceName, workerNum);

  DefaultChannelFuture.setUseDeadLockChecker(false);

  pipelineFactory = pipeline;
  bootstrap = new ServerBootstrap(factory);
  bootstrap.setPipelineFactory(pipelineFactory);
  // TODO - should be configurable
  bootstrap.setOption("reuseAddress", true);
  bootstrap.setOption("child.tcpNoDelay", true);
  bootstrap.setOption("child.keepAlive", true);
  bootstrap.setOption("child.connectTimeoutMillis", 10000);
  bootstrap.setOption("child.connectResponseTimeoutMillis", 10000);
  bootstrap.setOption("child.receiveBufferSize", 1048576 * 10);
}
 
開發者ID:gruter,項目名稱:tajo-cdh,代碼行數:17,代碼來源:NettyServerBase.java

示例9: prepare

import org.jboss.netty.channel.ChannelFactory; //導入依賴的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

示例10: main

import org.jboss.netty.channel.ChannelFactory; //導入依賴的package包/類
public static void main(String[] args) throws Exception {        

        Executor executor = Executors.newCachedThreadPool();
        ChannelFactory factory = new NioServerSocketChannelFactory(executor, executor);
        ServerBootstrap sb = new ServerBootstrap(factory);
        ClientSocketChannelFactory cf = new NioClientSocketChannelFactory(executor, executor);
        sb.setPipelineFactory(new ProxyPipelineFactory(cf,
                RtmpConfig.PROXY_REMOTE_HOST, RtmpConfig.PROXY_REMOTE_PORT));
        InetSocketAddress socketAddress = new InetSocketAddress(RtmpConfig.PROXY_PORT);
        sb.bind(socketAddress);
        logger.info("proxy server started, listening on {}", socketAddress);

        Thread monitor = new StopMonitor(RtmpConfig.PROXY_STOP_PORT);
        monitor.start();
        monitor.join();

        ChannelGroupFuture future = ALL_CHANNELS.close();
        logger.info("closing channels");
        future.awaitUninterruptibly();
        logger.info("releasing resources");
        factory.releaseExternalResources();
        logger.info("server stopped");

    }
 
開發者ID:bruni68510,項目名稱:flazr,代碼行數:25,代碼來源:RtmpProxy.java

示例11: addNewSwitch

import org.jboss.netty.channel.ChannelFactory; //導入依賴的package包/類
private void addNewSwitch(DummySwitch dummySwitch) {
	final SwitchChannelHandler switchHandler = new SwitchChannelHandler(coreConnector, aggreedVersion, moduleName);
	switchHandler.setDummySwitch(dummySwitch); // CONTAINS ALL THE INFO
												// ABOUT THIS SWITCH
	ChannelFactory factory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(),
			Executors.newCachedThreadPool());
	ClientBootstrap bootstrap = new ClientBootstrap(factory);
	bootstrap.setOption("tcpNoDelay", true);
	bootstrap.setOption("keepAlive", true);
	bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
		@Override
		public ChannelPipeline getPipeline() {
			return Channels.pipeline(switchHandler);
		}
	});

	// CONNECT AND ADD TO HASHMAP OF MANAGED SWITCHES
	ChannelFuture future = bootstrap.connect(new InetSocketAddress("localhost", 7753));
	managedSwitchesChannel.put(dummySwitch.getDatapathId(), future);
	managedBootstraps.put(dummySwitch.getDatapathId(), bootstrap);
	managedSwitches.put(dummySwitch.getDatapathId(), dummySwitch);
	switchHandler.registerSwitchConnection(future);
	switchHandler.setModuleHandler(moduleHandler);

}
 
開發者ID:fp7-netide,項目名稱:Engine,代碼行數:26,代碼來源:NetIdeModule.java

示例12: startUp

import org.jboss.netty.channel.ChannelFactory; //導入依賴的package包/類
@Override
public void startUp(FloodlightModuleContext context) {
	//ADD SWITCH LISTENERS
	floodlightProvider.addOFSwitchListener(this);
	
	//REGISTER FOR MESSAGES FROM THE SWITCHES
	floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this);
	floodlightProvider.addOFMessageListener(OFType.PACKET_OUT, this);
	floodlightProvider.addOFMessageListener(OFType.FLOW_MOD, this);
       floodlightProvider.addOFMessageListener(OFType.ERROR, this);
       

       //START UP THE SERVER FOR THE ODL-SHIM
       ChannelFactory serverFactory = new NioServerSocketChannelFactory(
                    Executors.newCachedThreadPool(),
                    Executors.newCachedThreadPool());

       ServerBootstrap serverBootstrap = new ServerBootstrap(serverFactory);
       serverBootstrap.setOption("child.tcpNoDelay", true);
       serverBootstrap.setOption("child.keepAlive", true);
       serverBootstrap.setPipelineFactory(new NetIdePipelineFactory());
       logger.info("NetIDE Module binding to 41414..." );
       serverBootstrap.bind(new InetSocketAddress(41414)); //TODO: REMOVE HARD CODING
}
 
開發者ID:fp7-netide,項目名稱:Engine,代碼行數:25,代碼來源:NetideModule.java

示例13: addNewSwitch

import org.jboss.netty.channel.ChannelFactory; //導入依賴的package包/類
/**
 * Creates the comms channel to the SDN Controller and then adds a 
 * fake switch for the controller to manage
 * @param dummySwitch the switch to be managed
 */
private void addNewSwitch(DummySwitch dummySwitch) {
	final SwitchChannelHandler switchHandler = new SwitchChannelHandler();
	switchHandler.setDummySwitch(dummySwitch); //CONTAINS ALL THE INFO ABOUT THIS SWITCH
	switchHandler.setShimChannel(this.channel);
	
	
	ChannelFactory factory = new NioClientSocketChannelFactory(
                  Executors.newCachedThreadPool(),
                  Executors.newCachedThreadPool());
    ClientBootstrap bootstrap = new ClientBootstrap(factory);
    bootstrap.setOption("tcpNoDelay", true);
    bootstrap.setOption("keepAlive", true);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        public ChannelPipeline getPipeline() {
            return Channels.pipeline(switchHandler);
        }
    });
    //CONNECT AND ADD TO HASHMAP OF MANAGED SWITCHES
    ChannelFuture future = bootstrap.connect(new InetSocketAddress("localhost", 6634));
    managedSwitches.put(dummySwitch.getId(), future);
    managedBootstraps.put(dummySwitch.getId(), bootstrap);
    switchHandler.setControllerChannel(future);
}
 
開發者ID:fp7-netide,項目名稱:Engine,代碼行數:29,代碼來源:BackendChannelHandler.java

示例14: init

import org.jboss.netty.channel.ChannelFactory; //導入依賴的package包/類
/**
 * Initialises the server.
 * 
 * @param releaseClassName The class name of the current active {@link Release}.
 * @throws ClassNotFoundException If the release class could not be found.
 * @throws IllegalAccessException If the release class could not be accessed.
 * @throws InstantiationException If the release class could not be instantiated.
 */
public void init(String releaseClassName) throws ClassNotFoundException, InstantiationException,
		IllegalAccessException {
	Class<?> clazz = Class.forName(releaseClassName);
	Release release = (Release) clazz.newInstance();

	logger.info("Initialized release #" + release.getReleaseNumber() + ".");

	ChannelFactory factory = new NioServerSocketChannelFactory(networkExecutor, networkExecutor);
	serviceBootstrap.setFactory(factory);
	httpBootstrap.setFactory(factory);
	jagGrabBootstrap.setFactory(factory);

	context = new ServerContext(release, serviceManager);
	ApolloHandler handler = new ApolloHandler(context);

	ChannelPipelineFactory servicePipelineFactory = new ServicePipelineFactory(handler, timer);
	serviceBootstrap.setPipelineFactory(servicePipelineFactory);

	ChannelPipelineFactory httpPipelineFactory = new HttpPipelineFactory(handler, timer);
	httpBootstrap.setPipelineFactory(httpPipelineFactory);

	ChannelPipelineFactory jagGrabPipelineFactory = new JagGrabPipelineFactory(handler, timer);
	jagGrabBootstrap.setPipelineFactory(jagGrabPipelineFactory);
}
 
開發者ID:DealerNextDoor,項目名稱:ApolloDev,代碼行數:33,代碼來源:Server.java

示例15: createChannel

import org.jboss.netty.channel.ChannelFactory; //導入依賴的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


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