欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

Thrift中socket關鍵的作用是什么

本篇文章為大家展示了Thrift中socket 關鍵的作用是什么,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。

成都創(chuàng)新互聯(lián)主營甘谷網(wǎng)站建設的網(wǎng)絡公司,主營網(wǎng)站建設方案,APP應用開發(fā),甘谷h5成都小程序開發(fā)搭建,甘谷網(wǎng)站營銷推廣歡迎甘谷等地區(qū)企業(yè)咨詢

TNonblockingServerSocket:

  public TNonblockingServerSocket(NonblockingAbstractServerSocketArgs args) throws TTransportException {
    clientTimeout_ = args.clientTimeout;
    try {
      serverSocketChannel = ServerSocketChannel.open();
      serverSocketChannel.configureBlocking(false);

      // Make server socket
      serverSocket_ = serverSocketChannel.socket();
      // Prevent 2MSL delay problem on server restarts
      serverSocket_.setReuseAddress(true);//是否重用地址
      // Bind to listening port
      serverSocket_.bind(args.bindAddr, args.backlog);//backlog 可接受連接數(shù)量
    } catch (IOException ioe) {
      serverSocket_ = null;
      throw new TTransportException("Could not create ServerSocket on address " + args.bindAddr.toString() + ".", ioe);
    }
  }

  public void listen() throws TTransportException {
    // Make sure not to block on accept
    if (serverSocket_ != null) {
      try {
        serverSocket_.setSoTimeout(0);
      } catch (SocketException sx) {
        LOGGER.error("Socket exception while setting socket timeout", sx);
      }
    }
  }

TNonblockingServer:
 

  private SelectAcceptThread selectAcceptThread_;  //內(nèi)部新事件,監(jiān)聽線程

  //父類中有相應啟動操作 --serve();
  public TNonblockingServer(AbstractNonblockingServerArgs args) {
    super(args);
  }

SelectAcceptThread  

public void run() {
      try {
        if (eventHandler_ != null) {
          eventHandler_.preServe();
        }

        while (!stopped_) {
          select();
          processInterestChanges();
        }
        for (SelectionKey selectionKey : selector.keys()) {
          cleanupSelectionKey(selectionKey);
        }
      } catch (Throwable t) {
        LOGGER.error("run() exiting due to uncaught error", t);
      } finally {
        try {
          selector.close();
        } catch (IOException e) {
          LOGGER.error("Got an IOException while closing selector!", e);
        }
        stopped_ = true;
      }
    }


 private void select() {
      try {
        // wait for io events.
        selector.select();

        // process the io events we received
        Iterator<SelectionKey> selectedKeys = selector.selectedKeys().iterator();
        while (!stopped_ && selectedKeys.hasNext()) {
          SelectionKey key = selectedKeys.next();
          selectedKeys.remove();

          // skip if not valid
          if (!key.isValid()) {
            cleanupSelectionKey(key);
            continue;
          }

          // if the key is marked Accept, then it has to be the server
          // transport.
          if (key.isAcceptable()) {
            handleAccept();
          } else if (key.isReadable()) {
            // deal with reads
            handleRead(key);
          } else if (key.isWritable()) {
            // deal with writes
            handleWrite(key);
          } else {
            LOGGER.warn("Unexpected state in select! " + key.interestOps());
          }
        }
      } catch (IOException e) {
        LOGGER.warn("Got an IOException while selecting!", e);
      }
    }
    /**
     * Do the work required to read from a readable client. If the frame is
     * fully read, then invoke the method call.
     */
    protected void handleRead(SelectionKey key) {
      FrameBuffer buffer = (FrameBuffer) key.attachment();
      if (!buffer.read()) {
        cleanupSelectionKey(key);
        return;
      }

      // if the buffer's frame read is complete, invoke the method.
      if (buffer.isFrameFullyRead()) {
        if (!requestInvoke(buffer)) {//回調(diào),通過線程池,調(diào)用 FrameBuffer  中的 invoke () 方法 進行數(shù)據(jù)讀取
          cleanupSelectionKey(key);
        }
      }
    }

// 創(chuàng)建一個新的線程進行回調(diào)
  protected boolean requestInvoke(FrameBuffer frameBuffer) {
    try {
      Runnable invocation = getRunnable(frameBuffer);
      invoker.execute(invocation);
      return true;
    } catch (RejectedExecutionException rx) {
      LOGGER.warn("ExecutorService rejected execution!", rx);
      return false;
    }
  }

  protected Runnable getRunnable(FrameBuffer frameBuffer){
    return new Invocation(frameBuffer);
  }

//Invocation 中回調(diào)方法
class Invocation implements Runnable {
  private final FrameBuffer frameBuffer;

  public Invocation(final FrameBuffer frameBuffer) {
    this.frameBuffer = frameBuffer;
  }

  public void run() {
    frameBuffer.invoke();
  }
}

FrameBuffer:

  public void invoke() {
      frameTrans_.reset(buffer_.array());
      response_.reset();

      try {
        if (eventHandler_ != null) {
          eventHandler_.processContext(context_, inTrans_, outTrans_);
        }
        processorFactory_.getProcessor(inTrans_).process(inProt_, outProt_);
        responseReady();
        return;
      } catch (TException te) {
        LOGGER.warn("Exception while invoking!", te);
      } catch (Throwable t) {
        LOGGER.error("Unexpected throwable while invoking!", t);
      }
      // This will only be reached when there is a throwable.
      state_ = FrameBufferState.AWAITING_CLOSE;
      requestSelectInterestChange();
    }

上述內(nèi)容就是Thrift中socket 關鍵的作用是什么,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

當前標題:Thrift中socket關鍵的作用是什么
標題網(wǎng)址:http://aaarwkj.com/article12/ggppgc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站微信公眾號網(wǎng)站制作、App設計、服務器托管、靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

h5響應式網(wǎng)站建設
我的农村中年激情熟妇| 蜜桃精品人妻一区二区三区 | 日韩精品一区二区视频| 婷婷综合伊人久久狠狠| 日韩精品一区二区三区中文| 91在线直播观看高清| 激情网站免费在线观看| 欧美精品成人在线一区| 黄色录像一级大片中国的| 精品自拍一区在线观看| 亚洲av成人精品网站推荐| 中文字幕伦理一区二区三区| av熟女乱一区二区三区| 国产亚洲一区二区三区午夜| 性生活的视频免费观看麻豆| 亚洲精品欧美激情专区| 亚洲国产成人精品av在线| 91日韩人妻一区二区三区| 69精品一区二区蜜桃视频| 日韩在线一区中文字幕| 国产蜜臀视频在线播放| 国产亚洲中文久久网久久| 亚洲av成人一区二区三区| 亚洲精品中文一区二区三区| 日本在线免费观看91 | 亚洲精品国产av成人网| 国产日韩熟女中文字幕| 日韩精品视频在线不卡| 国产污视频网站在线观看| 香蕉视频网站欧美一区| 欧美日韩国产免费,日日骚| 日韩一区二区三区成人| 门国产av一区二区三区| 亚洲女久久久噜噜噜综合| 久久日韩精品人妻一区二区| 亚洲男女尻逼片视频网站| 丝袜美腿亚洲欧美日韩| 日韩性生活视频免费播放| 成人黄色动作片在线观看| 日本韩国国语对白一区二区三区| 日本精品国产一区二区在线|