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


Java NioServerSocketChannelFactory類代碼示例

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


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

示例1: main

import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //導入依賴的package包/類
public static void main(String[] args) {
    // Server服務啟動器
    ServerBootstrap bootstrap = new ServerBootstrap(
            new NioServerSocketChannelFactory(
                    Executors.newCachedThreadPool(),
                    Executors.newCachedThreadPool()));
    // 設置一個處理客戶端消息和各種消息事件的類(Handler)
    bootstrap
            .setPipelineFactory(new ChannelPipelineFactory() {
                @Override
                public ChannelPipeline getPipeline()
                        throws Exception {
                    return Channels
                            .pipeline(new HelloServerHandler());
                }
            });
    // 開放8000端口供客戶端訪問。
    bootstrap.bind(new InetSocketAddress(8000));
}
 
開發者ID:lihengming,項目名稱:java-codes,代碼行數:20,代碼來源:NettyTest.java

示例2: NettyServerCnxnFactory

import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //導入依賴的package包/類
NettyServerCnxnFactory() {
    bootstrap = new ServerBootstrap(
            new NioServerSocketChannelFactory(
                    Executors.newCachedThreadPool(),
                    Executors.newCachedThreadPool()));
    // parent channel
    bootstrap.setOption("reuseAddress", true);
    // child channels
    bootstrap.setOption("child.tcpNoDelay", true);
    /* set socket linger to off, so that socket close does not block */
    bootstrap.setOption("child.soLinger", -1);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline p = Channels.pipeline();
            if (secure) {
                initSSL(p);
            }
            p.addLast("servercnxnfactory", channelHandler);

            return p;
        }
    });
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:25,代碼來源:NettyServerCnxnFactory.java

示例3: startHttpServer

import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //導入依賴的package包/類
private ServerBootstrap startHttpServer(int port,
    final Token<DelegationTokenIdentifier> token, final URI url) {
  ServerBootstrap bootstrap = new ServerBootstrap(
      new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
          Executors.newCachedThreadPool()));

  bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
    @Override
    public ChannelPipeline getPipeline() throws Exception {
      return Channels.pipeline(new HttpRequestDecoder(),
          new HttpChunkAggregator(65536), new HttpResponseEncoder(),
          new CredentialsLogicHandler(token, url.toString()));
    }
  });
  bootstrap.bind(new InetSocketAddress("localhost", port));
  return bootstrap;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestDelegationTokenRemoteFetcher.java

示例4: start

import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //導入依賴的package包/類
@Override
public void start() throws KairosDBException
{
	// Configure the server.
	serverBootstrap = new ServerBootstrap(
			new NioServerSocketChannelFactory(
					Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("telnet-boss-%d").build()),
					Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("telnet-worker-%d").build())));

	// Configure the pipeline factory.
	serverBootstrap.setPipelineFactory(this);
	serverBootstrap.setOption("child.tcpNoDelay", true);
	serverBootstrap.setOption("child.keepAlive", true);
	serverBootstrap.setOption("reuseAddress", true);

	// Bind and start to accept incoming connections.
	serverBootstrap.bind(new InetSocketAddress(address, port));
}
 
開發者ID:quqiangsheng,項目名稱:abhot,代碼行數:19,代碼來源:TelnetServer.java

示例5: main

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

示例6: connect

import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //導入依賴的package包/類
/**
 * Startup a ServerBootstrap with NioServerSocketChannelFactory using the
 * portNo specified in the constructor.
 * 
 * @return
 */
public ServerBootstrap connect() {

	bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
			Executors.newCachedThreadPool(),
			Executors.newCachedThreadPool()));

	bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
		@Override
		public ChannelPipeline getPipeline() throws Exception {
			return Channels.pipeline(new MessageFrameDecoder(),  new MessageEventBagHandler(bagList));
		}
	});

	System.out.println("Binding to: localhost:" + portNo);
	bootstrap.bind(new InetSocketAddress("localhost", portNo));

	return bootstrap;

}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:26,代碼來源:ServerUtil.java

