hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1784892 - in /httpcomponents/httpcore/trunk: httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/ httpcore5-testing/src/main/java/org/apache/hc/core5/testing/...
Date Wed, 01 Mar 2017 10:02:15 GMT
Author: olegk
Date: Wed Mar  1 10:02:14 2017
New Revision: 1784892

URL: http://svn.apache.org/viewvc?rev=1784892&view=rev
Log:
Improved (conciser) non-blocking i/o logging

Added:
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/Identifiable.java
  (with props)
Modified:
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOEventHandler.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalClientHttp1EventHandlerFactory.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalServerHttp1EventHandlerFactory.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalClientHttp2EventHandlerFactory.java
    httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalServerHttp2EventHandlerFactory.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ManagedIOSession.java
    httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpClientConnection.java?rev=1784892&r1=1784891&r2=1784892&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpClientConnection.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpClientConnection.java
Wed Mar  1 10:02:14 2017
@@ -44,10 +44,11 @@ import org.apache.hc.core5.http.io.HttpM
 import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
 import org.apache.hc.core5.http.message.RequestLine;
 import org.apache.hc.core5.http.message.StatusLine;
+import org.apache.hc.core5.util.Identifiable;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
-public class LoggingBHttpClientConnection extends DefaultBHttpClientConnection {
+public class LoggingBHttpClientConnection extends DefaultBHttpClientConnection implements
Identifiable {
 
     private static final AtomicLong COUNT = new AtomicLong();
 
@@ -78,6 +79,11 @@ public class LoggingBHttpClientConnectio
     }
 
     @Override
+    public String getId() {
+        return id;
+    }
+
+    @Override
     public void close() throws IOException {
         if (this.log.isDebugEnabled()) {
             this.log.debug(this.id + ": Close connection");

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java?rev=1784892&r1=1784891&r2=1784892&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java
Wed Mar  1 10:02:14 2017
@@ -44,9 +44,10 @@ import org.apache.hc.core5.http.io.HttpM
 import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
 import org.apache.hc.core5.http.message.RequestLine;
 import org.apache.hc.core5.http.message.StatusLine;
+import org.apache.hc.core5.util.Identifiable;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
-public class LoggingBHttpServerConnection extends DefaultBHttpServerConnection {
+public class LoggingBHttpServerConnection extends DefaultBHttpServerConnection implements
Identifiable {
 
     private static final AtomicLong COUNT = new AtomicLong();
 
@@ -72,6 +73,11 @@ public class LoggingBHttpServerConnectio
         this.wire = new Wire(LogManager.getLogger("org.apache.http.wire"), this.id);
     }
 
+    @Override
+    public String getId() {
+        return id;
+    }
+
     public LoggingBHttpServerConnection(final H1Config h1Config) {
         this(h1Config, null, null, null, null, null, null);
     }

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOEventHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOEventHandler.java?rev=1784892&r1=1784891&r2=1784892&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOEventHandler.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOEventHandler.java
Wed Mar  1 10:02:14 2017
@@ -54,7 +54,7 @@ public class LoggingIOEventHandler imple
     @Override
     public void connected(final IOSession session) {
         if (log.isDebugEnabled()) {
-            log.debug(id + " " + session + " connected");
+            log.debug(session + " connected");
         }
         handler.connected(session);
     }
@@ -62,7 +62,7 @@ public class LoggingIOEventHandler imple
     @Override
     public void inputReady(final IOSession session) {
         if (log.isDebugEnabled()) {
-            log.debug(id + " " + session + " input ready");
+            log.debug(session + " input ready");
         }
         handler.inputReady(session);
     }
@@ -70,7 +70,7 @@ public class LoggingIOEventHandler imple
     @Override
     public void outputReady(final IOSession session) {
         if (log.isDebugEnabled()) {
-            log.debug(id + " " + session + " output ready");
+            log.debug(session + " output ready");
         }
         handler.outputReady(session);
     }
@@ -78,7 +78,7 @@ public class LoggingIOEventHandler imple
     @Override
     public void timeout(final IOSession session) {
         if (log.isDebugEnabled()) {
-            log.debug(id + " " + session + " timeout");
+            log.debug(session + " timeout");
         }
         handler.timeout(session);
     }
@@ -91,7 +91,7 @@ public class LoggingIOEventHandler imple
     @Override
     public void disconnected(final IOSession session) {
         if (log.isDebugEnabled()) {
-            log.debug(id + " " + session + " disconnected");
+            log.debug(session + " disconnected");
         }
         handler.disconnected(session);
     }

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java?rev=1784892&r1=1784891&r2=1784892&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java
Wed Mar  1 10:02:14 2017
@@ -49,21 +49,24 @@ public class LoggingIOSession implements
 
     private final Logger log;
     private final Wire wirelog;
-    private final String id;
     private final IOSession session;
     private final ByteChannel channel;
 
-    public LoggingIOSession(final IOSession session, final String id, final Logger log, final
Logger wirelog) {
+    public LoggingIOSession(final IOSession session, final Logger log, final Logger wirelog)
{
         super();
         this.session = session;
-        this.id = id;
         this.log = log;
-        this.wirelog = wirelog != null ? new Wire(wirelog, this.id) : null;
+        this.wirelog = wirelog != null ? new Wire(wirelog, session.getId()) : null;
         this.channel = wirelog != null ? new LoggingByteChannel() : session.channel();
     }
 
-    public LoggingIOSession(final IOSession session, final String id, final Logger log) {
-        this(session, id, log, null);
+    public LoggingIOSession(final IOSession session, final Logger log) {
+        this(session, log, null);
+    }
+
+    @Override
+    public String getId() {
+        return session.getId();
     }
 
     @Override
@@ -124,7 +127,7 @@ public class LoggingIOSession implements
     public void setEventMask(final int ops) {
         this.session.setEventMask(ops);
         if (this.log.isDebugEnabled()) {
-            this.log.debug(this.id + " " + this.session + ": Event mask set " + formatOps(ops));
+            this.log.debug(this.session + " Event mask set " + formatOps(ops));
         }
     }
 
@@ -132,7 +135,7 @@ public class LoggingIOSession implements
     public void setEvent(final int op) {
         this.session.setEvent(op);
         if (this.log.isDebugEnabled()) {
-            this.log.debug(this.id + " " + this.session + ": Event set " + formatOps(op));
+            this.log.debug(this.session + " Event set " + formatOps(op));
         }
     }
 
@@ -140,14 +143,14 @@ public class LoggingIOSession implements
     public void clearEvent(final int op) {
         this.session.clearEvent(op);
         if (this.log.isDebugEnabled()) {
-            this.log.debug(this.id + " " + this.session + ": Event cleared " + formatOps(op));
+            this.log.debug(this.session + " Event cleared " + formatOps(op));
         }
     }
 
     @Override
     public void close() {
         if (this.log.isDebugEnabled()) {
-            this.log.debug(this.id + " " + this.session + ": Close");
+            this.log.debug(this.session + " Close");
         }
         this.session.close();
     }
@@ -165,7 +168,7 @@ public class LoggingIOSession implements
     @Override
     public void shutdown() {
         if (this.log.isDebugEnabled()) {
-            this.log.debug(this.id + " " + this.session + ": Shutdown");
+            this.log.debug(this.session + " Shutdown");
         }
         this.session.shutdown();
     }
@@ -178,7 +181,7 @@ public class LoggingIOSession implements
     @Override
     public void setSocketTimeout(final int timeout) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug(this.id + " " + this.session + ": Set timeout " + timeout);
+            this.log.debug(this.session + " Set timeout " + timeout);
         }
         this.session.setSocketTimeout(timeout);
     }
@@ -217,7 +220,7 @@ public class LoggingIOSession implements
 
     @Override
     public String toString() {
-        return this.id + " " + this.session.toString();
+        return this.session.toString();
     }
 
     class LoggingByteChannel implements ByteChannel {
@@ -226,7 +229,7 @@ public class LoggingIOSession implements
         public int read(final ByteBuffer dst) throws IOException {
             final int bytesRead = session.channel().read(dst);
             if (log.isDebugEnabled()) {
-                log.debug(id + " " + session + ": " + bytesRead + " bytes read");
+                log.debug(session + " " + bytesRead + " bytes read");
             }
             if (bytesRead > 0 && wirelog.isEnabled()) {
                 final ByteBuffer b = dst.duplicate();
@@ -242,7 +245,7 @@ public class LoggingIOSession implements
         public int write(final ByteBuffer src) throws IOException {
             final int byteWritten = session.channel().write(src);
             if (log.isDebugEnabled()) {
-                log.debug(id + " " + session + ": " + byteWritten + " bytes written");
+                log.debug(session + " " + byteWritten + " bytes written");
             }
             if (byteWritten > 0 && wirelog.isEnabled()) {
                 final ByteBuffer b = src.duplicate();
@@ -257,7 +260,7 @@ public class LoggingIOSession implements
         @Override
         public void close() throws IOException {
             if (log.isDebugEnabled()) {
-                log.debug(id + " " + session + ": Channel close");
+                log.debug(session + " Channel close");
             }
             session.channel().close();
         }

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalClientHttp1EventHandlerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalClientHttp1EventHandlerFactory.java?rev=1784892&r1=1784891&r2=1784892&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalClientHttp1EventHandlerFactory.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalClientHttp1EventHandlerFactory.java
Wed Mar  1 10:02:14 2017
@@ -28,7 +28,6 @@
 package org.apache.hc.core5.testing.nio.http;
 
 import java.util.Iterator;
-import java.util.concurrent.atomic.AtomicLong;
 
 import javax.net.ssl.SSLContext;
 
@@ -74,8 +73,6 @@ import org.apache.logging.log4j.Logger;
 @Contract(threading = ThreadingBehavior.IMMUTABLE)
 class InternalClientHttp1EventHandlerFactory implements IOEventHandlerFactory {
 
-    private static final AtomicLong COUNT = new AtomicLong();
-
     private final HttpProcessor httpProcessor;
     private final H1Config h1Config;
     private final CharCodingConfig charCodingConfig;
@@ -120,7 +117,7 @@ class InternalClientHttp1EventHandlerFac
 
     @Override
     public IOEventHandler createHandler(final IOSession ioSession, final Object attachment)
{
-        final String id = "http1-outgoing-" + COUNT.incrementAndGet();
+        final String id = ioSession.getId();
         if (sslContext != null && ioSession instanceof TransportSecurityLayer) {
             ((TransportSecurityLayer) ioSession).start(sslContext, null ,null, null);
         }
@@ -128,7 +125,7 @@ class InternalClientHttp1EventHandlerFac
         final Logger wireLog = LogManager.getLogger("org.apache.hc.core5.http.wire");
         final Logger headerLog = LogManager.getLogger("org.apache.hc.core5.http.headers");
         final ClientHttp1StreamDuplexer streamDuplexer = createClientHttp1StreamDuplexer(
-                new LoggingIOSession(ioSession, id, sessionLog, wireLog),
+                new LoggingIOSession(ioSession, sessionLog, wireLog),
                 httpProcessor,
                 h1Config,
                 charCodingConfig,
@@ -142,14 +139,14 @@ class InternalClientHttp1EventHandlerFac
                     @Override
                     public void onConnect(final HttpConnection connection) {
                         if (sessionLog.isDebugEnabled()) {
-                            sessionLog.debug(id + ": "  + connection + " connected");
+                            sessionLog.debug(id + " "  + connection + " connected");
                         }
                     }
 
                     @Override
                     public void onDisconnect(final HttpConnection connection) {
                         if (sessionLog.isDebugEnabled()) {
-                            sessionLog.debug(id + ": "  + connection + " disconnected");
+                            sessionLog.debug(id + " "  + connection + " disconnected");
                         }
                     }
 
@@ -158,7 +155,7 @@ class InternalClientHttp1EventHandlerFac
                         if (ex instanceof ConnectionClosedException) {
                             return;
                         }
-                        sessionLog.error(id + ": "  + ex.getMessage(), ex);
+                        sessionLog.error(id + " "  + ex.getMessage(), ex);
                     }
 
                 },

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalServerHttp1EventHandlerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalServerHttp1EventHandlerFactory.java?rev=1784892&r1=1784891&r2=1784892&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalServerHttp1EventHandlerFactory.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http/InternalServerHttp1EventHandlerFactory.java
Wed Mar  1 10:02:14 2017
@@ -28,7 +28,6 @@
 package org.apache.hc.core5.testing.nio.http;
 
 import java.util.Iterator;
-import java.util.concurrent.atomic.AtomicLong;
 
 import javax.net.ssl.SSLContext;
 
@@ -76,8 +75,6 @@ import org.apache.logging.log4j.Logger;
 @Contract(threading = ThreadingBehavior.IMMUTABLE)
 class InternalServerHttp1EventHandlerFactory implements IOEventHandlerFactory {
 
-    private static final AtomicLong COUNT = new AtomicLong();
-
     private final HttpProcessor httpProcessor;
     private final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory;
     private final H1Config h1Config;
@@ -125,7 +122,7 @@ class InternalServerHttp1EventHandlerFac
 
     @Override
     public IOEventHandler createHandler(final IOSession ioSession, final Object attachment)
{
-        final String id = "http1-incoming-" + COUNT.incrementAndGet();
+        final String id = ioSession.getId();
         if (sslContext != null && ioSession instanceof TransportSecurityLayer) {
             ((TransportSecurityLayer) ioSession).start(sslContext, null ,null, null);
         }
@@ -134,7 +131,7 @@ class InternalServerHttp1EventHandlerFac
         final Logger headerLog = LogManager.getLogger("org.apache.hc.core5.http.headers");
 
         final ServerHttp1StreamDuplexer streamDuplexer = createServerHttp1StreamDuplexer(
-                new LoggingIOSession(ioSession, id, sessionLog, wireLog),
+                new LoggingIOSession(ioSession, sessionLog, wireLog),
                 httpProcessor,
                 exchangeHandlerFactory,
                 h1Config,
@@ -149,14 +146,14 @@ class InternalServerHttp1EventHandlerFac
                     @Override
                     public void onConnect(final HttpConnection connection) {
                         if (sessionLog.isDebugEnabled()) {
-                            sessionLog.debug(id + ": "  + connection + " connected");
+                            sessionLog.debug(id + " "  + connection + " connected");
                         }
                     }
 
                     @Override
                     public void onDisconnect(final HttpConnection connection) {
                         if (sessionLog.isDebugEnabled()) {
-                            sessionLog.debug(id + ": "  + connection + " disconnected");
+                            sessionLog.debug(id + " "  + connection + " disconnected");
                         }
                     }
 
@@ -165,7 +162,7 @@ class InternalServerHttp1EventHandlerFac
                         if (ex instanceof ConnectionClosedException) {
                             return;
                         }
-                        sessionLog.error(id + ": "  + ex.getMessage(), ex);
+                        sessionLog.error(id + " "  + ex.getMessage(), ex);
                     }
 
                 },

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalClientHttp2EventHandlerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalClientHttp2EventHandlerFactory.java?rev=1784892&r1=1784891&r2=1784892&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalClientHttp2EventHandlerFactory.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalClientHttp2EventHandlerFactory.java
Wed Mar  1 10:02:14 2017
@@ -27,8 +27,6 @@
 
 package org.apache.hc.core5.testing.nio.http2;
 
-import java.util.concurrent.atomic.AtomicLong;
-
 import javax.net.ssl.SSLContext;
 
 import org.apache.hc.core5.http.ConnectionClosedException;
@@ -53,8 +51,6 @@ import org.apache.logging.log4j.Logger;
 
 class InternalClientHttp2EventHandlerFactory implements IOEventHandlerFactory {
 
-    private static final AtomicLong COUNT = new AtomicLong();
-
     private final HttpProcessor httpProcessor;
     private final HandlerFactory<AsyncPushConsumer> exchangeHandlerFactory;
     private final CharCodingConfig charCodingConfig;
@@ -76,7 +72,7 @@ class InternalClientHttp2EventHandlerFac
 
     @Override
     public IOEventHandler createHandler(final IOSession ioSession, final Object attachment)
{
-        final String id = "http2-outgoing-" + COUNT.incrementAndGet();
+        final String id = ioSession.getId();
         if (sslContext != null && ioSession instanceof TransportSecurityLayer) {
             ((TransportSecurityLayer) ioSession).start(sslContext, null ,null, null);
         }
@@ -88,14 +84,14 @@ class InternalClientHttp2EventHandlerFac
                     @Override
                     public void onConnect(final HttpConnection connection) {
                         if (sessionLog.isDebugEnabled()) {
-                            sessionLog.debug(id + ": "  + connection + " connected");
+                            sessionLog.debug(id + " "  + connection + " connected");
                         }
                     }
 
                     @Override
                     public void onDisconnect(final HttpConnection connection) {
                         if (sessionLog.isDebugEnabled()) {
-                            sessionLog.debug(id + ": "  + connection + " disconnected");
+                            sessionLog.debug(id + " "  + connection + " disconnected");
                         }
                     }
 
@@ -104,14 +100,14 @@ class InternalClientHttp2EventHandlerFac
                         if (ex instanceof ConnectionClosedException) {
                             return;
                         }
-                        sessionLog.error(id + ": "  + ex.getMessage(), ex);
+                        sessionLog.error(id + " "  + ex.getMessage(), ex);
                     }
 
                 }, new InternalHttp2StreamListener(id)) {
 
             @Override
             protected ClientHttp2StreamMultiplexer createStreamMultiplexer(final IOSession
ioSession) {
-                return super.createStreamMultiplexer(new LoggingIOSession(ioSession, id,
sessionLog));
+                return super.createStreamMultiplexer(new LoggingIOSession(ioSession, sessionLog));
             }
         }, id, sessionLog);
 

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalServerHttp2EventHandlerFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalServerHttp2EventHandlerFactory.java?rev=1784892&r1=1784891&r2=1784892&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalServerHttp2EventHandlerFactory.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/http2/InternalServerHttp2EventHandlerFactory.java
Wed Mar  1 10:02:14 2017
@@ -27,8 +27,6 @@
 
 package org.apache.hc.core5.testing.nio.http2;
 
-import java.util.concurrent.atomic.AtomicLong;
-
 import javax.net.ssl.SSLContext;
 
 import org.apache.hc.core5.http.ConnectionClosedException;
@@ -53,8 +51,6 @@ import org.apache.logging.log4j.Logger;
 
 class InternalServerHttp2EventHandlerFactory implements IOEventHandlerFactory {
 
-    private static final AtomicLong COUNT = new AtomicLong();
-
     private final HttpProcessor httpProcessor;
     private final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory;
     private final CharCodingConfig charCodingConfig;
@@ -76,7 +72,7 @@ class InternalServerHttp2EventHandlerFac
 
     @Override
     public IOEventHandler createHandler(final IOSession ioSession, final Object attachment)
{
-        final String id = "http2-incoming-" + COUNT.incrementAndGet();
+        final String id = ioSession.getId();
         if (sslContext != null && ioSession instanceof TransportSecurityLayer) {
             ((TransportSecurityLayer) ioSession).start(sslContext, null ,null, null);
         }
@@ -88,14 +84,14 @@ class InternalServerHttp2EventHandlerFac
                     @Override
                     public void onConnect(final HttpConnection connection) {
                         if (sessionLog.isDebugEnabled()) {
-                            sessionLog.debug(id + ": "  + connection + " connected");
+                            sessionLog.debug(id + " "  + connection + " connected");
                         }
                     }
 
                     @Override
                     public void onDisconnect(final HttpConnection connection) {
                         if (sessionLog.isDebugEnabled()) {
-                            sessionLog.debug(id + ": "  + connection + " disconnected");
+                            sessionLog.debug(id + " "  + connection + " disconnected");
                         }
                     }
 
@@ -104,14 +100,14 @@ class InternalServerHttp2EventHandlerFac
                         if (ex instanceof ConnectionClosedException) {
                             return;
                         }
-                        sessionLog.error(id + ": "  + ex.getMessage(), ex);
+                        sessionLog.error(id + " "  + ex.getMessage(), ex);
                     }
 
                 }, new InternalHttp2StreamListener(id)) {
 
             @Override
             protected ServerHttp2StreamMultiplexer createStreamMultiplexer(final IOSession
ioSession) {
-                return super.createStreamMultiplexer(new LoggingIOSession(ioSession, id,
sessionLog));
+                return super.createStreamMultiplexer(new LoggingIOSession(ioSession, sessionLog));
             }
         }, id, sessionLog);
 

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java?rev=1784892&r1=1784891&r2=1784892&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSession.java
Wed Mar  1 10:02:14 2017
@@ -31,6 +31,8 @@ import java.io.Closeable;
 import java.net.SocketAddress;
 import java.nio.channels.ByteChannel;
 
+import org.apache.hc.core5.util.Identifiable;
+
 /**
  * IOSession interface represents a sequence of logically related data exchanges
  * between two end points.
@@ -47,7 +49,7 @@ import java.nio.channels.ByteChannel;
  *
  * @since 4.0
  */
-public interface IOSession extends Closeable {
+public interface IOSession extends Closeable, Identifiable {
 
     int ACTIVE       = 0;
     int CLOSING      = 1;

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java?rev=1784892&r1=1784891&r2=1784892&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java
Wed Mar  1 10:02:14 2017
@@ -28,7 +28,6 @@
 package org.apache.hc.core5.reactor;
 
 import java.io.IOException;
-import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 import java.nio.channels.ByteChannel;
 import java.nio.channels.SelectionKey;
@@ -36,6 +35,7 @@ import java.nio.channels.SocketChannel;
 import java.util.Deque;
 import java.util.concurrent.ConcurrentLinkedDeque;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
@@ -49,8 +49,11 @@ import org.apache.hc.core5.util.Args;
 @Contract(threading = ThreadingBehavior.SAFE)
 class IOSessionImpl implements IOSession {
 
+    private final static AtomicLong COUNT = new AtomicLong(0);
+
     private final SelectionKey key;
     private final SocketChannel channel;
+    private final String id;
     private final AtomicInteger status;
     private final AtomicInteger eventMask;
     private final Deque<Command> commandQueue;
@@ -73,10 +76,16 @@ class IOSessionImpl implements IOSession
         this.commandQueue = new ConcurrentLinkedDeque<>();
         this.socketTimeout = 0;
         this.eventMask = new AtomicInteger(key.interestOps());
+        this.id = "i/o-" + Long.toHexString(COUNT.incrementAndGet());
         this.status = new AtomicInteger(ACTIVE);
     }
 
     @Override
+    public String getId() {
+        return id;
+    }
+
+    @Override
     public IOEventHandler getHandler() {
         return this.eventHandler;
     }
@@ -227,29 +236,10 @@ class IOSessionImpl implements IOSession
         }
     }
 
-    private static void formatAddress(final StringBuilder buffer, final SocketAddress socketAddress)
{
-        if (socketAddress instanceof InetSocketAddress) {
-            final InetSocketAddress addr = (InetSocketAddress) socketAddress;
-            buffer.append(addr.getAddress() != null ? addr.getAddress().getHostAddress()
:
-                addr.getAddress())
-            .append(':')
-            .append(addr.getPort());
-        } else {
-            buffer.append(socketAddress);
-        }
-    }
-
     @Override
     public String toString() {
         final StringBuilder buffer = new StringBuilder();
-        final SocketAddress remoteAddress = getRemoteAddress();
-        final SocketAddress localAddress = getLocalAddress();
-        if (remoteAddress != null && localAddress != null) {
-            formatAddress(buffer, localAddress);
-            buffer.append("<->");
-            formatAddress(buffer, remoteAddress);
-        }
-        buffer.append("[");
+        buffer.append(id).append("[");
         switch (this.status.get()) {
         case ACTIVE:
             buffer.append("ACTIVE");

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ManagedIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ManagedIOSession.java?rev=1784892&r1=1784891&r2=1784892&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ManagedIOSession.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ManagedIOSession.java
Wed Mar  1 10:02:14 2017
@@ -74,6 +74,11 @@ class ManagedIOSession implements IOSess
         updateAccessTime();
     }
 
+    @Override
+    public String getId() {
+        return ioSession.getId();
+    }
+
     void updateAccessTime() {
         this.lastAccessTime = System.currentTimeMillis();
     }

Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java?rev=1784892&r1=1784891&r2=1784892&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
Wed Mar  1 10:02:14 2017
@@ -175,6 +175,11 @@ public class SSLIOSession implements IOS
         };
     }
 
+    @Override
+    public String getId() {
+        return session.getId();
+    }
+
     /**
      * Returns {@code true} is the session has been fully initialized,
      * {@code false} otherwise.

Added: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/Identifiable.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/Identifiable.java?rev=1784892&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/Identifiable.java
(added)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/Identifiable.java
Wed Mar  1 10:02:14 2017
@@ -0,0 +1,39 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.util;
+
+/**
+ * Object with a unique identifier.
+ *
+ * @since 5.0
+ */
+public interface Identifiable {
+
+    String getId();
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/Identifiable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/Identifiable.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/util/Identifiable.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message