<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Niftythrift服務(wù)端和客戶端實(shí)現(xiàn)

          聯(lián)合創(chuàng)作 · 2023-09-29 13:02

          Nifty是facebook公司開源的,基于nettythrift服務(wù)端和客戶端實(shí)現(xiàn)。

          然后使用此包就可以快速發(fā)布出基于netty的高效的服務(wù)端和客戶端代碼。

          示例:

          public void startServer() {
              // Create the handler
              MyService.Iface serviceInterface = new MyServiceHandler();
          
              // Create the processor
              TProcessor processor = new MyService.Processor<>(serviceInterface);
          
              // Build the server definition
              ThriftServerDef serverDef = new ThriftServerDefBuilder().withProcessor(processor)
                                                                      .build();
          
              // Create the server transport
              final NettyServerTransport server = new NettyServerTransport(serverDef,
                                                                           new NettyConfigBuilder(),
                                                                           new DefaultChannelGroup(),
                                                                           new HashedWheelTimer());
          
              // Create netty boss and executor thread pools
              ExecutorService bossExecutor = Executors.newCachedThreadPool();
              ExecutorService workerExecutor = Executors.newCachedThreadPool();
          
              // Start the server
              server.start(bossExecutor, workerExecutor);
          
              // 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();
                      }
                  }
              });
          }

          Or the same thing using guice:

          public void startGuiceServer() {
              final NiftyBootstrap bootstrap = Guice.createInjector(
                  Stage.PRODUCTION,
                  new NiftyModule() {
                      @Override
                      protected void configureNifty() {
                          // Create the handler
                          MyService.Iface serviceInterface = new MyServiceHandler();
          
                          // Create the processor
                          TProcessor processor = new MyService.Processor<>(serviceInterface);
          
                          // Build the server definition
                          ThriftServerDef serverDef = new ThriftServerDefBuilder().withProcessor(processor)
                                                                                  .build();
          
                          // Bind the definition
                          bind().toInstance(serverDef);
                      }
                  }).getInstance(NiftyBootstrap.class);
          
              // Start the server
              bootstrap.start();
          
              // Arrange to stop the server at shutdown
              Runtime.getRuntime().addShutdownHook(new Thread() {
                  @Override
                  public void run() {
                      bootstrap.stop();
                  }
              });
          }
          瀏覽 24
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  欧美淫色图 | 91无码人妻一区二区成人AⅤ | 免费看逼片 | 求毛片网站 | 大屌操综合 |