示例7: connectServer

import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //導入依賴的package包/類
private ServerBootstrap connectServer(boolean simulateConflict,
		boolean simulateConflictErrorPointer) {

	ServerBootstrap bootstrap = new ServerBootstrap(
			new NioServerSocketChannelFactory(
					Executors.newCachedThreadPool(),
					Executors.newCachedThreadPool()));

	final MessageEventBagHandler messagEventBagHandler = new MessageEventBagHandler(
			bagList, simulateConflict, simulateConflictErrorPointer);
	bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
		@Override
		public ChannelPipeline getPipeline() throws Exception {
			return Channels.pipeline(new MessageFrameDecoder(),
					messagEventBagHandler);
		}
	});

	bootstrap.bind(new InetSocketAddress(testPort));

	return bootstrap;

}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:24,代碼來源:TestFilesSendWorker.java

示例8: connectServer

import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //導入依賴的package包/類
private ServerBootstrap connectServer() {

		ServerBootstrap bootstrap = new ServerBootstrap(
				new NioServerSocketChannelFactory(
						Executors.newCachedThreadPool(),
						Executors.newCachedThreadPool()));

		bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
			@Override
			public ChannelPipeline getPipeline() throws Exception {
				return Channels.pipeline(new MessageFrameDecoder(),
						new MessageEventBagHandler(bagList));
			}
		});

		bootstrap.bind(new InetSocketAddress(testPort));

		return bootstrap;

	}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:21,代碼來源:TestFilesSendWorkerConflict.java

示例9: connect

import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //導入依賴的package包/類
@Override
public void connect() {

	workerService = createWorkerService(getThreadPoolType(CollectorProperties.WRITER.COLLECTOR_WORKER_THREAD_POOL));

	workerbossService = createWorkderBossService(getThreadPoolType(CollectorProperties.WRITER.COLLECTOR_WORKERBOSS_THREAD_POOL));
	channelFactory = new NioServerSocketChannelFactory(workerbossService,
			workerService);

	bootstrap = new ServerBootstrap(channelFactory);

	bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
		@Override
		public ChannelPipeline getPipeline() throws Exception {
			return Channels.pipeline(ipFilterHandler,
					new MessageFrameDecoder(), new ReadTimeoutHandler(
							HashedWheelTimerFactory.getInstance(),
							readTimeout, TimeUnit.MILLISECONDS),
					metricsHandler, channelHandler);
		}
	});

	bootstrap.bind(new InetSocketAddress(port));

}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:26,代碼來源:CollectorServerImpl.java

示例10: connectLockBootstrap

import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //導入依賴的package包/類
/**
 * Startup a ServerBootstrap with NioServerSocketChannelFactory using the
 * portNo specified in the constructor.
 * 
 */
private void connectLockBootstrap() {

	lockBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
			Executors.newCachedThreadPool(),
			Executors.newCachedThreadPool()));

	lockBootstrap.setPipelineFactory(new ChannelPipelineFactory() {
		@Override
		public ChannelPipeline getPipeline() throws Exception {
			return Channels.pipeline(new MessageFrameDecoder(),
					metricHandler, lockHandler);
		}
	});

	lockBootstrap.bind(new InetSocketAddress(lockPort));

}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:23,代碼來源:CoordinationServerImpl.java

示例11: connectUnlockBootstrap

import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //導入依賴的package包/類
/**
 * Startup a ServerBootstrap with NioServerSocketChannelFactory using the
 * portNo specified in the constructor.
 * 
 */
private void connectUnlockBootstrap() {

	unlockBootstrap = new ServerBootstrap(
			new NioServerSocketChannelFactory(
					Executors.newCachedThreadPool(),
					Executors.newCachedThreadPool()));

	unlockBootstrap.setPipelineFactory(new ChannelPipelineFactory() {
		@Override
		public ChannelPipeline getPipeline() throws Exception {
			return Channels.pipeline(new MessageFrameDecoder(),
					unlockHandler);
		}
	});

	unlockBootstrap.bind(new InetSocketAddress(releaseLockPort));

}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:24,代碼來源:CoordinationServerImpl.java

