seguin      02/02/20 08:12:42

  Modified:    jk/java/org/apache/ajp Ajp13.java RequestHandler.java
               jk/java/org/apache/ajp/tomcat4 Ajp13Connector.java
                        Ajp13Processor.java
  Added:       jk/java/org/apache/ajp Logger.java
  Log:
  logging improvements:
   *) have log messages from ajp classes (Ajp13, RequestHandler, etc.) go
      to connector's logger (so they get logged to a file with the rest of
      the connector's log message).
   *) put all threads created by tomcat4 connector into a thread group and
      do a ThreadGroup.list() every minute when debug level is > 0.  (this
      should probably be made configurable, and perhaps send this info to
      the log file instead of stdout.  baby steps.)
  
  these changes were, in part, brought on by bug 5735 in an attempt to debug
  the problem.
  
  Revision  Changes    Path
  1.24      +2 -10     jakarta-tomcat-connectors/jk/java/org/apache/ajp/Ajp13.java
  
  Index: Ajp13.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/ajp/Ajp13.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- Ajp13.java        6 Feb 2002 18:26:50 -0000       1.23
  +++ Ajp13.java        20 Feb 2002 16:12:42 -0000      1.24
  @@ -551,24 +551,16 @@
       
       public void setDebug(int debug) {
           this.debug = debug;
  +        this.reqHandler.setDebug(debug);
       }
   
       public void setLogger(Logger l) {
           this.logger = l;
  +        this.reqHandler.setLogger(l);
       }
   
       /**
        * XXX place holder...
        */
       Logger logger = new Logger();
  -    public static class Logger {
  -        void log(String msg) {
  -            System.out.println("[Ajp13] " + msg);
  -        }
  -        
  -        void log(String msg, Throwable t) {
  -            System.out.println("[Ajp13] " + msg);
  -            t.printStackTrace(System.out);
  -        }
  -    }
   }
  
  
  
  1.12      +12 -2     
jakarta-tomcat-connectors/jk/java/org/apache/ajp/RequestHandler.java
  
  Index: RequestHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/ajp/RequestHandler.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- RequestHandler.java       6 Feb 2002 18:26:50 -0000       1.11
  +++ RequestHandler.java       20 Feb 2002 16:12:42 -0000      1.12
  @@ -583,9 +583,19 @@
           return -1;
       }
      
  -    private static int debug=0;
  +    private int debug=0;
  +    private Logger logger = new Logger();
  +    
  +    public void setDebug(int debug) {
  +        this.debug = debug;
  +    }
  +
  +    public void setLogger(Logger l) {
  +        this.logger = l;
  +    }
  +    
       void log(String s) {
  -     System.out.println("RequestHandler: " + s );
  +        logger.log("[RequestHandler] " + s );
       }
   
       // ==================== Servlet Input Support =================
  
  
  
  1.1                  jakarta-tomcat-connectors/jk/java/org/apache/ajp/Logger.java
  
  Index: Logger.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * 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/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  package org.apache.ajp;
  
  /**
   * A simple logger class used by classes in this package.
   * The intention is for this class to be overridden so that
   * log messages from classes in this package can be adapted
   * to loggers used by the connector implementations for various
   * servlet containers.
   *
   * @author Kevin Seguin [[EMAIL PROTECTED]]
   */
  public class Logger {
      
      /**
       * Log the given message.
       * @param msg The message to log.
       */
      public void log(String msg) {
          System.out.println("[Ajp13] " + msg);
      }
      
      /**
       * Log the given message and error.
       * @param msg The message to log.
       * @param t The error to log.
       */
      public void log(String msg, Throwable t) {
          System.out.println("[Ajp13] " + msg);
          t.printStackTrace(System.out);
      }
  }
  
  
  
  1.14      +72 -7     
