List of usage examples for org.apache.http.nio NHttpServerConnection getMetrics
HttpConnectionMetrics getMetrics();
From source file:org.apache.synapse.transport.passthru.SourceRequest.java
/** * Produce the content in to the pipe.//from w ww . j a v a 2 s . com * @param conn the connection * @param decoder content decoder * * @throws java.io.IOException if an error occurs * @return number of bytes read */ public int read(NHttpServerConnection conn, ContentDecoder decoder) throws IOException { if (pipe == null) { throw new IllegalStateException("A Pipe must be connected before calling read"); } if (entityEnclosing) { int bytes = pipe.produce(decoder); if (decoder.isCompleted()) { conn.getContext().setAttribute(PassThroughConstants.REQ_FROM_CLIENT_READ_END_TIME, System.currentTimeMillis()); sourceConfiguration.getMetrics() .notifyReceivedMessageSize(conn.getMetrics().getReceivedBytesCount()); // Update connection state SourceContext.updateState(conn, ProtocolState.REQUEST_DONE); // Suspend client input conn.suspendInput(); } return bytes; } else { throw new IllegalStateException("Only Entity Enclosing Requests " + "can read content in to the pipe"); } }
From source file:org.apache.synapse.transport.passthru.SourceResponse.java
/** * Consume the content through the Pipe and write them to the wire * @param conn connection/* w w w .j av a 2 s .co m*/ * @param encoder encoder * @throws java.io.IOException if an error occurs * @return number of bytes written */ public int write(NHttpServerConnection conn, ContentEncoder encoder) throws IOException { int bytes = 0; if (pipe != null) { bytes = pipe.consume(encoder); } else { encoder.complete(); } // Update connection state if (encoder.isCompleted()) { SourceContext.updateState(conn, ProtocolState.RESPONSE_DONE); sourceConfiguration.getMetrics().notifySentMessageSize(conn.getMetrics().getSentBytesCount()); if (response != null && !this.connStrategy.keepAlive(response, conn.getContext())) { SourceContext.updateState(conn, ProtocolState.CLOSING); sourceConfiguration.getSourceConnections().closeConnection(conn); } else if (SourceContext.get(conn).isShutDown()) { // we need to shut down if the shutdown flag is set SourceContext.updateState(conn, ProtocolState.CLOSING); sourceConfiguration.getSourceConnections().closeConnection(conn); } else { // Reset connection state sourceConfiguration.getSourceConnections().releaseConnection(conn); // Ready to deal with a new request conn.requestInput(); } } return bytes; }
From source file:org.apache.synapse.transport.nhttp.ServerHandler.java
public void responseReady(NHttpServerConnection conn) { if (JavaUtils.isTrueExplicitly(conn.getContext().getAttribute(NhttpConstants.FORCE_CLOSING)) && !JavaUtils.isTrueExplicitly(conn.getContext().getAttribute(NhttpConstants.MESSAGE_IN_FLIGHT))) { try {//www.j a va 2 s .c om if (log.isDebugEnabled()) { log.debug(conn + ": Closing a persisted connection since it is forced : " + conn); } conn.close(); } catch (IOException ignore) { } return; } metrics.notifyReceivedMessageSize(conn.getMetrics().getReceivedBytesCount()); metrics.notifySentMessageSize(conn.getMetrics().getSentBytesCount()); conn.getMetrics().reset(); conn.getContext().removeAttribute(NhttpConstants.MESSAGE_IN_FLIGHT); if (log.isTraceEnabled()) { log.trace(conn + ": Ready to send response"); } }