示例12: TSOChannelHandler

import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //導入依賴的package包/類
@Inject
public TSOChannelHandler(TSOServerConfig config, RequestProcessor requestProcessor, MetricsRegistry metrics) {

    this.config = config;
    this.metrics = metrics;
    this.requestProcessor = requestProcessor;
    // Setup netty listener
    this.factory = new NioServerSocketChannelFactory(
            Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("boss-%d").build()),
            Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("worker-%d").build()),
            (Runtime.getRuntime().availableProcessors() * 2 + 1) * 2);

    this.bootstrap = new ServerBootstrap(factory);
    bootstrap.setPipelineFactory(new TSOPipelineFactory(this));

}
 
開發者ID:apache,項目名稱:incubator-omid,代碼行數:17,代碼來源:TSOChannelHandler.java

示例13: ProgrammableTSOServer

import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //導入依賴的package包/類
@Inject
public ProgrammableTSOServer(int port) {
    // Setup netty listener
    factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(new ThreadFactoryBuilder()
            .setNameFormat("boss-%d").build()), Executors.newCachedThreadPool(new ThreadFactoryBuilder()
            .setNameFormat("worker-%d").build()), (Runtime.getRuntime().availableProcessors() * 2 + 1) * 2);

    // Create the global ChannelGroup
    channelGroup = new DefaultChannelGroup(ProgrammableTSOServer.class.getName());

    ServerBootstrap bootstrap = new ServerBootstrap(factory);
    bootstrap.setPipelineFactory(new TSOChannelHandler.TSOPipelineFactory(this));

    // Add the parent channel to the group
    Channel channel = bootstrap.bind(new InetSocketAddress(port));
    channelGroup.add(channel);

    LOG.info("********** Dumb TSO Server running on port {} **********", port);
}
 
開發者ID:apache,項目名稱:incubator-omid,代碼行數:20,代碼來源:ProgrammableTSOServer.java

示例14: start

import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //導入依賴的package包/類
public void start()
{
	//Configure the server
	NioServerSocketChannelFactory nioFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
		Executors.newCachedThreadPool());
	ServerBootstrap bootstrap = new ServerBootstrap(nioFactory);
	
	// Configure the pipeline factory.
	bootstrap.setPipelineFactory(new TextProtocolPipelineFactory());
	
	//some more options
	bootstrap.setOption("child.tcpNoDelay", true);
       bootstrap.setOption("child.keepAlive", true);
	
	// Bind and start to accept incoming connections.
	this.channel = bootstrap.bind(new InetSocketAddress(1504));
	
	System.out.println("--------------------------------------------");
       System.out.println("Netty Http Server successfully loaded on port ("+1504+").....");
       System.out.println("--------------------------------------------");
}
 
開發者ID:ZalemSoftware,項目名稱:OpenMobster,代碼行數:22,代碼來源:TextProtocolServer.java

示例15: doLoad

import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; //導入依賴的package包/類
@Override
protected boolean doLoad() throws ModuleException {

	serverBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool(),
			workerCount));

	serverBootstrap.setPipelineFactory(new MyChannelPipelineFactory(this));
	serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
	serverBootstrap.setOption("child.keepAlive", tcpKeepAlive);
	if (tcpSendBufferSize > 0) {
		serverBootstrap.setOption("child.sendBufferSize", tcpSendBufferSize);
	}
	if (tcpReceiveBufferSize > 0) {
		serverBootstrap.setOption("child.receiveBufferSize", tcpReceiveBufferSize);
	}
	serverBootstrap.setOption("reuseAddress", reuseAddress);
	serverBootstrap.setOption("child.reuseAddress", reuseAddress);

	serverChannel = serverBootstrap.bind(new InetSocketAddress(port));
	logger.debug("Bound to port [{}]", port);

	return true;
}
 
開發者ID:gncloud,項目名稱:fastcatsearch3,代碼行數:24,代碼來源:HttpTransportModule.java


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