remm        2005/04/14 16:32:55

  Modified:    util/java/org/apache/tomcat/util/net AprEndpoint.java
               http11/src/java/org/apache/coyote/http11
                        Http11AprProtocol.java
               webapps/manager/WEB-INF/classes/org/apache/catalina/manager
                        StatusTransformer.java
  Log:
  - Code cleanup.
  - Number of keepalive connections seems a valuable statistics, as they won't 
show up in the scoreboard.
  - Fix thread names.
  
  Revision  Changes    Path
  1.2       +35 -62    
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/AprEndpoint.java
  
  Index: AprEndpoint.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/AprEndpoint.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AprEndpoint.java  14 Apr 2005 18:52:28 -0000      1.1
  +++ AprEndpoint.java  14 Apr 2005 23:32:54 -0000      1.2
  @@ -261,6 +261,14 @@
   
       
       /**
  +     * Number of keepalive sockets.
  +     */
  +    protected int keepAliveCount = 0;
  +    public int getKeepAliveCount() { return keepAliveCount; }
  +    public void setKeepAliveCount(int keepAliveCount) { this.keepAliveCount 
= keepAliveCount; }
  +    
  +    
  +    /**
        * Dummy maxSpareThreads property.
        */
       public int getMaxSpareThreads() { return 0; }
  @@ -378,8 +386,22 @@
           if (!running) {
               running = true;
               paused = false;
  -            // Start acceptor and poller threads
  -            threadStart();
  +
  +            // Start acceptor thread
  +            acceptorThread = new Thread(new Acceptor(), getName() + 
"-Acceptor");
  +            acceptorThread.setPriority(getThreadPriority());
  +            acceptorThread.setDaemon(true);
  +            acceptorThread.start();
  +
  +            // Start poller thread
  +            poller = new Poller(pollerSize);
  +            pollerThread = new Thread(poller, getName() + "-Poller");
  +            pollerThread.setPriority(getThreadPriority());
  +            pollerThread.setDaemon(true);
  +            pollerThread.start();
  +            
  +            // Start sendfile thread
  +            // FIXME: Implement sendfile support
           }
       }
   
  @@ -401,7 +423,9 @@
           if (running) {
               running = false;
               unlockAccept();
  -            threadStop();
  +            acceptorThread = null;
  +            pollerThread = null;
  +            sendfileThread = null;
           }
       }
   
  @@ -410,7 +434,7 @@
               stop();
           }
           // Close server socket
  -        closeServerSocket();
  +        Socket.close(serverSock);
           // Close all APR memory pools and resources
           Pool.destroy(rootPool);
           initialized = false ;
  @@ -429,26 +453,6 @@
   
   
       /**
  -     * Close the server socket.
  -     */
  -    protected void closeServerSocket() {
  -        if (!paused)
  -            unlockAccept();
  -        // FIXME: Close server socket
  -        Socket.close(serverSock);
  -        /*
  -        try {
  -            if( serverSocket!=null)
  -                serverSocket.close();
  -        } catch(Exception e) {
  -            log.error(sm.getString("endpoint.err.close"), e);
  -        }
  -        serverSocket = null;
  -        */
  -    }
  -
  -    
  -    /**
        * Unlock the server socket accept using a bugus connection.
        */
       protected void unlockAccept() {
  @@ -459,8 +463,8 @@
                   s = new java.net.Socket("127.0.0.1", port);
               } else {
                   s = new java.net.Socket(address, port);
  -                    // setting soLinger to a small value will help shutdown 
the
  -                    // connection quicker
  +                // setting soLinger to a small value will help shutdown the
  +                // connection quicker
                   s.setSoLinger(true, 0);
               }
           } catch(Exception e) {
  @@ -590,32 +594,6 @@
       }
   
   
  -    /**
  -     * Start the background processing thread.
  -     */
  -    protected void threadStart() {
  -        acceptorThread = new Thread(new Acceptor(), getName());
  -        acceptorThread.setPriority(getThreadPriority());
  -        acceptorThread.setDaemon(true);
  -        acceptorThread.start();
  -
  -        poller = new Poller(pollerSize);
  -        pollerThread = new Thread(poller, getName() + "-poller");
  -        pollerThread.setPriority(getThreadPriority());
  -        pollerThread.setDaemon(true);
  -        pollerThread.start();
  -    }
  -
  -
  -    /**
  -     * Stop the background processing thread.
  -     */
  -    protected void threadStop() {
  -        acceptorThread = null;
  -        pollerThread = null;
  -    }
  -
  -
       // --------------------------------------------------- Acceptor Inner 