jakarta-tomcat-connectors/jk/java/org/apache/ajp/tomcat4/Ajp13Connector.java
  
  Index: Ajp13Connector.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/ajp/tomcat4/Ajp13Connector.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Ajp13Connector.java       15 Feb 2002 21:13:19 -0000      1.13
  +++ Ajp13Connector.java       20 Feb 2002 16:12:42 -0000      1.14
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/ajp/tomcat4/Ajp13Connector.java,v
 1.13 2002/02/15 21:13:19 remm Exp $
  - * $Revision: 1.13 $
  - * $Date: 2002/02/15 21:13:19 $
  + * $Header: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/ajp/tomcat4/Ajp13Connector.java,v
 1.14 2002/02/20 16:12:42 seguin Exp $
  + * $Revision: 1.14 $
  + * $Date: 2002/02/20 16:12:42 $
    *
    * ====================================================================
    *
  @@ -93,7 +93,7 @@
    * Implementation of an Ajp13 connector.
    *
    * @author Kevin Seguin
  - * @version $Revision: 1.13 $ $Date: 2002/02/15 21:13:19 $
  + * @version $Revision: 1.14 $ $Date: 2002/02/20 16:12:42 $
    */
   
   
  @@ -254,12 +254,24 @@
   
   
       /**
  +     * This connector's thread group.
  +     */
  +    private ThreadGroup threadGroup = null;
  +
  +
  +    /**
        * The name to register for the background thread.
        */
       private String threadName = null;
   
   
       /**
  +     * A thread that periodically logs debug info if debug > 0.
  +     */
  +    private DebugThread debugThread = null;
  +
  +
  +    /**
        * The thread synchronization object.
        */
       private Object threadSync = new Object();
  @@ -711,7 +723,13 @@
        */
       void recycle(Ajp13Processor processor) {
   
  -        processors.push(processor);
  +        synchronized(processors) {
  +            if (debug > 0) {
  +                logger.log("added processor to available processors, available="
  +                           + processors.size());
  +            }
  +            processors.push(processor);
  +        }
   
       }
   
  @@ -745,7 +763,7 @@
        */
       private Ajp13Processor newProcessor() {
   
  -        Ajp13Processor processor = new Ajp13Processor(this, curProcessors++);
  +        Ajp13Processor processor = new Ajp13Processor(this, curProcessors++, 
threadGroup);
        if (processor instanceof Lifecycle) {
            try {
                ((Lifecycle) processor).start();
  @@ -816,7 +834,16 @@
            // Accept the next incoming connection from the server socket
            Socket socket = null;
            try {
  +                if (debug > 0) {
  +                    logger.log("accepting socket...");
  +                }
  +                
                socket = serverSocket.accept();
  +
  +                if (debug > 0) {
  +                    logger.log("accepted socket, assigning to processor.");
  +                }
  +                
                   socket.setSoLinger(true, 100);
                   socket.setKeepAlive(true);
                   
  @@ -855,6 +882,13 @@
            }
   
            // Hand this socket off to an appropriate processor
  +            if (debug > 0) {
  +                synchronized(processors) {
  +                    logger.log("about to create a processor, available="
  +                               + processors.size() + ", created=" + created.size()
  +                               + ", maxProcessors=" + maxProcessors);
  +                }
  +            }
            Ajp13Processor processor = createProcessor();
            if (processor == null) {
                try {
  @@ -886,7 +920,7 @@
   
        logger.log(sm.getString("ajp13Connector.starting"));
   
  -     thread = new Thread(this, threadName);
  +     thread = new Thread(threadGroup, this, threadName);
        thread.setDaemon(true);
        thread.start();
   
  @@ -959,7 +993,14 @@
        if (started)
            throw new LifecycleException
                (sm.getString("ajp13Connector.alreadyStarted"));
  +
  +        debugThread = new DebugThread();
  +        debugThread.setDaemon(true);
  +        debugThread.start();
  +
           threadName = "Ajp13Connector[" + port + "]";
  +        threadGroup = new ThreadGroup(threadName);
  +        threadGroup.setDaemon(true);
           logger.setConnector(this);
           logger.setName(threadName);
        lifecycle.fireLifecycleEvent(START_EVENT, null);
  @@ -1027,5 +1068,29 @@
   
       }
   
  +    /**
  +     * Debugging thread used to debug thread activity in this
  +     * connector.
  +     */
  +    private class DebugThread extends Thread
  +    {
  +        public void run() {
  +            while (true) {
  +                try {
  +                    sleep(60 * 1000);
  +                } catch (InterruptedException e) {
  +                    break;
  +                }
  +                if (debug > 0) {
  +                    logger.log("active threads=" + threadGroup.activeCount());
  +                    System.out.println("===================================");
  +                    System.out.println("Ajp13Connector active threads="
  +                                       + threadGroup.activeCount());
  +                    threadGroup.list();
  +                    System.out.println("===================================");
  +                }
  +            }
  +        }
  +    }
   
   }
  
  
  
  1.8       +67 -9     
jakarta-tomcat-connectors/jk/java/org/apache/ajp/tomcat4/Ajp13Processor.java
  
  Index: Ajp13Processor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/ajp/tomcat4/Ajp13Processor.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Ajp13Processor.java       7 Feb 2002 00:44:40 -0000       1.7
  +++ Ajp13Processor.java       20 Feb 2002 16:12:42 -0000      1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/ajp/tomcat4/Ajp13Processor.java,v
 1.7 2002/02/07 00:44:40 costin Exp $
  - * $Revision: 1.7 $
  - * $Date: 2002/02/07 00:44:40 $
  + * $Header: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/ajp/tomcat4/Ajp13Processor.java,v
 1.8 2002/02/20 16:12:42 seguin Exp $
  + * $Revision: 1.8 $
  + * $Date: 2002/02/20 16:12:42 $
    *
    * ====================================================================
    *
  @@ -102,7 +102,7 @@
   
   /**
    * @author Kevin Seguin
  - * @version $Revision: 1.7 $ $Date: 2002/02/07 00:44:40 $
  + * @version $Revision: 1.8 $ $Date: 2002/02/20 16:12:42 $
    */
   
   final class Ajp13Processor
  @@ -140,8 +140,12 @@
        *
        * @param connector Ajp13Connector that owns this processor
        * @param id Identifier of this Ajp13Processor (unique per connector)
  +     * @param threadGroup The thread group any threads created by the processor
  +     *        should be in.
        */
  -    public Ajp13Processor(Ajp13Connector connector, int id) {
  +    public Ajp13Processor(Ajp13Connector connector,
  +                          int id,
  +                          ThreadGroup threadGroup) {
   
        super();
        this.connector = connector;
  @@ -154,6 +158,7 @@
           this.response.setConnector(connector);
        this.threadName =
          "Ajp13Processor[" + connector.getPort() + "][" + id + "]";
  +        this.threadGroup = threadGroup;
   
           this.logger.setConnector(connector);
           this.logger.setName(this.threadName);
  @@ -251,6 +256,12 @@
   
   
       /**
  +     * This processor's thread group.
  +     */
  +    private ThreadGroup threadGroup = null;
  +
  +
  +    /**
        * The thread synchronization object.
        */
       private Object threadSync = new Object();
  @@ -330,7 +341,7 @@
       private void parseConnection(Socket socket)
           throws IOException, ServletException {
   
  -     if (debug >= 2)
  +     if (debug > 1)
            logger.log("  parseConnection: address=" + socket.getInetAddress() +
                ", port=" + connector.getPort());
        request.setServerPort(connector.getPort());
  @@ -349,6 +360,16 @@
   
           Ajp13 ajp13 = new Ajp13();
           ajp13.setDebug(debug);
  +        ajp13.setLogger(new org.apache.ajp.Logger() {
  +                public void log(String msg) {
  +                    logger.log("[Ajp13] " + msg);
  +                }
  +                
  +                public void log(String msg, Throwable t) {
  +                    logger.log("[Ajp13] " + msg, t);
  +                }
  +            });
  +
           Ajp13InputStream input = new Ajp13InputStream(ajp13);
           Ajp13OutputStream output = new Ajp13OutputStream(ajp13);
           response.setAjp13(ajp13);
  @@ -368,7 +389,15 @@
               
               int status = 0;
               try {
  -                status = ajp13.receiveNextRequest(ajpRequest);                
  +                if (debug > 0) {
  +                    logger.log("waiting on next request...");
  +                }
  +                
  +                status = ajp13.receiveNextRequest(ajpRequest);
  +                
  +                if (debug > 0) {
  +                    logger.log("received next request, status=" + status);
  +                }
               } catch (IOException e) {
                   logger.log("process: ajp13.receiveNextRequest", e);
               }
  @@ -444,6 +473,10 @@
               }
   
               // Recycling the request and the response objects
  +            if (debug > 0) {
  +                logger.log("recyling objects ...");
  +            }
  +            
               ajpRequest.recycle();
               request.recycle();
               response.recycle();
  @@ -456,13 +489,29 @@
           }
           
        try {
  +            if (debug > 0) {
  +                logger.log("closing ajp13 object...");
  +            }
  +
               ajp13.close();
  +
  +            if (debug > 0) {
  +                logger.log("ajp13 object closed.");
  +            }
        } catch (IOException e) {
            logger.log("process: ajp13.close", e);
        }
   
        try {
  +            if (debug > 0) {
  +                logger.log("closing socket...");
  +            }
  +
               socket.close();
  +
  +            if (debug > 0) {
  +                logger.log("socket closed.");
  +            }
        } catch (IOException e) {
            logger.log("process: socket.close", e);
        }
  @@ -487,16 +536,25 @@
        while (!stopped.value()) {
   
            // Wait for the next socket to be assigned
  +            if (debug > 0) {
  +                logger.log("waiting for next socket to be assigned...");
  +            }
            Socket socket = await();
            if (socket == null)
                continue;
   
  +            if (debug > 0) {
  +                logger.log("socket assigned.");
  +            }
  +
            // Process the request from this socket
            process(socket);
   
            // Finish up this request
  +            if (debug > 0) {
  +                logger.log("recycling myself ...");
  +            }
            connector.recycle(this);
  -
        }
   
        // Tell threadStop() we have shut ourselves down successfully
  @@ -515,7 +573,7 @@
        logger.log(sm.getString("ajp13Processor.starting"));
   
           stopped.set(false);
  -     thread = new Thread(this, threadName);
  +     thread = new Thread(threadGroup, this, threadName);
        thread.setDaemon(true);
        thread.start();
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to