You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2003/01/16 23:29:52 UTC

cvs commit: jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11 Http11Processor.java Http11Protocol.java

costin      2003/01/16 14:29:52

  Modified:    http11   build.xml
               http11/src/java/org/apache/coyote/http11
                        Http11Processor.java Http11Protocol.java
  Log:
  Same thing as in jk - threads and request processors are registered in
  JMX  (if coyote itself is registered and it registers the protocol adapter )
  
  Revision  Changes    Path
  1.10      +5 -1      jakarta-tomcat-connectors/http11/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/build.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- build.xml	13 Nov 2002 00:14:25 -0000	1.9
  +++ build.xml	16 Jan 2003 22:29:51 -0000	1.10
  @@ -31,6 +31,8 @@
     <property name="tomcat33-coyote.jar" 
             value="../coyote/build/lib/tomcat33-coyote.jar"/>
     <property name="junit.jar"        value="${junit.home}/junit.jar"/>
  +  <property name="jmx.jar" location="../lib/mx4j.jar" />
  +  <property name="commons-modeler.jar" location="../../jakarta-commons/modeler/dist/commons-modeler.jar" />
     <property name="commons-logging.jar" value="../lib/commons-logging.jar" />
   
   <!-- ========== Component Declarations ==================================== -->
  @@ -75,6 +77,8 @@
       <pathelement location="${tomcat-util.jar}"/>
       <pathelement location="${tomcat-coyote.jar}"/>
       <pathelement location="${commons-logging.jar}"/>
  +    <pathelement location="${commons-modeler.jar}"/>
  +    <pathelement location="${jmx.jar}"/>
     </path>
   
   
  
  
  
  1.56      +28 -8     jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java
  
  Index: Http11Processor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- Http11Processor.java	4 Jan 2003 10:34:19 -0000	1.55
  +++ Http11Processor.java	16 Jan 2003 22:29:51 -0000	1.56
  @@ -59,7 +59,6 @@
   
   package org.apache.coyote.http11;
   
  -import java.io.EOFException;
   import java.io.InterruptedIOException;
   import java.io.InputStream;
   import java.io.IOException;
  @@ -74,12 +73,12 @@
   import org.apache.tomcat.util.buf.Ascii;
   import org.apache.tomcat.util.buf.HexUtils;
   import org.apache.tomcat.util.net.SSLSupport;
  +import org.apache.tomcat.util.threads.ThreadPool;
  +import org.apache.tomcat.util.threads.ThreadWithAttributes;
   
   import org.apache.coyote.ActionHook;
   import org.apache.coyote.ActionCode;
   import org.apache.coyote.Adapter;
  -import org.apache.coyote.InputBuffer;
  -import org.apache.coyote.OutputBuffer;
   import org.apache.coyote.Processor;
   import org.apache.coyote.Request;
   import org.apache.coyote.Response;
  @@ -279,6 +278,7 @@
        */
       protected char[] hostNameC = new char[0];
   
  +    protected ThreadPool threadPool;
   
       // ------------------------------------------------------------- Properties
   
  @@ -321,6 +321,9 @@
           }
       }
   
  +    public void setThreadPool(ThreadPool threadPool) {
  +        this.threadPool = threadPool;
  +    }
   
       /**
        * Add user-agent for which gzip compression didn't works
  @@ -532,17 +535,28 @@
           return timeout;
       }
   
  +    /** Get the request associated with this processor.
  +     *
  +     * @return
  +     */
  +    public Request getRequest() {
  +        return request;
  +    }
  +
       /**
        * Process pipelined HTTP requests using the specified input and output
        * streams.
        * 
  -     * @param inputStream stream from which the HTTP requests will be read
  -     * @param outputStream stream which will be used to output the HTTP 
  +     * @param input stream from which the HTTP requests will be read
  +     * @param output stream which will be used to output the HTTP
        * responses
        * @throws IOException error during an I/O operation
        */
       public void process(InputStream input, OutputStream output)
           throws IOException {
  +        ThreadWithAttributes thrA=
  +                (ThreadWithAttributes)Thread.currentThread();
  +        thrA.setCurrentStage(threadPool, "parsing http request");
   
           // Set the remote address
           remoteAddr = null;
  @@ -567,6 +581,7 @@
                       socket.setSoTimeout(soTimeout);
                   }
                   inputBuffer.parseRequestLine();
  +                thrA.setParam( threadPool, request.requestURI().toString());
                   keptAlive = true;
                   if (!disableUploadTimeout) {
                       socket.setSoTimeout(timeout);
  @@ -583,6 +598,7 @@
               }
   
               // Setting up filters, and parse some request headers
  +            thrA.setCurrentStage(threadPool, "prepareRequest");
               prepareRequest();
   
               if (maxKeepAliveRequests > 0 && --keepAliveLeft == 0)
  @@ -591,6 +607,7 @@
               // Process the request in the adapter
               if (!error) {
                   try {
  +                    thrA.setCurrentStage(threadPool, "service");
                       adapter.service(request, response);
                   } catch (InterruptedIOException e) {
                       error = true;
  @@ -604,6 +621,7 @@
   
               // Finish the handling of the request
               try {
  +                thrA.setCurrentStage(threadPool, "endRequestIB");
                   inputBuffer.endRequest();
               } catch (IOException e) {
                   error = true;
  @@ -614,6 +632,7 @@
                   error = true;
               }
               try {
  +                thrA.setCurrentStage(threadPool, "endRequestOB");
                   outputBuffer.endRequest();
               } catch (IOException e) {
                   error = true;
  @@ -622,6 +641,10 @@
                   error = true;
               }
   
  +            thrA.setCurrentStage(threadPool, "ended");
  +            // Don't reset the param - we'll see it as ended. Next request
  +            // will reset it
  +            // thrA.setParam(null);
               // Next request
               inputBuffer.nextRequest();
               outputBuffer.nextRequest();
  @@ -634,7 +657,6 @@
   
           // Recycle ssl info
           sslSupport = null;
  -
       }
   
   
  @@ -650,7 +672,6 @@
       public void action(ActionCode actionCode, Object param) {
   
           if (actionCode == ActionCode.ACTION_COMMIT) {
  -
               // Commit current response
   
               if (response.isCommitted())
  @@ -688,7 +709,6 @@
               }
   
           } else if (actionCode == ActionCode.ACTION_CLOSE) {
  -
               // Close
   
               // End the processing of the current request, and stop any further
  
  
  
  1.19      +67 -11    jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Protocol.java
  
  Index: Http11Protocol.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Protocol.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Http11Protocol.java	18 Dec 2002 20:36:58 -0000	1.18
  +++ Http11Protocol.java	16 Jan 2003 22:29:51 -0000	1.19
  @@ -66,13 +66,13 @@
   import java.io.*;
   import java.net.*;
   import java.util.*;
  -import java.text.*;
   import org.apache.tomcat.util.res.StringManager;
  -import org.apache.tomcat.util.IntrospectionUtils;
  -import org.apache.tomcat.util.buf.*;
  -import org.apache.tomcat.util.http.*;
  -import org.apache.tomcat.util.log.*;
  +import org.apache.tomcat.util.threads.ThreadPool;
   import org.apache.tomcat.util.net.*;
  +import org.apache.commons.modeler.Registry;
  +import javax.management.ObjectName;
  +import javax.management.MBeanServer;
  +import javax.management.MBeanRegistration;
   
   
   /**
  @@ -83,9 +83,12 @@
    * @author Remy Maucherat
    * @author Costin Manolache
    */
  -public class Http11Protocol implements ProtocolHandler
  +public class Http11Protocol implements ProtocolHandler, MBeanRegistration
   {
   
  +    public Http11Protocol() {
  +    }
  +
       /**
        * The string manager for this package.
        */
  @@ -98,8 +101,8 @@
       /** Pass config info
        */
       public void setAttribute( String name, Object value ) {
  -
  -        log.debug(sm.getString("http11protocol.setattribute", name, value));
  +        if( log.isTraceEnabled())
  +            log.trace(sm.getString("http11protocol.setattribute", name, value));
           attributes.put(name, value);
   /*
           if ("maxKeepAliveRequests".equals(name)) {
  @@ -132,7 +135,7 @@
   	try {
               checkSocketFactory();
           } catch( Exception ex ) {
  -            log.error(sm.getString("http11protocol.socketfactory.initerror"), 
  +            log.error(sm.getString("http11protocol.socketfactory.initerror"),
                         ex);
               throw ex;
           }
  @@ -146,6 +149,7 @@
               }
           }
   
  +        // XXX get domain from registration
           try {
               ep.initEndpoint();
           } catch (Exception ex) {
  @@ -157,6 +161,15 @@
       }
   
       public void start() throws Exception {
  +        if( this.domain != null ) {
  +            try {
  +                Registry.getRegistry().registerComponent(tp, domain,"ThreadPool",
  +                        "type=ThreadPool,worker=http11,name=http%" + ep.getPort());
  +            } catch (Exception e) {
  +                log.error("Can't register threadpool" );
  +            }
  +        }
  +
           try {
               ep.startEndpoint();
           } catch (Exception ex) {
  @@ -171,7 +184,8 @@
       }
       
       // -------------------- Properties--------------------
  -    protected PoolTcpEndpoint ep=new PoolTcpEndpoint();
  +    protected ThreadPool tp=ThreadPool.createThreadPool(true);
  +    protected PoolTcpEndpoint ep=new PoolTcpEndpoint(tp);
       protected boolean secure;
       
       protected ServerSocketFactory socketFactory;
  @@ -334,7 +348,8 @@
   
       static class Http11ConnectionHandler implements TcpConnectionHandler {
           Http11Protocol proto;
  -        
  +        static int count=0;
  +
           Http11ConnectionHandler( Http11Protocol proto ) {
               this.proto=proto;
           }
  @@ -354,6 +369,7 @@
   
               Http11Processor  processor = new Http11Processor();
               processor.setAdapter( proto.adapter );
  +            processor.setThreadPool( proto.tp );
               processor.setMaxKeepAliveRequests( proto.maxKeepAliveRequests );
               processor.setTimeout( proto.timeout );
               processor.setDisableUploadTimeout( proto.disableUploadTimeout );
  @@ -362,6 +378,18 @@
               //thData[0]=adapter;
               thData[1]=processor;
               thData[2]=null;
  +
  +            if( proto.getDomain() != null ) {
  +                try {
  +                    RequestProcessor rp=new RequestProcessor(processor.getRequest());
  +                    Registry.getRegistry().registerComponent( rp,
  +                            proto.getDomain(), "RequestProcessor",
  +                            "type=RequestProcessor,name=HttpRequest" + count++ );
  +                } catch( Exception ex ) {
  +                    log.warn("Error registering request");
  +                }
  +            }
  +
               return  thData;
           }
   
  @@ -510,4 +538,32 @@
       
       */
   
  +    protected String domain;
  +    protected ObjectName oname;
  +    protected MBeanServer mserver;
  +
  +    public ObjectName getObjectName() {
  +        return oname;
  +    }
  +
  +    public String getDomain() {
  +        return domain;
  +    }
  +
  +    public ObjectName preRegister(MBeanServer server,
  +                                  ObjectName name) throws Exception {
  +        oname=name;
  +        mserver=server;
  +        domain=name.getDomain();
  +        return name;
  +    }
  +
  +    public void postRegister(Boolean registrationDone) {
  +    }
  +
  +    public void preDeregister() throws Exception {
  +    }
  +
  +    public void postDeregister() {
  +    }
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>