Class
   
   
  @@ -698,7 +676,6 @@
           
           protected long serverPollset = 0;
           protected long pool = 0;
  -        protected int nsocks = 0;
           protected long[] desc;
   
           public Poller(int size) {
  @@ -707,6 +684,7 @@
                   serverPollset = Poll.create(size, pool, 0, soTimeout * 1000);
                   desc = new long[size];
               } catch( Exception ex ) {
  +                // FIXME: more appropriate logging
                   ex.printStackTrace();
               }
           }
  @@ -714,19 +692,14 @@
           public synchronized void add(long socket, long pool) {
               int rv = Poll.add(serverPollset, socket, pool, Poll.APR_POLLIN);
               if (rv == Status.APR_SUCCESS) {
  -                //System.out.println("Added socket " + socket + " to 
pollset");
  -                nsocks++;
  +                keepAliveCount++;
               }
           }
           
           public synchronized void remove(long socket) {
               int rv = Poll.remove(serverPollset, socket);
               if (rv == Status.APR_SUCCESS) {
  -                nsocks--;
  -                //System.out.println("Removed socket " + socket + " from 
pollset");
  -            } else {
  -                // FIXME: log this properly
  -                //System.out.println("Failed removing worker " + socket + " 
from pollset");
  +                keepAliveCount--;
               }
           }
           
  @@ -748,9 +721,9 @@
                       }
                   }
   
  -                while (nsocks < 1) {
  +                while (keepAliveCount < 1) {
                       try {
  -                        Thread.sleep(1);
  +                        Thread.sleep(10);
                       } catch (InterruptedException e) {
                           // Ignore
                       }
  
  
  
  1.2       +1 -0      
jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11AprProtocol.java
  
  Index: Http11AprProtocol.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11AprProtocol.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Http11AprProtocol.java    14 Apr 2005 18:52:28 -0000      1.1
  +++ Http11AprProtocol.java    14 Apr 2005 23:32:54 -0000      1.2
  @@ -113,6 +113,7 @@
       /** Start the protocol
        */
       public void init() throws Exception {
  +        ep.setName(getName());
           ep.setHandler(cHandler);
           try {
               checkSocketFactory();
  
  
  
  1.25      +8 -1      
jakarta-tomcat-catalina/webapps/manager/WEB-INF/classes/org/apache/catalina/manager/StatusTransformer.java
  
  Index: StatusTransformer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/webapps/manager/WEB-INF/classes/org/apache/catalina/manager/StatusTransformer.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- StatusTransformer.java    6 Oct 2004 17:10:25 -0000       1.24
  +++ StatusTransformer.java    14 Apr 2005 23:32:54 -0000      1.25
  @@ -204,6 +204,13 @@
               writer.print(mBeanServer.getAttribute(tpName, 
"currentThreadCount"));
               writer.print(" Current thread busy: ");
               writer.print(mBeanServer.getAttribute(tpName, 
"currentThreadsBusy"));
  +            try {
  +                Object value = mBeanServer.getAttribute(tpName, 
"keepAliveCount");
  +                writer.print(" Keeped alive sockets count: ");
  +                writer.print(value);
  +            } catch (Exception e) {
  +                // Ignore
  +            }
               
               writer.print("<br>");
   
  
  
  

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

Reply via email to