remm        2004/01/26 11:49:18

  Modified:    util/java/org/apache/tomcat/util/threads Reaper.java
                        ThreadPool.java
               util/java/org/apache/tomcat/util/buf MessageBytes.java
                        UDecoder.java
               util/java/org/apache/tomcat/util/net PoolTcpEndpoint.java
  Log:
  - Remove compilation warnings.
  
  Revision  Changes    Path
  1.5       +54 -51    
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/threads/Reaper.java
  
  Index: Reaper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/threads/Reaper.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Reaper.java       2 Sep 2003 21:34:38 -0000       1.4
  +++ Reaper.java       26 Jan 2004 19:49:17 -0000      1.5
  @@ -68,91 +68,94 @@
    * @author Costin Manolache
    */
   public class Reaper extends Thread {
  -    private boolean daemon=false;
  +    private boolean daemon = false;
   
       public Reaper() {
  -     if( daemon )
  +        if (daemon)
               this.setDaemon(true);
  -     this.setName("TomcatReaper");
  +        this.setName("TomcatReaper");
       }
   
       public Reaper(String name) {
  -        if( daemon )
  +        if (daemon)
               this.setDaemon(true);
  -     this.setName(name);
  +        this.setName(name);
       }
   
       private long interval = 1000 * 60; //ms
  -    
  +
       // XXX TODO Allow per/callback interval, find next, etc
       // Right now the "interval" is used for all callbacks
       // and it represent a sleep between runs.
  -    
  -    ThreadPoolRunnable cbacks[]=new ThreadPoolRunnable[30]; // XXX max
  -    Object tdata[][]=new Object[30][]; // XXX max
  -    int count=0;
  +
  +    ThreadPoolRunnable cbacks[] = new ThreadPoolRunnable[30]; // XXX max
  +    Object tdata[][] = new Object[30][]; // XXX max
  +    int count = 0;
   
       /** Adding and removing callbacks is synchronized
        */
  -    Object lock=new Object();
  -    static boolean running=true;
  +    Object lock = new Object();
  +    static boolean running = true;
   
       // XXX Should be called 'interval' not defaultInterval
   
  -    public void setDefaultInterval( long t ) {
  -     interval=t;
  +    public void setDefaultInterval(long t) {
  +        interval = t;
       }
   
       public long getDefaultIntervale() {
           return interval;
       }
   
  -    public int addCallback( ThreadPoolRunnable c, int interval ) {
  -     synchronized( lock ) {
  -         cbacks[count]=c;
  -         count++;
  -         return count-1;
  -     }
  +    public int addCallback(ThreadPoolRunnable c, int interval) {
  +        synchronized (lock) {
  +            cbacks[count] = c;
  +            count++;
  +            return count - 1;
  +        }
       }
   
  -    public void removeCallback( int idx ) {
  -     synchronized( lock ) {
  -         count--;
  -         cbacks[idx]=cbacks[count];
  -         cbacks[count]=null;
  -     }
  +    public void removeCallback(int idx) {
  +        synchronized (lock) {
  +            count--;
  +            cbacks[idx] = cbacks[count];
  +            cbacks[count] = null;
  +        }
       }
   
       public void startReaper() {
  -     running=true;
  -     this.start();
  +        running = true;
  +        this.start();
       }
   
       public synchronized void stopReaper() {
  -     running=false;
  -     System.out.println("Stop reaper ");
  -     this.interrupt(); // notify() doesn't stop sleep
  +        running = false;
  +        System.out.println("Stop reaper ");
  +        this.interrupt(); // notify() doesn't stop sleep
       }
  -    
  +
       public void run() {
  -     while (running) {
  -         if( !running) break;
  -         try {
  -             this.sleep(interval);
  -         } catch (InterruptedException ie) {
  -             // sometimes will happen
  -         }
  -
  -         if( !running) break;
  -         for( int i=0; i< count; i++ ) {
  -             ThreadPoolRunnable callB=cbacks[i];
  -             // it may be null if a callback is removed.
  -             //  I think the code is correct
  -             if( callB!= null ) {
  -                 callB.runIt( tdata[i] );
  -             }
  -             if( !running) break;
  -         }
  -     }
  +        while (running) {
  +            if (!running)
  +                break;
  +            try {
  +                Thread.sleep(interval);
  +            } catch (InterruptedException ie) {
  +                // sometimes will happen
  +            }
  +
  +            if (!running)
  +                break;
  +            for (int i = 0; i < count; i++) {
  +                ThreadPoolRunnable callB = cbacks[i];
  +                // it may be null if a callback is removed.
  +                //  I think the code is correct
  +                if (callB != null) {
  +                    callB.runIt(tdata[i]);
  +                }
  +                if (!running)
  +                    break;
  +            }
  +        }
       }
   }
  
  
  
  1.22      +68 -68    
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/threads/ThreadPool.java
  
  Index: ThreadPool.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/threads/ThreadPool.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- ThreadPool.java   21 Jan 2004 17:54:02 -0000      1.21
  +++ ThreadPool.java   26 Jan 2004 19:49:17 -0000      1.22
  @@ -649,89 +649,89 @@
   
           public void run() {
               boolean _shouldRun = false;
  -            boolean _shouldTerminate = false; 
  +            boolean _shouldTerminate = false;
               ThreadPoolRunnable _toRun = null;
  -          try {
  -            while(true) {
  -                try {
  -                    /* Wait for work. */
  -                    synchronized(this) {
  -                        while (!shouldRun && !shouldTerminate) {
  -                            this.wait();
  +            try {
  +                while (true) {
  +                    try {
  +                        /* Wait for work. */
  +                        synchronized (this) {
  +                            while (!shouldRun && !shouldTerminate) {
  +                                this.wait();
  +                            }
  +                            _shouldRun = shouldRun;
  +                            _shouldTerminate = shouldTerminate;
  +                            _toRun = toRun;
                           }
  -                        _shouldRun = shouldRun;
  -                        _shouldTerminate = shouldTerminate;
  -                        _toRun = toRun;
  -                    }
   
  -                    if( _shouldTerminate ) {
  -                            if( p.log.isDebugEnabled())
  -                                p.log.debug( "Terminate");
  +                        if (_shouldTerminate) {
  +                            if (ThreadPool.log.isDebugEnabled())
  +                                ThreadPool.log.debug("Terminate");
                               break;
  -                    }
  +                        }
   
  -                    /* Check if should execute a runnable.  */
  -                    try {
  -                        if(noThData) {
  -                            if( _toRun != null ) {
  -                                Object thData[]=_toRun.getInitData();
  -                                t.setThreadData(p, thData);
  -                                if(p.log.isDebugEnabled())
  -                                    p.log.debug( "Getting new thread data");
  +                        /* Check if should execute a runnable.  */
  +                        try {
  +                            if (noThData) {
  +                                if (_toRun != null) {
  +                                    Object thData[] = _toRun.getInitData();
  +                                    t.setThreadData(p, thData);
  +                                    if (ThreadPool.log.isDebugEnabled())
  +                                        ThreadPool.log.debug(
  +                                            "Getting new thread data");
  +                                }
  +                                noThData = false;
                               }
  -                            noThData = false;
  -                        }
   
  -                        if(_shouldRun) {
  -                         if( _toRun != null ) { 
  -                                _toRun.runIt(t.getThreadData(p));
  -                            } else if( toRunRunnable != null ) { 
  -                                toRunRunnable.run();
  -                            } else {
  -                                if( p.log.isDebugEnabled())
  -                                    p.log.debug( "No toRun ???");
  +                            if (_shouldRun) {
  +                                if (_toRun != null) {
  +                                    _toRun.runIt(t.getThreadData(p));
  +                                } else if (toRunRunnable != null) {
  +                                    toRunRunnable.run();
  +                                } else {
  +                                    if (ThreadPool.log.isDebugEnabled())
  +                                    ThreadPool.log.debug("No toRun ???");
  +                                }
                               }
  -                        }
  -                    } catch(Throwable t) {
  -                     p.log.error(sm.getString("threadpool.thread_error",
  -                                                 t, toRun.toString()));
  -                       /*
  -                        * The runnable throw an exception (can be even a 
ThreadDeath),
  -                        * signalling that the thread die.
  -                        *
  -                     * The meaning is that we should release the thread from
  -                     * the pool.
  -                     */
  -                        shouldTerminate = true;
  -                        shouldRun = false;
  -                        p.notifyThreadEnd(this);
  -                    } finally {
  -                        if(_shouldRun) {
  -                            shouldRun = false;
  +                        } catch (Throwable t) {
  +                            ThreadPool.log.error(sm.getString
  +                                ("threadpool.thread_error", t, toRun.toString()));
                               /*
  -                          * Notify the pool that the thread is now idle.
  -                             */
  -                            p.returnController(this);
  +                             * The runnable throw an exception (can be even a 
ThreadDeath),
  +                             * signalling that the thread die.
  +                             *
  +                            * The meaning is that we should release the thread from
  +                            * the pool.
  +                            */
  +                            shouldTerminate = true;
  +                            shouldRun = false;
  +                            p.notifyThreadEnd(this);
  +                        } finally {
  +                            if (_shouldRun) {
  +                                shouldRun = false;
  +                                /*
  +                                * Notify the pool that the thread is now idle.
  +                                 */
  +                                p.returnController(this);
  +                            }
                           }
  -                    }
   
  -                    /*
  -                  * Check if should terminate.
  -                  * termination happens when the pool is shutting down.
  -                  */
  -                    if(_shouldTerminate) {
  -                        break;
  +                        /*
  +                        * Check if should terminate.
  +                        * termination happens when the pool is shutting down.
  +                        */
  +                        if (_shouldTerminate) {
  +                            break;
  +                        }
  +                    } catch (InterruptedException ie) { /* for the wait operation */
  +                        // can never happen, since we don't call interrupt
  +                        ThreadPool.log.error("Unexpected exception", ie);
                       }
  -                } catch(InterruptedException ie) { /* for the wait operation */
  -                 // can never happen, since we don't call interrupt
  -                 p.log.error("Unexpected exception", ie);
                   }
  +            } finally {
  +                p.removeThread(Thread.currentThread());
               }
  -          } finally {
  -              p.removeThread(Thread.currentThread());
  -          }
           }
  -
           /** Run a task
            *
            * @param toRun
  
  
  
  1.11      +0 -2      
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/MessageBytes.java
  
  Index: MessageBytes.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/MessageBytes.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- MessageBytes.java 1 Oct 2003 07:52:21 -0000       1.10
  +++ MessageBytes.java 26 Jan 2004 19:49:17 -0000      1.11
  @@ -581,8 +581,6 @@
       }
   
       /** Set the buffer to the representation of an int
  -     *  @deprecated The buffer are general purpose, caching for headers should
  -     *  be done in headers
        */
       public void setInt(int i) {
        recycle();
  
  
  
  1.7       +4 -4      
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/UDecoder.java
  
  Index: UDecoder.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/UDecoder.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- UDecoder.java     2 Sep 2003 21:34:38 -0000       1.6
  +++ UDecoder.java     26 Jan 2004 19:49:17 -0000      1.7
  @@ -94,10 +94,10 @@
        byte buff[]=mb.getBytes();
        int end=mb.getEnd();
   
  -     int idx= mb.indexOf( buff, start, end, '%' );
  +     int idx= ByteChunk.indexOf( buff, start, end, '%' );
           int idx2=-1;
           if( query )
  -            idx2= mb.indexOf( buff, start, end, '+' );
  +            idx2= ByteChunk.indexOf( buff, start, end, '+' );
        if( idx<0 && idx2<0 ) {
            return;
        }
  @@ -154,10 +154,10 @@
        char buff[]=mb.getBuffer();
        int cend=mb.getEnd();
   
  -     int idx= mb.indexOf( buff, start, cend, '%' );
  +     int idx= CharChunk.indexOf( buff, start, cend, '%' );
           int idx2=-1;
           if( query )
  -            idx2= mb.indexOf( buff, start, cend, '+' );
  +            idx2= CharChunk.indexOf( buff, start, cend, '+' );
        if( idx<0 && idx2<0 ) {
            return;
        }
  
  
  
  1.33      +33 -30    
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/PoolTcpEndpoint.java
  
  Index: PoolTcpEndpoint.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/PoolTcpEndpoint.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- PoolTcpEndpoint.java      26 Jan 2004 18:19:48 -0000      1.32
  +++ PoolTcpEndpoint.java      26 Jan 2004 19:49:18 -0000      1.33
  @@ -75,7 +75,6 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.apache.tomcat.util.collections.SimplePool;
   import org.apache.tomcat.util.res.StringManager;
   import org.apache.tomcat.util.threads.ThreadPool;
   import org.apache.tomcat.util.threads.ThreadPoolRunnable;
  @@ -561,7 +560,7 @@
       PoolTcpEndpoint endpoint;
       
       public TcpWorkerThread(PoolTcpEndpoint endpoint) {
  -     this.endpoint = endpoint;
  +        this.endpoint = endpoint;
       }
   
       public Object[] getInitData() {
  @@ -574,8 +573,8 @@
       
       public void runIt(Object perThrData[]) {
   
  -     // Create per-thread cache
  -     if (endpoint.isRunning()) {
  +        // Create per-thread cache
  +        if (endpoint.isRunning()) {
   
               // Loop if endpoint is paused
               while (endpoint.isPaused()) {
  @@ -587,66 +586,70 @@
               }
   
               // Accept a new connection
  -         Socket s = null;
  -         try {
  +            Socket s = null;
  +            try {
                   s = endpoint.acceptSocket();
  -         } finally {
  -             // Continue accepting on another thread...
  +            } finally {
  +                // Continue accepting on another thread...
                   if (endpoint.isRunning()) {
                       endpoint.tp.runIt(this);
                   }
               }
   
               // Process the connection
  -         if (null != s) {
  -
  +            if (null != s) {
                   TcpConnection con = null;
                   int step = 1;
                   try {
   
                       // 1: Set socket options: timeout, linger, etc
  -                    endpoint.setSocketOptions( s );
  +                    endpoint.setSocketOptions(s);
   
                       // 2: SSL handshake
                       step = 2;
  -                 if(endpoint.getServerSocketFactory()!=null) {
  +                    if (endpoint.getServerSocketFactory() != null) {
                           endpoint.getServerSocketFactory().handshake(s);
  -                 }
  +                    }
   
                       // 3: Process the connection
                       step = 3;
                       con = (TcpConnection) perThrData[0];
  -                 con.setEndpoint(endpoint);
  -                 con.setSocket(s);
  -                 endpoint.getConnectionHandler()
  -                        .processConnection(con, (Object []) perThrData[1]);
  +                    con.setEndpoint(endpoint);
  +                    con.setSocket(s);
  +                    endpoint.getConnectionHandler().processConnection(
  +                        con,
  +                        (Object[]) perThrData[1]);
   
                   } catch (SocketException se) {
  -                    endpoint.log.error
  -                        ("Remote Host " + s.getInetAddress() +
  -                         " SocketException: " + se.getMessage());
  +                    PoolTcpEndpoint.log.error(
  +                        "Remote Host "
  +                            + s.getInetAddress()
  +                            + " SocketException: "
  +                            + se.getMessage());
                       // Try to close the socket
                       try {
                           s.close();
  -                    } catch (IOException e) {}
  +                    } catch (IOException e) {
  +                    }
                   } catch (Throwable t) {
                       if (step == 2) {
  -                        endpoint.log.debug("Handshake failed", t);
  +                        PoolTcpEndpoint.log.debug("Handshake failed", t);
                       } else {
  -                        endpoint.log.error("Unexpected error", t);
  +                        PoolTcpEndpoint.log.error("Unexpected error", t);
                       }
                       // Try to close the socket
                       try {
                           s.close();
  -                    } catch (IOException e) {}
  +                    } catch (IOException e) {
  +                    }
                   } finally {
                       if (con != null) {
                           con.recycle();
                       }
                   }
  -         }
  +            }
   
  -     }
  +        }
       }
  -
  +    
   }
  
  
  

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

Reply via email to