hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r232618 - in /jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote: ./ impl/
Date Sun, 14 Aug 2005 15:46:46 GMT
Author: olegk
Date: Sun Aug 14 08:46:38 2005
New Revision: 232618

URL: http://svn.apache.org/viewcvs?rev=232618&view=rev
Log:
Better thread names and debug logging

Added:
    jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/DefaultThreadFactory.java
  (with props)
Modified:
    jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/ConnectionListener.java
    jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpProtocolHandler.java
    jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/CoyoteHttpConnection.java
    jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/DefaultHttpConnectionManager.java
    jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java

Modified: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/ConnectionListener.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/ConnectionListener.java?rev=232618&r1=232617&r2=232618&view=diff
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/ConnectionListener.java
(original)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/ConnectionListener.java
Sun Aug 14 08:46:38 2005
@@ -89,15 +89,24 @@
         try {
             while (this.serverchannel.isOpen() && !Thread.interrupted()) {
                 try {
+                    LOG.debug("Waiting for incoming HTTP connection");
                     SocketChannel channel = this.serverchannel.accept();
                     Socket socket = channel.socket();
                     if (LOG.isDebugEnabled()) {
-                        LOG.debug("Incoming connection from " + socket.getRemoteSocketAddress());
+                        LOG.debug("Incoming HTTP connection from " + 
+                        		socket.getRemoteSocketAddress());
                     }
                     HttpServerConnection conn = this.connfactory.newConnection(
                             socket, this.params);
                     this.connmanager.process(conn);
+                } catch (IOException ex) {
+                	if (LOG.isInfoEnabled()) {
+                        LOG.info("Connection listener terminated due to an I/O error: " +

+                        		ex.getMessage());
+                	}
+                    break;
                 } catch (Throwable ex) {
+                    LOG.error("Connection listener terminated due to a runtime error", ex);
                     break;
                 }
             }

Modified: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpProtocolHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpProtocolHandler.java?rev=232618&r1=232617&r2=232618&view=diff
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpProtocolHandler.java
(original)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpProtocolHandler.java
Sun Aug 14 08:46:38 2005
@@ -41,6 +41,7 @@
 import org.apache.coyote.ProtocolHandler;
 import org.apache.http.coyote.impl.DefaultHttpConnectionFactory;
 import org.apache.http.coyote.impl.DefaultHttpConnectionManager;
+import org.apache.http.coyote.impl.DefaultThreadFactory;
 import org.apache.http.coyote.params.CoyoteParams;
 import org.apache.http.impl.DefaultHttpParams;
 import org.apache.http.params.HttpConnectionParams;
@@ -69,8 +70,10 @@
     
 	private ConnectionListener listener = null;
 	private ExecutorService listenerExecutor = null;
+	private ThreadGroup listenertg = null;
     private HttpConnectionManager connmanager = null;
 	private ExecutorService requestExecutor = null;
+	private ThreadGroup conntg = null;
 	
 	public HttpProtocolHandler() {
 		super();
@@ -115,18 +118,27 @@
 	}
 	
 	public void init() throws Exception {
+		this.conntg = new ThreadGroup("Connection thread group");
+		
         this.requestExecutor = new ThreadPoolExecutor(
                 this.minThreads, this.maxThreads,
-                0L, TimeUnit.MILLISECONDS,
-                new LinkedBlockingQueue<Runnable>());
+                180L, TimeUnit.SECONDS,
+                new LinkedBlockingQueue<Runnable>(),
+                new DefaultThreadFactory(this.conntg, "HttpConnection-" + getPort()));
+        
         this.connmanager = new DefaultHttpConnectionManager( 
                 this.requestExecutor,
                 this.params,
-                this.adapter); 
+                this.adapter);
+
+		this.listenertg = new ThreadGroup("Listener thread group");
+        
         this.listenerExecutor = new ThreadPoolExecutor(
                 1, 1,
                 0L, TimeUnit.MILLISECONDS,
-                new LinkedBlockingQueue<Runnable>());
+                new LinkedBlockingQueue<Runnable>(),
+                new DefaultThreadFactory(this.listenertg, "HttpListener"));
+        
         this.listener = new ConnectionListener(
                 new DefaultHttpConnectionFactory(), 
                 this.connmanager,

Modified: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/CoyoteHttpConnection.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/CoyoteHttpConnection.java?rev=232618&r1=232617&r2=232618&view=diff
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/CoyoteHttpConnection.java
(original)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/CoyoteHttpConnection.java
Sun Aug 14 08:46:38 2005
@@ -29,9 +29,13 @@
 
 package org.apache.http.coyote.impl;
 
+import java.io.IOException;
+import java.net.Socket;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.impl.DefaultHttpServerConnection;
+import org.apache.http.params.HttpParams;
 
 /**
  * <p>
@@ -45,11 +49,20 @@
     private static Log LOG = LogFactory.getLog(CoyoteHttpConnection.class);
     private static Log WIRE_LOG = LogFactory.getLog("coyote.wire");
     
+    private String name = null;
+    
     public CoyoteHttpConnection() {
         super();
+        this.name = "No Connection"; 
     }
 
     @Override
+	public void bind(final Socket socket, final HttpParams params) throws IOException {
+		super.bind(socket, params);
+        this.name = socket.getRemoteSocketAddress().toString(); 
+	}
+
+	@Override
     protected boolean isErrorEnabled() {
         return LOG.isErrorEnabled();
     }
@@ -88,5 +101,10 @@
     protected void wirelog(String s) {
         WIRE_LOG.debug(s);
     }
+
+	@Override
+	public String toString() {
+		return this.name;
+	}
     
 }

Modified: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/DefaultHttpConnectionManager.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/DefaultHttpConnectionManager.java?rev=232618&r1=232617&r2=232618&view=diff
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/DefaultHttpConnectionManager.java
(original)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/DefaultHttpConnectionManager.java
Sun Aug 14 08:46:38 2005
@@ -114,7 +114,7 @@
             public void completed(IOProcessor processor) {
                 removeProcessor(processor);
                 if (LOG.isDebugEnabled()) {
-                    LOG.debug(processor + " processor terminated");
+                    LOG.debug(processor + " terminated");
                 }
             }
             

Added: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/DefaultThreadFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/DefaultThreadFactory.java?rev=232618&view=auto
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/DefaultThreadFactory.java
(added)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/DefaultThreadFactory.java
Sun Aug 14 08:46:38 2005
@@ -0,0 +1,66 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.coyote.impl;
+
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ */
+public class DefaultThreadFactory implements ThreadFactory {
+
+    final ThreadGroup group;
+    final AtomicInteger count;
+    final String namePrefix;
+	
+    public DefaultThreadFactory(final ThreadGroup group, final String namePrefix) {
+        super();
+        this.count = new AtomicInteger(1);
+        this.group = group;
+        this.namePrefix = namePrefix;
+    }
+
+    public Thread newThread(final Runnable runnable) {
+    	StringBuffer buffer = new StringBuffer();
+    	buffer.append(this.namePrefix);
+    	buffer.append('-');
+    	buffer.append(this.count.getAndIncrement());
+        Thread t = new Thread(group, runnable, buffer.toString(), 0);
+        t.setDaemon(false);
+        t.setPriority(Thread.NORM_PRIORITY);
+        return t;
+    }
+        
+}

Propchange: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/DefaultThreadFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/DefaultThreadFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/DefaultThreadFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java?rev=232618&r1=232617&r2=232618&view=diff
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java
(original)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java
Sun Aug 14 08:46:38 2005
@@ -191,6 +191,7 @@
     }
 
     private void receiveHttpRequest() throws IOException, HttpException {
+        LOG.debug("Waiting for incoming HTTP request");
         this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_NEW);
     	this.httpreq = this.conn.receiveRequest(this.params);
         this.coyotereq.setStartTime(System.currentTimeMillis());
