Java 类com.facebook.nifty.core.NettyServerTransport 实例源码

项目:ikasoa    文件:NettyIkasoaFactory.java   
@Override
public void start() throws STException {
    if (server == null) {
        ThriftServerDef thriftServerDef = new ThriftServerDefBuilder().listen(getServerPort())
                .withProcessor(getProcessor()).build();
        server = nettyServerConfig == null ? new NettyServerTransport(thriftServerDef)
                : new NettyServerTransport(thriftServerDef, nettyServerConfig, channelGroup);
    }
    server.start();
    LOG.debug("Server start .");
}
项目:high    文件:Server.java   
public static void startServer() {
    // Create the handler
    //ThriftTestService.Iface serviceInterface = 
   //   MyService.Iface serviceInterface = new MyServiceHandler();

    // Create the processor
    //TProcessor processor = new MyService.Processor<>(serviceInterface);

    // Create the processor
    //TProcessor processor = new ThriftTestService.Processor<>(new InMemoryScribe());

    InMemoryScribe inMemoryScribe = new InMemoryScribeImpl();
    TProtocolFactory protocolFactory  = new TBinaryProtocol.Factory();
    ThriftCodecManager thriftCodecManager = new ThriftCodecManager();
     List list  = new ArrayList<>();
     list.add(inMemoryScribe);

    ThriftServiceProcessor processor = new ThriftServiceProcessor(thriftCodecManager, Arrays.<ThriftEventHandler>asList(), inMemoryScribe);

    // Build the server definition
    ThriftServerDef serverDef = new ThriftServerDefBuilder().withProcessor(processor)
                                                            .build();

    // Create the server transport
    final NettyServerTransport server = new NettyServerTransport(serverDef  );

    // Create netty boss and executor thread pools
    ExecutorService bossExecutor = Executors.newCachedThreadPool();
    ExecutorService workerExecutor = Executors.newCachedThreadPool();

    // Start the server
    //server.start(bossExecutor, workerExecutor);
    server.start();
    // Arrange to stop the server at shutdown
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            try {
                server.stop();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    });
}
项目:high    文件:ThApp.java   
public static void main(String[] args) {
    ThriftServiceProcessor processor = new ThriftServiceProcessor(
               new ThriftCodecManager(),
               ImmutableList.<ThriftEventHandler>of(),
               new ThirdPartyCollectionServiceImpl()
       );



    // Build the server definition
    ThriftServerDef serverDef = new ThriftServerDefBuilder()
            .listen(8899)
            .withProcessor(processor)
            .build();

    // Create the server transport
    final NettyServerTransport server = new NettyServerTransport(serverDef  );

    // Create netty boss and executor thread pools
    ExecutorService bossExecutor = Executors.newCachedThreadPool();
    ExecutorService workerExecutor = Executors.newCachedThreadPool();

    // Start the server
    //server.start(bossExecutor, workerExecutor);
    server.start();
    // Arrange to stop the server at shutdown
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            try {
                server.stop();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    });

    /**ThreadPool taskWorkerExecutor = newFixedThreadPool(1);

       ThriftServerDef serverDef = ThriftServerDef.newBuilder()
               .listen(8899)
               .withProcessor(processor)
               .using(taskWorkerExecutor)
               .build();

       bossExecutor = newCachedThreadPool();
       ioWorkerExecutor = newCachedThreadPool();

       NettyServerConfig serverConfig = NettyServerConfig.newBuilder()
               .setBossThreadExecutor(bossExecutor)
               .setWorkerThreadExecutor(ioWorkerExecutor)
               .build();

       server = new ThriftServer(serverConfig, serverDef);
       server.start();**/

}
项目:NeverwinterDP-Commons    文件:NiftyServerUnitTest.java   
private void startServer(final ThriftServerDefBuilder thriftServerDefBuilder) {
  server = new NettyServerTransport(thriftServerDefBuilder.build(), NettyServerConfig.newBuilder().build(), new DefaultChannelGroup());
  server.start();
  port = ((InetSocketAddress) server.getServerChannel().getLocalAddress()).getPort();
}