コード例 #1
0
  public void responseReady(NHttpServerConnection conn) {
    try {
      ProtocolState protocolState = SourceContext.getState(conn);
      if (protocolState.compareTo(ProtocolState.REQUEST_DONE) < 0) {
        return;
      }

      if (protocolState.compareTo(ProtocolState.CLOSING) >= 0) {
        return;
      }

      if (protocolState != ProtocolState.REQUEST_DONE) {
        handleInvalidState(conn, "Writing a response");
        return;
      }

      // because the duplex nature of http core we can reach hear without a actual response
      SourceResponse response = SourceContext.getResponse(conn);
      if (response != null) {
        response.start(conn);

        metrics.incrementMessagesSent();
      }
    } catch (IOException e) {
      logIOException(conn, e);

      informWriterError(conn);

      SourceContext.updateState(conn, ProtocolState.CLOSING);
      sourceConfiguration.getSourceConnections().shutDownConnection(conn);
    } catch (HttpException e) {
      log.error(e.getMessage(), e);

      informWriterError(conn);

      SourceContext.updateState(conn, ProtocolState.CLOSING);
      sourceConfiguration.getSourceConnections().shutDownConnection(conn);
    }
  }
コード例 #2
0
 public static ProtocolState getProtocolState(int i) {
   return ProtocolState.values()[i];
 }