List of usage examples for org.apache.http.nio.util SharedOutputBuffer close
public void close()
From source file:org.apache.synapse.transport.nhttp.ClientHandler.java
/** * Shutdown the connection ignoring any IO errors during the process * * @param conn the connection to be shutdown * @param isError whether shutdown is due to an error * @param errorMsg error message if shutdown happens on error *///from w w w. j a v a 2 s . co m private void shutdownConnection(final NHttpClientConnection conn, boolean isError, String errorMsg) { if (conn instanceof HttpInetConnection) { HttpInetConnection inetConnection = (HttpInetConnection) conn; if (log.isWarnEnabled() && (isError || log.isDebugEnabled())) { String msg = "Connection from local address : " + inetConnection.getLocalAddress() + ":" + inetConnection.getLocalPort() + " to remote address : " + inetConnection.getRemoteAddress() + ":" + inetConnection.getRemotePort() + " is closed!" + (errorMsg != null ? " - On error : " + errorMsg : ""); if (isError) { log.warn(msg); } else { log.debug(msg); } } if (countConnections) { removeConnectionRecord(inetConnection); } } HttpContext context = conn.getContext(); SharedOutputBuffer outputBuffer = (SharedOutputBuffer) context.getAttribute(REQUEST_SOURCE_BUFFER); if (outputBuffer != null) { outputBuffer.close(); } SharedInputBuffer inputBuffer = (SharedInputBuffer) context.getAttribute(RESPONSE_SINK_BUFFER); if (inputBuffer != null) { inputBuffer.close(); } try { conn.shutdown(); } catch (IOException ignore) { } context.removeAttribute(RESPONSE_SINK_BUFFER); context.removeAttribute(REQUEST_SOURCE_BUFFER); context.removeAttribute(CLIENT_CONNECTION_DEBUG); context.removeAttribute(CONNECTION_CREATION_TIME); }
From source file:org.apache.synapse.transport.nhttp.ServerHandler.java
/** * Shutdown the connection ignoring any IO errors during the process * @param conn the connection to be shutdown * @param isError whether shutdown is due to an error * @param errorMsg error message if shutdown happens on error *///from w w w .j a v a 2s .co m private void shutdownConnection(final NHttpServerConnection conn, boolean isError, String errorMsg) { SharedOutputBuffer outputBuffer = (SharedOutputBuffer) conn.getContext() .getAttribute(RESPONSE_SOURCE_BUFFER); if (outputBuffer != null) { outputBuffer.close(); } SharedInputBuffer inputBuffer = (SharedInputBuffer) conn.getContext().getAttribute(REQUEST_SINK_BUFFER); if (inputBuffer != null) { inputBuffer.close(); } if (log.isWarnEnabled() && (isError || log.isDebugEnabled()) && conn instanceof HttpInetConnection) { HttpInetConnection inetConnection = (HttpInetConnection) conn; InetAddress remoteAddress = inetConnection.getRemoteAddress(); int remotePort = inetConnection.getRemotePort(); String msg; if (remotePort != -1 && remoteAddress != null) { // If connection is still alive msg = "Connection from remote address : " + remoteAddress + ":" + remotePort + " to local address : " + inetConnection.getLocalAddress() + ":" + inetConnection.getLocalPort() + " is closed!" + (errorMsg != null ? " - On error : " + errorMsg : ""); } else { // if connection is already closed. obtain params from http context HttpContext httpContext = conn.getContext(); msg = "Connection from remote address : " + httpContext.getAttribute(NhttpConstants.CLIENT_REMOTE_ADDR) + ":" + httpContext.getAttribute(NhttpConstants.CLIENT_REMOTE_PORT) + " to local address : " + inetConnection.getLocalAddress() + ":" + inetConnection.getLocalPort() + " is closed!" + (errorMsg != null ? " - On error : " + errorMsg : ""); } if (isError) { log.warn(msg); } else { log.debug(msg); } } synchronized (this) { if (!activeConnections.isEmpty() && activeConnections.remove(conn) && log.isDebugEnabled()) { log.debug("Removing the connection : " + conn + " from pool of size : " + activeConnections.size()); } } try { conn.shutdown(); } catch (IOException ignore) { } }