hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r638532 - /httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/
Date Tue, 18 Mar 2008 19:42:44 GMT
Author: olegk
Date: Tue Mar 18 12:42:42 2008
New Revision: 638532

URL: http://svn.apache.org/viewvc?rev=638532&view=rev
Log:
Improvements to the logging decorators

Added:
    httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java
  (with props)
    httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java
  (with props)
Modified:
    httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java
    httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientIOTarget.java
    httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerIOTarget.java

Added: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java?rev=638532&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java
(added)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java
Tue Mar 18 12:42:42 2008
@@ -0,0 +1,54 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * 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.http.contrib.logging;
+
+import org.apache.http.impl.nio.DefaultClientIOEventDispatch;
+import org.apache.http.nio.NHttpClientHandler;
+import org.apache.http.nio.NHttpClientIOTarget;
+import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.params.HttpParams;
+
+public class LoggingClientIOEventDispatch extends DefaultClientIOEventDispatch {
+
+    public LoggingClientIOEventDispatch(
+            final NHttpClientHandler handler, 
+            final HttpParams params) {
+        super(new LoggingNHttpClientHandler(handler), params);
+    }
+
+    @Override
+    protected NHttpClientIOTarget createConnection(final IOSession session) {
+        return new LoggingNHttpClientIOTarget(
+                super.createConnection(new LoggingIOSession(session, "client")));
+    }
+    
+}

Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java?rev=638532&r1=638531&r2=638532&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java
(original)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java
Tue Mar 18 12:42:42 2008
@@ -36,6 +36,7 @@
 import java.nio.ByteBuffer;
 import java.nio.channels.ByteChannel;
 import java.nio.channels.SelectionKey;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -50,21 +51,21 @@
  */
 public class LoggingIOSession implements IOSession {
 
-    private static int COUNT = 0;
+    private static AtomicLong COUNT = new AtomicLong(0);
     
     private final Log log;
     private final IOSession session;
     private final ByteChannel channel;
-    private final int id;
+    private final String id;
     
-    public LoggingIOSession(final IOSession session) {
+    public LoggingIOSession(final IOSession session, final String id) {
         super();
         if (session == null) {
             throw new IllegalArgumentException("I/O session may not be null");
         }
         this.session = session;
         this.channel = new LoggingByteChannel();
-        this.id = ++COUNT;
+        this.id = id + "-" + COUNT.incrementAndGet();
         this.log = LogFactory.getLog(session.getClass());
     }
 

Modified: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientIOTarget.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientIOTarget.java?rev=638532&r1=638531&r2=638532&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientIOTarget.java
(original)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientIOTarget.java
Tue Mar 18 12:42:42 2008
@@ -32,19 +32,22 @@
 package org.apache.http.contrib.logging;
 
 import java.io.IOException;
+import java.net.InetAddress;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.Header;
 import org.apache.http.HttpConnectionMetrics;
 import org.apache.http.HttpException;
+import org.apache.http.HttpInetConnection;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.nio.NHttpClientHandler;
 import org.apache.http.nio.NHttpClientIOTarget;
 import org.apache.http.protocol.HttpContext;
 
-public class LoggingNHttpClientIOTarget implements NHttpClientIOTarget  {
+public class LoggingNHttpClientIOTarget 
+    implements NHttpClientIOTarget, HttpInetConnection {
 
     private final NHttpClientIOTarget target;
     private final Log log;
@@ -155,4 +158,41 @@
         this.target.produceOutput(handler);
     }
     
+    public InetAddress getLocalAddress() {
+      if (this.target instanceof HttpInetConnection) {
+          return ((HttpInetConnection) this.target).getLocalAddress();
+      } else {
+          return null;
+      }
+  }
+
+  public int getLocalPort() {
+      if (this.target instanceof HttpInetConnection) {
+          return ((HttpInetConnection) this.target).getLocalPort();
+      } else {
+          return -1;
+      }
+  }
+
+  public InetAddress getRemoteAddress() {
+      if (this.target instanceof HttpInetConnection) {
+          return ((HttpInetConnection) this.target).getRemoteAddress();
+      } else {
+          return null;
+      }
+  }
+
+  public int getRemotePort() {
+      if (this.target instanceof HttpInetConnection) {
+          return ((HttpInetConnection) this.target).getRemotePort();
+      } else {
+          return -1;
+      }
+  }
+  
+  @Override
+  public String toString() {
+      return this.target.toString();
+  }
+  
 }

Modified: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerIOTarget.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerIOTarget.java?rev=638532&r1=638531&r2=638532&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerIOTarget.java
(original)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerIOTarget.java
Tue Mar 18 12:42:42 2008
@@ -32,19 +32,22 @@
 package org.apache.http.contrib.logging;
 
 import java.io.IOException;
+import java.net.InetAddress;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.Header;
 import org.apache.http.HttpConnectionMetrics;
 import org.apache.http.HttpException;
+import org.apache.http.HttpInetConnection;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.nio.NHttpServerIOTarget;
 import org.apache.http.nio.NHttpServiceHandler;
 import org.apache.http.protocol.HttpContext;
 
-public class LoggingNHttpServerIOTarget implements NHttpServerIOTarget {
+public class LoggingNHttpServerIOTarget 
+    implements NHttpServerIOTarget, HttpInetConnection {
 
     private final NHttpServerIOTarget target;
     private final Log log;
@@ -154,4 +157,41 @@
         this.target.produceOutput(handler);
     }
     
+    public InetAddress getLocalAddress() {
+      if (this.target instanceof HttpInetConnection) {
+          return ((HttpInetConnection) this.target).getLocalAddress();
+      } else {
+          return null;
+      }
+  }
+
+  public int getLocalPort() {
+      if (this.target instanceof HttpInetConnection) {
+          return ((HttpInetConnection) this.target).getLocalPort();
+      } else {
+          return -1;
+      }
+  }
+
+  public InetAddress getRemoteAddress() {
+      if (this.target instanceof HttpInetConnection) {
+          return ((HttpInetConnection) this.target).getRemoteAddress();
+      } else {
+          return null;
+      }
+  }
+
+  public int getRemotePort() {
+      if (this.target instanceof HttpInetConnection) {
+          return ((HttpInetConnection) this.target).getRemotePort();
+      } else {
+          return -1;
+      }
+  }
+  
+  @Override
+  public String toString() {
+      return this.target.toString();
+  }
+  
 }

Added: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java?rev=638532&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java
(added)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java
Tue Mar 18 12:42:42 2008
@@ -0,0 +1,54 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * 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.http.contrib.logging;
+
+import org.apache.http.impl.nio.DefaultServerIOEventDispatch;
+import org.apache.http.nio.NHttpServerIOTarget;
+import org.apache.http.nio.NHttpServiceHandler;
+import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.params.HttpParams;
+
+public class LoggingServerIOEventDispatch extends DefaultServerIOEventDispatch {
+
+    public LoggingServerIOEventDispatch(
+            final NHttpServiceHandler handler, 
+            final HttpParams params) {
+        super(new LoggingNHttpServiceHandler(handler), params);
+    }
+
+    @Override
+    protected NHttpServerIOTarget createConnection(final IOSession session) {
+        return new LoggingNHttpServerIOTarget(
+                super.createConnection(new LoggingIOSession(session, "server")));
+    }
+    
+}

Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message