@@ -228,7 +229,7 @@
     	        HttpResponse ack = createResponse(HttpStatus.SC_CONTINUE);
     	        try {
     	            this.conn.sendResponse(ack);
-    	            LOG.debug("Ack continue sent");
+    	            LOG.debug("100-Continue sent");
     	        } catch (HttpException ex) {
     	            LOG.error("Malformed HTTP response", ex);
     	            this.conn.close();
@@ -266,6 +267,12 @@
     	this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_PARSE);
         // Convert the request line
         RequestLine reqline = this.httpreq.getRequestLine();
+        
+        if (LOG.isDebugEnabled()) {
+        	LOG.debug("Request method: " + reqline.getMethod());
+        	LOG.debug("Target URI: " + reqline.getUri());
+        }
+        
         HttpVersion ver = reqline.getHttpVersion();
         if (!ver.lessEquals(HttpVersion.HTTP_1_1)) {
             throw new UnsupportedHttpVersionException("Unsupported verion: " + ver); 
@@ -363,8 +370,19 @@
             return;
         }
         HttpVersion ver = this.httpreq.getRequestLine().getHttpVersion();
-        int statuscode = this.coyoteres.getStatus(); 
-        BasicHttpResponse tmp = new BasicHttpResponse(new StatusLine(ver, statuscode));
+        int statuscode = this.coyoteres.getStatus();
+        String statusPhrase = this.coyoteres.getMessage();
+        if (statusPhrase == null) {
+        	statusPhrase = HttpStatus.getStatusText(statuscode);
+        }
+
+        if (LOG.isDebugEnabled()) {
+        	LOG.debug("Response status: " + statuscode);
+        	LOG.debug("Response phrase: " + statusPhrase);
+        }
+        
+        StatusLine statusline = new StatusLine(ver, statuscode, statusPhrase);
+        BasicHttpResponse tmp = new BasicHttpResponse(statusline);
         this.httpres = tmp;
         MimeHeaders headers = this.coyoteres.getMimeHeaders();
         int size = headers.size();
