You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2011/05/30 13:45:01 UTC
svn commit: r1129131 -
/httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/
Author: olegk
Date: Mon May 30 11:45:01 2011
New Revision: 1129131
URL: http://svn.apache.org/viewvc?rev=1129131&view=rev
Log:
Reverted to using a synthetic id for connection event identification instread of previously used one based on a local/remote address pair
Removed:
httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java
httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java
Modified:
httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java
httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java
httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientHandler.java
httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java
httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServiceHandler.java
Modified: httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java?rev=1129131&r1=1129130&r2=1129131&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java Mon May 30 11:45:01 2011
@@ -34,7 +34,6 @@ import java.nio.channels.ByteChannel;
import java.nio.channels.SelectionKey;
import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.http.nio.reactor.IOSession;
import org.apache.http.nio.reactor.SessionBufferStatus;
@@ -47,18 +46,20 @@ public class LoggingIOSession implements
private final Log log;
private final Wire wirelog;
+ private final String id;
private final IOSession session;
private final ByteChannel channel;
- public LoggingIOSession(final IOSession session) {
+ public LoggingIOSession(final IOSession session, final String id, final Log log, final Log wirelog) {
super();
if (session == null) {
throw new IllegalArgumentException("I/O session may not be null");
}
this.session = session;
this.channel = new LoggingByteChannel();
- this.log = LogFactory.getLog(session.getClass());
- this.wirelog = new Wire(LogFactory.getLog("org.apache.http.wire"), getId());
+ this.id = id;
+ this.log = log;
+ this.wirelog = new Wire(wirelog, this.id);
}
public ByteChannel channel() {
@@ -99,27 +100,27 @@ public class LoggingIOSession implements
public void setEventMask(int ops) {
this.session.setEventMask(ops);
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + " " + this.session + ": Event mask set " + formatOps(ops));
+ this.log.debug(this.id + " " + this.session + ": Event mask set " + formatOps(ops));
}
}
public void setEvent(int op) {
this.session.setEvent(op);
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + " " + this.session + ": Event set " + formatOps(op));
+ this.log.debug(this.id + " " + this.session + ": Event set " + formatOps(op));
}
}
public void clearEvent(int op) {
this.session.clearEvent(op);
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + " " + this.session + ": Event cleared " + formatOps(op));
+ this.log.debug(this.id + " " + this.session + ": Event cleared " + formatOps(op));
}
}
public void close() {
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + " " + this.session + ": Close");
+ this.log.debug(this.id + " " + this.session + ": Close");
}
this.session.close();
}
@@ -134,7 +135,7 @@ public class LoggingIOSession implements
public void shutdown() {
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + " " + this.session + ": Shutdown");
+ this.log.debug(this.id + " " + this.session + ": Shutdown");
}
this.session.shutdown();
}
@@ -145,7 +146,7 @@ public class LoggingIOSession implements
public void setSocketTimeout(int timeout) {
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + " " + this.session + ": Set timeout " + timeout);
+ this.log.debug(this.id + " " + this.session + ": Set timeout " + timeout);
}
this.session.setSocketTimeout(timeout);
}
@@ -168,27 +169,21 @@ public class LoggingIOSession implements
public void setAttribute(final String name, final Object obj) {
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + " " + this.session + ": Set attribute " + name);
+ this.log.debug(this.id + " " + this.session + ": Set attribute " + name);
}
this.session.setAttribute(name, obj);
}
public Object removeAttribute(final String name) {
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + " " + this.session + ": Remove attribute " + name);
+ this.log.debug(this.id + " " + this.session + ": Remove attribute " + name);
}
return this.session.removeAttribute(name);
}
- private String getId() {
- StringBuilder buf = new StringBuilder();
- buf.append(getLocalAddress()).append("->").append(getRemoteAddress());
- return buf.toString();
- }
-
@Override
public String toString() {
- return getId() + " " + this.session.toString();
+ return this.id + " " + this.session.toString();
}
class LoggingByteChannel implements ByteChannel {
@@ -196,7 +191,7 @@ public class LoggingIOSession implements
public int read(final ByteBuffer dst) throws IOException {
int bytesRead = session.channel().read(dst);
if (log.isDebugEnabled()) {
- log.debug(getId() + " " + session + ": " + bytesRead + " bytes read");
+ log.debug(id + " " + session + ": " + bytesRead + " bytes read");
}
if (bytesRead > 0 && wirelog.isEnabled()) {
ByteBuffer b = dst.duplicate();
@@ -211,7 +206,7 @@ public class LoggingIOSession implements
public int write(final ByteBuffer src) throws IOException {
int byteWritten = session.channel().write(src);
if (log.isDebugEnabled()) {
- log.debug(getId() + " " + session + ": " + byteWritten + " bytes written");
+ log.debug(id + " " + session + ": " + byteWritten + " bytes written");
}
if (byteWritten > 0 && wirelog.isEnabled()) {
ByteBuffer b = src.duplicate();
@@ -225,7 +220,7 @@ public class LoggingIOSession implements
public void close() throws IOException {
if (log.isDebugEnabled()) {
- log.debug(getId() + " " + session + ": Channel close");
+ log.debug(id + " " + session + ": Channel close");
}
session.channel().close();
}
Modified: httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java?rev=1129131&r1=1129130&r2=1129131&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java Mon May 30 11:45:01 2011
@@ -29,6 +29,7 @@ package org.apache.http.contrib.logging;
import java.io.IOException;
import java.nio.channels.ReadableByteChannel;
+import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -49,23 +50,34 @@ import org.apache.http.params.HttpParams
public class LoggingNHttpClientConnection extends DefaultNHttpClientConnection {
+ private static final AtomicLong COUNT = new AtomicLong();
+
private final Log log;
+ private final Log iolog;
private final Log headerlog;
+ private final Log wirelog;
+ private final String id;
public LoggingNHttpClientConnection(
- final IOSession session,
- final HttpResponseFactory responseFactory,
- final ByteBufferAllocator allocator,
- final HttpParams params) {
+ final IOSession session,
+ final HttpResponseFactory responseFactory,
+ final ByteBufferAllocator allocator,
+ final HttpParams params) {
super(session, responseFactory, allocator, params);
this.log = LogFactory.getLog(getClass());
+ this.iolog = LogFactory.getLog(session.getClass());
this.headerlog = LogFactory.getLog("org.apache.http.headers");
+ this.wirelog = LogFactory.getLog("org.apache.http.wire");
+ this.id = "http-outgoing-" + COUNT.incrementAndGet();
+ if (this.iolog.isDebugEnabled() || this.wirelog.isDebugEnabled()) {
+ this.session = new LoggingIOSession(session, this.id, this.headerlog, this.wirelog);
+ }
}
@Override
public void close() throws IOException {
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + ": Close connection");
+ this.log.debug(this.id + ": Close connection");
}
super.close();
}
@@ -73,7 +85,7 @@ public class LoggingNHttpClientConnectio
@Override
public void shutdown() throws IOException {
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + ": Shutdown connection");
+ this.log.debug(this.id + ": Shutdown connection");
}
super.shutdown();
}
@@ -81,7 +93,7 @@ public class LoggingNHttpClientConnectio
@Override
public void submitRequest(final HttpRequest request) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + ": " + request.getRequestLine().toString());
+ this.log.debug(this.id + ": " + request.getRequestLine().toString());
}
super.submitRequest(request);
}
@@ -89,7 +101,7 @@ public class LoggingNHttpClientConnectio
@Override
public void consumeInput(final NHttpClientHandler handler) {
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + ": Consume input");
+ this.log.debug(this.id + ": Consume input");
}
super.consumeInput(handler);
}
@@ -97,7 +109,7 @@ public class LoggingNHttpClientConnectio
@Override
public void produceOutput(final NHttpClientHandler handler) {
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + ": Produce output");
+ this.log.debug(this.id + ": Produce output");
}
super.produceOutput(handler);
}
@@ -119,17 +131,9 @@ public class LoggingNHttpClientConnectio
super.createResponseParser(buffer, responseFactory, params));
}
- private String getId() {
- StringBuilder buf = new StringBuilder();
- buf.append(getLocalAddress()).append(":").append(getLocalPort())
- .append("->")
- .append(getRemoteAddress()).append(":").append(getRemotePort());
- return buf.toString();
- }
-
@Override
public String toString() {
- return getId();
+ return this.id;
}
class LoggingNHttpMessageWriter implements NHttpMessageWriter<HttpRequest> {
@@ -147,10 +151,10 @@ public class LoggingNHttpClientConnectio
public void write(final HttpRequest message) throws IOException, HttpException {
if (message != null && headerlog.isDebugEnabled()) {
- headerlog.debug(getId() + " >> " + message.getRequestLine().toString());
+ headerlog.debug(id + " >> " + message.getRequestLine().toString());
Header[] headers = message.getAllHeaders();
for (int i = 0; i < headers.length; i++) {
- headerlog.debug(getId() + " >> " + headers[i].toString());
+ headerlog.debug(id + " >> " + headers[i].toString());
}
}
this.writer.write(message);
@@ -178,10 +182,10 @@ public class LoggingNHttpClientConnectio
public HttpResponse parse() throws IOException, HttpException {
HttpResponse message = this.parser.parse();
if (message != null && headerlog.isDebugEnabled()) {
- headerlog.debug(getId() + " << " + message.getStatusLine().toString());
+ headerlog.debug(id + " << " + message.getStatusLine().toString());
Header[] headers = message.getAllHeaders();
for (int i = 0; i < headers.length; i++) {
- headerlog.debug(getId() + " << " + headers[i].toString());
+ headerlog.debug(id + " << " + headers[i].toString());
}
}
return message;
Modified: httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientHandler.java?rev=1129131&r1=1129130&r2=1129131&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientHandler.java Mon May 30 11:45:01 2011
@@ -31,7 +31,6 @@ import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.http.Header;
import org.apache.http.HttpException;
import org.apache.http.HttpResponse;
import org.apache.http.nio.ContentDecoder;
@@ -47,7 +46,6 @@ import org.apache.http.nio.NHttpClientHa
public class LoggingNHttpClientHandler implements NHttpClientHandler {
private final Log log;
- private final Log headerlog;
private final NHttpClientHandler handler;
public LoggingNHttpClientHandler(final NHttpClientHandler handler) {
@@ -57,7 +55,6 @@ public class LoggingNHttpClientHandler i
}
this.handler = handler;
this.log = LogFactory.getLog(handler.getClass());
- this.headerlog = LogFactory.getLog("org.apache.http.headers");
}
public void connected(final NHttpClientConnection conn, final Object attachment) {
@@ -107,13 +104,6 @@ public class LoggingNHttpClientHandler i
this.log.debug(conn + ": " + response.getStatusLine());
}
this.handler.responseReceived(conn);
- if (this.headerlog.isDebugEnabled()) {
- this.headerlog.debug(conn + " << " + response.getStatusLine().toString());
- Header[] headers = response.getAllHeaders();
- for (int i = 0; i < headers.length; i++) {
- this.headerlog.debug(conn + " << " + headers[i].toString());
- }
- }
}
public void inputReady(final NHttpClientConnection conn, final ContentDecoder decoder) {
Modified: httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java?rev=1129131&r1=1129130&r2=1129131&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java Mon May 30 11:45:01 2011
@@ -29,6 +29,7 @@ package org.apache.http.contrib.logging;
import java.io.IOException;
import java.nio.channels.ReadableByteChannel;
+import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -49,23 +50,34 @@ import org.apache.http.params.HttpParams
public class LoggingNHttpServerConnection extends DefaultNHttpServerConnection {
+ private static final AtomicLong COUNT = new AtomicLong();
+
private final Log log;
+ private final Log iolog;
private final Log headerlog;
+ private final Log wirelog;
+ private final String id;
public LoggingNHttpServerConnection(
- final IOSession session,
- final HttpRequestFactory requestFactory,
- final ByteBufferAllocator allocator,
- final HttpParams params) {
+ final IOSession session,
+ final HttpRequestFactory requestFactory,
+ final ByteBufferAllocator allocator,
+ final HttpParams params) {
super(session, requestFactory, allocator, params);
this.log = LogFactory.getLog(getClass());
+ this.iolog = LogFactory.getLog(session.getClass());
this.headerlog = LogFactory.getLog("org.apache.http.headers");
+ this.wirelog = LogFactory.getLog("org.apache.http.wire");
+ this.id = "http-incoming-" + COUNT.incrementAndGet();
+ if (this.iolog.isDebugEnabled() || this.wirelog.isDebugEnabled()) {
+ this.session = new LoggingIOSession(session, this.id, this.headerlog, this.wirelog);
+ }
}
@Override
public void close() throws IOException {
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + ": Close connection");
+ this.log.debug(this.id + ": Close connection");
}
super.close();
}
@@ -73,7 +85,7 @@ public class LoggingNHttpServerConnectio
@Override
public void shutdown() throws IOException {
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + ": Shutdown connection");
+ this.log.debug(this.id + ": Shutdown connection");
}
super.shutdown();
}
@@ -81,7 +93,7 @@ public class LoggingNHttpServerConnectio
@Override
public void submitResponse(final HttpResponse response) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + ": " + response.getStatusLine().toString());
+ this.log.debug(this.id + ": " + response.getStatusLine().toString());
}
super.submitResponse(response);
}
@@ -89,7 +101,7 @@ public class LoggingNHttpServerConnectio
@Override
public void consumeInput(final NHttpServiceHandler handler) {
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + ": Consume input");
+ this.log.debug(this.id + ": Consume input");
}
super.consumeInput(handler);
}
@@ -97,7 +109,7 @@ public class LoggingNHttpServerConnectio
@Override
public void produceOutput(final NHttpServiceHandler handler) {
if (this.log.isDebugEnabled()) {
- this.log.debug(getId() + ": Produce output");
+ this.log.debug(this.id + ": Produce output");
}
super.produceOutput(handler);
}
@@ -119,17 +131,9 @@ public class LoggingNHttpServerConnectio
super.createRequestParser(buffer, requestFactory, params));
}
- private String getId() {
- StringBuilder buf = new StringBuilder();
- buf.append(getLocalAddress()).append(":").append(getLocalPort())
- .append("->")
- .append(getRemoteAddress()).append(":").append(getRemotePort());
- return buf.toString();
- }
-
@Override
public String toString() {
- return getId();
+ return this.id;
}
class LoggingNHttpMessageWriter implements NHttpMessageWriter<HttpResponse> {
@@ -147,10 +151,10 @@ public class LoggingNHttpServerConnectio
public void write(final HttpResponse message) throws IOException, HttpException {
if (message != null && headerlog.isDebugEnabled()) {
- headerlog.debug(getId() + " << " + message.getStatusLine().toString());
+ headerlog.debug(id + " << " + message.getStatusLine().toString());
Header[] headers = message.getAllHeaders();
for (int i = 0; i < headers.length; i++) {
- headerlog.debug(getId() + " << " + headers[i].toString());
+ headerlog.debug(id + " << " + headers[i].toString());
}
}
this.writer.write(message);
@@ -178,10 +182,10 @@ public class LoggingNHttpServerConnectio
public HttpRequest parse() throws IOException, HttpException {
HttpRequest message = this.parser.parse();
if (message != null && headerlog.isDebugEnabled()) {
- headerlog.debug(getId() + " >> " + message.getRequestLine().toString());
+ headerlog.debug(id + " >> " + message.getRequestLine().toString());
Header[] headers = message.getAllHeaders();
for (int i = 0; i < headers.length; i++) {
- headerlog.debug(getId() + " >> " + headers[i].toString());
+ headerlog.debug(id + " >> " + headers[i].toString());
}
}
return message;
Modified: httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServiceHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServiceHandler.java?rev=1129131&r1=1129130&r2=1129131&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServiceHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServiceHandler.java Mon May 30 11:45:01 2011
@@ -31,7 +31,6 @@ import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.http.Header;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.nio.ContentDecoder;
@@ -47,7 +46,6 @@ import org.apache.http.nio.NHttpServiceH
public class LoggingNHttpServiceHandler implements NHttpServiceHandler {
private final Log log;
- private final Log headerlog;
private final NHttpServiceHandler handler;
public LoggingNHttpServiceHandler(final NHttpServiceHandler handler) {
@@ -57,7 +55,6 @@ public class LoggingNHttpServiceHandler
}
this.handler = handler;
this.log = LogFactory.getLog(handler.getClass());
- this.headerlog = LogFactory.getLog("org.apache.http.headers");
}
public void connected(final NHttpServerConnection conn) {
@@ -90,13 +87,6 @@ public class LoggingNHttpServiceHandler
this.log.debug(conn + ": " + request.getRequestLine());
}
this.handler.requestReceived(conn);
- if (this.headerlog.isDebugEnabled()) {
- this.headerlog.debug(conn + " >> " + request.getRequestLine().toString());
- Header[] headers = request.getAllHeaders();
- for (int i = 0; i < headers.length; i++) {
- this.headerlog.debug(conn + " >> " + headers[i].toString());
- }
- }
}
public void outputReady(final NHttpServerConnection conn, final ContentEncoder encoder) {