Hadoop维护IPC链接

IPC链接上长时间没有发生远程调用,客户端会发送一个心跳消息给服务器端,用于维护链接。

Connection的lastActivity用来记录上次发生IPC通信的时间。

 

Connection.touch方法更新lastActivity为当前时间,在setupIOstream和receiveResponse中被调用。

lastActivity和当前时间超过某个值(在${ipc.ping.interval}),则需要发送心跳消息。

private synchronized void sendPing() throws IOException {
      long curTime = System.currentTimeMillis();
      if ( curTime - lastActivity.get() >= pingInterval) {
        lastActivity.set(curTime);
        synchronized (out) {
          out.writeInt(PING_CALL_ID);
          out.flush();
        }
      }
    }

 

服务器端也使用lastContact来维护链接。

posted @ 2014-12-25 17:39  dorothychai  阅读(259)  评论(0编辑  收藏  举报