public <T extends TransportResponse> void sendRequest(
      final DiscoveryNode node,
      final String action,
      final TransportRequest request,
      final TransportRequestOptions options,
      TransportResponseHandler<T> handler) {
    if (node == null) {
      throw new ElasticsearchIllegalStateException("can't send request to a null node");
    }
    final long requestId = newRequestId();
    TimeoutHandler timeoutHandler = null;
    try {
      clientHandlers.put(requestId, new RequestHolder<>(handler, node, action, timeoutHandler));
      if (started.get() == false) {
        // if we are not started the exception handling will remove the RequestHolder again and
        // calls the handler to notify the caller.
        // it will only notify if the toStop code hasn't done the work yet.
        throw new TransportException("TransportService is closed stopped can't send request");
      }
      if (options.timeout() != null) {
        timeoutHandler = new TimeoutHandler(requestId);
        timeoutHandler.future =
            threadPool.schedule(options.timeout(), ThreadPool.Names.GENERIC, timeoutHandler);
      }
      transport.sendRequest(node, requestId, action, request, options);
    } catch (final Throwable e) {
      // usually happen either because we failed to connect to the node
      // or because we failed serializing the message
      final RequestHolder holderToNotify = clientHandlers.remove(requestId);
      // if the scheduler raise a EsRejectedExecutionException (due to shutdown), we may have a
      // timeout handler, but no future
      if (timeoutHandler != null) {
        FutureUtils.cancel(timeoutHandler.future);
      }

      // If holderToNotify == null then handler has already been taken care of.
      if (holderToNotify != null) {
        // callback that an exception happened, but on a different thread since we don't
        // want handlers to worry about stack overflows
        final SendRequestTransportException sendRequestException =
            new SendRequestTransportException(node, action, e);
        threadPool
            .executor(ThreadPool.Names.GENERIC)
            .execute(
                new Runnable() {
                  @Override
                  public void run() {
                    holderToNotify.handler().handleException(sendRequestException);
                  }
                });
      }
    }
  }
 private void notifyTimeout(final long availableSequence) {
   try {
     if (timeoutHandler != null) {
       timeoutHandler.onTimeout(availableSequence);
     }
   } catch (Throwable e) {
     exceptionHandler.handleEventException(e, availableSequence, null);
   }
 }
        @Override
        public void run() {
          // TODO Auto-generated method stub
          List<NameValuePair> params = new ArrayList<NameValuePair>();
          params.add(new BasicNameValuePair("Request", "RequestCommentList"));
          params.add(
              new BasicNameValuePair(
                  "GymID", CourtCommentActivity.this.getIntent().getStringExtra("ID")));

          String result = new HttpPostConnection("CommentServer", params).httpConnection();

          if (result.equals("timeout")) {
            Message msg = new Message();
            Bundle b = new Bundle();
            msg.setData(b);
            timeoutHandler.sendMessage(msg);
          } else {

            try {
              commentID = new JSONObject(result);

              sumPage = (int) (commentID.getInt("CommentNum") / eachPageNum);
              lastPageItemNum = commentID.getInt("CommentNum") - sumPage * eachPageNum;
              if (commentID.getInt("CommentNum") == 0) {
                Message msg = new Message();
                Bundle b = new Bundle();
                msg.setData(b);
                closeGifHandler.sendMessage(msg);

                msg = new Message();
                b = new Bundle();
                msg.setData(b);
                closeProgressHandler.sendMessage(msg);
                return;
              }
              new Thread(r_EachPageComment).start();

            } catch (JSONException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          }
        }