@@ -428,7 +446,7 @@
 	           
 	public void action(final ActionCode actionCode, final Object param) {
         if (actionCode == ActionCode.ACTION_COMMIT) {
-            LOG.debug("Commit action");
+            LOG.debug("Action Commit");
             if (this.coyoteres.isCommitted()) {
                 return;
             }
@@ -440,7 +458,7 @@
                 this.coyoteres.setErrorException(ex);
             }
         } else if (actionCode == ActionCode.ACTION_ACK) {
-            LOG.debug("Ack action");
+            LOG.debug("Action Ack");
             if (this.coyoteres.isCommitted()) {
                 return;
             }
@@ -450,7 +468,7 @@
                 this.coyoteres.setErrorException(ex);
             }
         } else if (actionCode == ActionCode.ACTION_CLIENT_FLUSH) {
-            LOG.debug("Flush action");
+            LOG.debug("Action Flush");
             try {
                 if (!this.coyoteres.isCommitted()) {
                     prepareHttpResponse();
@@ -462,7 +480,7 @@
                 this.coyoteres.setErrorException(ex);
             }            
         } else if (actionCode == ActionCode.ACTION_CLOSE) {
-            LOG.debug("Flush action");
+            LOG.debug("Action Close");
             try {
                 if (!this.coyoteres.isCommitted()) {
                     prepareHttpResponse();
@@ -474,7 +492,7 @@
                 this.coyoteres.setErrorException(ex);
             }            
         } else if (actionCode == ActionCode.ACTION_RESET) {
-            LOG.debug("Reset action");
+            LOG.debug("Action Reset");
             reset();
         } else if (actionCode == ActionCode.ACTION_REQ_HOST_ADDR_ATTRIBUTE) {
             // Not implemetned
@@ -525,6 +543,15 @@
 		} else {
 			return 0;
 		}
+	}
+
+	@Override
+	public String toString() {
+		StringBuffer buffer = new StringBuffer();
+		buffer.append("HTTP connection (");
+		buffer.append(this.conn);
+		buffer.append(") processor");
+		return buffer.toString();
 	}
 	
 }



Mime
View raw message