costin      00/12/03 00:19:03

  Modified:    src/share/org/apache/tomcat/context ErrorHandler.java
               src/share/org/apache/tomcat/core BaseInterceptor.java
                        ContextManager.java
               src/share/org/apache/tomcat/modules/server
                        Http10Interceptor.java
  Log:
  Few more changes in startup:
  
  - make sure no request is served before all interceptors are started.
  
  - added 2 more hooks - engineStart/engineStop. That will allow modules
  to know when the engine is accepting connections and when is it stopped
  ( mostly for the use of connectors )
  
  Revision  Changes    Path
  1.7       +2 -1      
jakarta-tomcat/src/share/org/apache/tomcat/context/ErrorHandler.java
  
  Index: ErrorHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/ErrorHandler.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ErrorHandler.java 2000/11/30 04:58:39     1.6
  +++ ErrorHandler.java 2000/12/03 08:19:02     1.7
  @@ -144,9 +144,10 @@
        // error
        // XXX this log was intended to debug the status code generation.
        // it can be removed for all cases.
  -     if( code != 302 && code != 401 && code!=400  ) // tuneme
  +     if( code != 302 && code != 401 && code!=400  ) {// tuneme
            ctx.log( "Status code:" + code + " request:"  + req + " msg:" +
                     req.getAttribute("javax.servlet.error.message"));
  +     }
        
        errorPath = ctx.getErrorPage( code );
        if( errorPath != null ) {
  
  
  
  1.27      +15 -0     
jakarta-tomcat/src/share/org/apache/tomcat/core/BaseInterceptor.java
  
  Index: BaseInterceptor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/BaseInterceptor.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- BaseInterceptor.java      2000/12/02 08:26:45     1.26
  +++ BaseInterceptor.java      2000/12/03 08:19:02     1.27
  @@ -326,6 +326,21 @@
       {
       }
   
  +    /** This notifies that tomcat is started. Adapters shouldn't
  +     accept connections before everything is set up internally.
  +    */
  +    public void engineStart(ContextManager cm )
  +     throws TomcatException
  +    {
  +    }
  +
  +    /** This notifies that tomcat is stoped. No more requests will
  +     be processed.
  +    */
  +    public void engineStop(ContextManager cm )
  +     throws TomcatException
  +    {
  +    }
   
       /**
        *  Called when a context is added to a CM. The context is probably not
  
  
  
  1.154     +39 -10    
jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java
  
  Index: ContextManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java,v
  retrieving revision 1.153
  retrieving revision 1.154
  diff -u -r1.153 -r1.154
  --- ContextManager.java       2000/12/02 08:26:47     1.153
  +++ ContextManager.java       2000/12/03 08:19:03     1.154
  @@ -425,21 +425,13 @@
                    cI[i].addContext( this, ctx );
                }
                ctx.setState( Context.STATE_ADDED );
  +             log("Adding " +  ctx.toString());
            } catch( TomcatException ex ) {
                log( "Context not added " + ctx , ex );
                continue;
            }
        }
  -    }
   
  -    /** Will start the connectors and begin serving requests.
  -     *  It must be called after init.
  -     */
  -    public final void start() throws TomcatException {
  -     if( state!=STATE_INIT )
  -         throw new TomcatException( "Invalid state in start(), " +
  -                                    " you need to call init() "+ state);
  -     
        Enumeration enum = getContexts();
        while (enum.hasMoreElements()) {
            Context ctx = (Context)enum.nextElement();
  @@ -453,6 +445,24 @@
            }
        }
   
  +
  +    }
  +
  +    /** Will start the connectors and begin serving requests.
  +     *  It must be called after init.
  +     */
  +    public final void start() throws TomcatException {
  +     if( state!=STATE_INIT )
  +         throw new TomcatException( "Invalid state in start(), " +
  +                                    " you need to call init() "+ state);
  +     
  +     //XXX before or after state=START ?
  +     
  +     BaseInterceptor cI[]=defaultContainer.getInterceptors();
  +     for( int i=0; i< cI.length; i++ ) {
  +         cI[i].engineStart( this );
  +     }
  +
        // requests can be processed now
        state=STATE_START;
       }
  @@ -460,6 +470,14 @@
       /** Will stop all connectors
        */
       public final void stop() throws Exception {
  +     state=STATE_INIT; // initialized, but not accepting connections
  +     
  +     BaseInterceptor cI[]=defaultContainer.getInterceptors();
  +     for( int i=0; i< cI.length; i++ ) {
  +         cI[i].engineStop( this );
  +     }
  +
  +     // XXX we shouldn't call shutdown is stop !
        shutdown();
       }
   
  @@ -631,7 +649,18 @@
        *  call this method to get it processed.
        */
       public final void service( Request req, Response res ) {
  -     internalService( req, res );
  +     if( state!=STATE_START ) {
  +         // A request was received before all components are
  +         // in started state. Than can happen if the adapter was
  +         // started too soon or of the server is temporarily
  +         // disabled.
  +         req.setAttribute("javax.servlet.error.message",
  +                          "Server is starting");
  +         handleStatus( req, res, 503 ); // service unavailable
  +     } else {
  +         internalService( req, res );
  +     }
  +     
        // clean up
        try {
            res.finish();
  
  
  
  1.8       +1 -0      
jakarta-tomcat/src/share/org/apache/tomcat/modules/server/Http10Interceptor.java
  
  Index: Http10Interceptor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/server/Http10Interceptor.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Http10Interceptor.java    2000/11/30 04:58:45     1.7
  +++ Http10Interceptor.java    2000/12/03 08:19:03     1.8
  @@ -162,6 +162,7 @@
            // any other exception or error is odd. Here we log it
            // with "ERROR" level, so it will show up even on
            // less-than-verbose logs.
  +         e.printStackTrace();
            log( "Error reading request, ignored", e, Logger.ERROR);
        } 
        finally {
  
  
  

Reply via email to