hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1144809 - in /httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio: DefaultNHttpClientConnection.java DefaultNHttpServerConnection.java NHttpConnectionBase.java reactor/IOSessionImpl.java
Date Sun, 10 Jul 2011 10:35:47 GMT
Author: olegk
Date: Sun Jul 10 10:35:46 2011
New Revision: 1144809

URL: http://svn.apache.org/viewvc?rev=1144809&view=rev
Log:
Minor code refactoring

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java?rev=1144809&r1=1144808&r2=1144809&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
Sun Jul 10 10:35:46 2011
@@ -28,8 +28,6 @@
 package org.apache.http.impl.nio;
 
 import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
@@ -258,38 +256,4 @@ public class DefaultNHttpClientConnectio
         return this.request != null;
     }
 
-    @Override
-    public String toString() {
-        StringBuilder buf = new StringBuilder();
-
-        final SocketAddress remoteAddress = this.session.getRemoteAddress();
-        final SocketAddress localAddress = this.session.getLocalAddress();
-
-        if (remoteAddress == null || localAddress == null) {
-            return "[CLOSED]";
-        }
-
-        if (remoteAddress instanceof InetSocketAddress &&
-            localAddress instanceof InetSocketAddress) {
-
-            final InetSocketAddress remote = ((InetSocketAddress) remoteAddress);
-            final InetSocketAddress local  = ((InetSocketAddress) localAddress);
-
-            buf.append(local.getAddress() != null ? local.getAddress().getHostAddress() :
local.getAddress())
-            .append(':')
-            .append(local.getPort())
-            .append("->")
-            .append(remote.getAddress() != null ? remote.getAddress().getHostAddress() :
remote.getAddress())
-            .append(':')
-            .append(remote.getPort());
-
-        } else {
-            buf.append(localAddress)
-            .append("->")
-            .append(remoteAddress);
-        }
-
-        return buf.toString();
-    }
-
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java?rev=1144809&r1=1144808&r2=1144809&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
Sun Jul 10 10:35:46 2011
@@ -28,8 +28,6 @@
 package org.apache.http.impl.nio;
 
 import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
@@ -260,38 +258,4 @@ public class DefaultNHttpServerConnectio
         return this.response != null;
     }
 
-    @Override
-    public String toString() {
-        StringBuilder buf = new StringBuilder();
-
-        final SocketAddress remoteAddress = this.session.getRemoteAddress();
-        final SocketAddress localAddress  = this.session.getLocalAddress();
-
-        if (remoteAddress == null || localAddress == null) {
-            return "[CLOSED]";
-        }
-
-        if (remoteAddress instanceof InetSocketAddress &&
-            localAddress instanceof InetSocketAddress) {
-
-            final InetSocketAddress remote = ((InetSocketAddress) remoteAddress);
-            final InetSocketAddress local  = ((InetSocketAddress) localAddress);
-
-            buf.append(remote.getAddress() != null ? remote.getAddress().getHostAddress()
: remote.getAddress())
-            .append(':')
-            .append(remote.getPort())
-            .append("->")
-            .append(local.getAddress() != null ? local.getAddress().getHostAddress() : local.getAddress())
-            .append(':')
-            .append(local.getPort());
-
-        } else {
-            buf.append(remoteAddress)
-            .append("->")
-            .append(localAddress);
-        }
-
-        return buf.toString();
-    }
-
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java?rev=1144809&r1=1144808&r2=1144809&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
Sun Jul 10 10:35:46 2011
@@ -423,13 +423,42 @@ public class NHttpConnectionBase
         return this.connMetrics;
     }
 
+    private static void formatAddress(final StringBuilder buffer, final SocketAddress socketAddress)
{
+        if (socketAddress instanceof InetSocketAddress) {
+            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() {
-        StringBuilder buf = new StringBuilder();
-        buf.append(this.session.getLocalAddress())
-            .append("<->")
-            .append(this.session.getRemoteAddress());
-        return buf.toString();
+        StringBuilder buffer = new StringBuilder();
+        SocketAddress remoteAddress = this.session.getRemoteAddress();
+        SocketAddress localAddress = this.session.getLocalAddress();
+        if (remoteAddress != null && localAddress != null) {
+            formatAddress(buffer, localAddress);
+            buffer.append("<->");
+            formatAddress(buffer, remoteAddress);
+        }
+        buffer.append("[");
+        switch (this.status) {
+        case ACTIVE:
+            buffer.append("ACTIVE");
+            break;
+        case CLOSING:
+            buffer.append("CLOSING");
+            break;
+        case CLOSED:
+            buffer.append("CLOSED");
+            break;
+        }
+        buffer.append("]");
+        return buffer.toString();
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java?rev=1144809&r1=1144808&r2=1144809&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
Sun Jul 10 10:35:46 2011
@@ -308,35 +308,28 @@ public class IOSessionImpl implements IO
         }
     }
 
+    private static void formatAddress(final StringBuilder buffer, final SocketAddress socketAddress)
{
+        if (socketAddress instanceof InetSocketAddress) {
+            InetSocketAddress addr = ((InetSocketAddress) socketAddress);
+            buffer.append(addr.getAddress() != null ? addr.getAddress().getHostAddress()
:
+                addr.getAddress())
+            .append(':')
+            .append(addr.getPort());
+        } else {
+            buffer.append(socketAddress);
+        }
+    }
+
     @Override
     public synchronized String toString() {
         StringBuilder buffer = new StringBuilder();
-
-        final SocketAddress remoteAddress = getRemoteAddress();
-        final SocketAddress localAddress = getLocalAddress();
-
+        SocketAddress remoteAddress = getRemoteAddress();
+        SocketAddress localAddress = getLocalAddress();
         if (remoteAddress != null && localAddress != null) {
-            if (remoteAddress instanceof InetSocketAddress &&
-                localAddress instanceof InetSocketAddress) {
-
-                final InetSocketAddress remote = ((InetSocketAddress) remoteAddress);
-                final InetSocketAddress local  = ((InetSocketAddress) localAddress);
-
-                buffer.append(local.getAddress() != null ? local.getAddress().getHostAddress()
: local.getAddress())
-                .append(':')
-                .append(local.getPort())
-                .append("<->")
-                .append(remote.getAddress() != null ? remote.getAddress().getHostAddress()
: remote.getAddress())
-                .append(':')
-                .append(remote.getPort());
-
-            } else {
-                buffer.append(localAddress)
-                .append("<->")
-                .append(remoteAddress);
-            }
+            formatAddress(buffer, localAddress);
+            buffer.append("<->");
+            formatAddress(buffer, remoteAddress);
         }
-
         buffer.append("[");
         switch (this.status) {
         case ACTIVE:



Mime
View raw message