当前位置: 首页>>代码示例>>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;未经允许,请勿转载。