remm        2003/10/31 13:45:25

  Modified:    catalina/src/share/org/apache/catalina/core
                        ContainerBase.java StandardContext.java
  Log:
  - Modify the MBean lifecycle for the containers.
  - The MBeans will now be removed only on destroy, rather than on stop.
  - The use case is this:
    * Assume a started host exists
    * Add a context by instantiating a MBean
    * Then call init (addChild will be called, which will start the context)
    * If there's an error starting the context, its MBean would have been removed
      right away, preventing further operations on the context (at least through JMX),
      and preventing redeploying it again (the host still has it as a child, so trying 
the
      same sequence again after fixing the issue would fail). I have deterrmined
      there's no way to properly handle this case through JMX, so the clean fix
      seems to do JMX unregistration only on destroy (so that the MBean has the
      same lifecycle as the context itself, which seems logical).
  
  Revision  Changes    Path
  1.30      +14 -13    
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ContainerBase.java
  
  Index: ContainerBase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ContainerBase.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- ContainerBase.java        15 Oct 2003 17:24:16 -0000      1.29
  +++ ContainerBase.java        31 Oct 2003 21:45:25 -0000      1.30
  @@ -1213,18 +1213,6 @@
               }
           }
   
  -        // unregister this component
  -        if( oname != null ) {
  -            try {
  -                if( controller == oname ) {
  -                    Registry.getRegistry().unregisterComponent(oname);
  -                    log.debug("unregistering " + oname);
  -                }
  -            } catch( Throwable t ) {
  -                log.error("Error unregistering ", t );
  -            }
  -        }
  -        
           // Notify our interested LifecycleListeners
           lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT, null);
   
  @@ -1253,7 +1241,7 @@
                   mserver.invoke(parentName, "addChild", new Object[] { this },
                           new String[] {"org.apache.catalina.Container"});
               }
  -        }      
  +        }
           initialized=true;
       }
       
  @@ -1266,6 +1254,19 @@
               stop();
           }
           initialized=false;
  +
  +        // unregister this component
  +        if ( oname != null ) {
  +            try {
  +                if( controller == oname ) {
  +                    Registry.getRegistry().unregisterComponent(oname);
  +                    log.debug("unregistering " + oname);
  +                }
  +            } catch( Throwable t ) {
  +                log.error("Error unregistering ", t );
  +            }
  +        }
  +
           if (parent != null) {
               parent.removeChild(this);
           }
  
  
  
  1.98      +32 -18    
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardContext.java
  
  Index: StandardContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
  retrieving revision 1.97
  retrieving revision 1.98
  diff -u -r1.97 -r1.98
  --- StandardContext.java      21 Oct 2003 00:18:25 -0000      1.97
  +++ StandardContext.java      31 Oct 2003 21:45:25 -0000      1.98
  @@ -4059,6 +4059,7 @@
   
           if (ok) {
   
  +            boolean mainOk = false;
               try {
   
                   started = true;
  @@ -4084,7 +4085,7 @@
   
                   // Set JMX object name for proper pipeline registration
                   preRegisterJMX();
  -
  +                
                   // Start our child containers, if any
                   Container children[] = findChildren();
                   for (int i = 0; i < children.length; i++) {
  @@ -4123,9 +4124,16 @@
                   // Start ContainerBackgroundProcessor thread
                   super.threadStart();
   
  +                mainOk = true;
  +
               } finally {
                   // Unbinding thread
                   unbindThread(oldCCL);
  +                if (!mainOk) {
  +                    // An exception occurred
  +                    // Register with JMX anyway, to allow management
  +                    registerJMX();
  +                }
               }
   
           }
  @@ -4190,9 +4198,9 @@
           }
   
           // JMX registration
  -        if (ok) {
  -            registerJMX();
  +        registerJMX();
   
  +        if (ok) {
               // Notify our interested LifecycleListeners
               lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null);
           }
  @@ -4206,13 +4214,18 @@
                                   sequenceNumber++);
               broadcaster.sendNotification(notification);
           }
  -        
  +
           // Close all JARs right away to avoid always opening a peak number 
           // of files on startup
           if (getLoader() instanceof WebappLoader) {
               ((WebappLoader) getLoader()).closeJARs(true);
           }
   
  +        // Reinitializing if something went wrong
  +        if (!ok && started) {
  +            stop();
  +        }
  +
           //cacheContext();
       }
       
  @@ -4403,6 +4416,13 @@
        * 
        */ 
       public void destroy() throws Exception {
  +        if( oname != null ) { 
  +            // Send j2ee.object.deleted notification 
  +            Notification notification = 
  +                new Notification("j2ee.object.deleted", this.getObjectName(), 
  +                                sequenceNumber++);
  +            broadcaster.sendNotification(notification);
  +        } 
           super.destroy();
       }
       
  @@ -4411,17 +4431,6 @@
           // If you extend this - override this method and make sure to clean up
           children=new HashMap();
           log.debug("resetContext " + oname + " " + mserver);
  -        if( oname != null ) { 
  -            Registry.getRegistry().unregisterComponent(oname);
  -            
  -            // Send j2ee.object.deleted notification 
  -            Notification notification = 
  -                new Notification("j2ee.object.deleted", this.getObjectName(), 
  -                                sequenceNumber++);
  -            broadcaster.sendNotification(notification);
  -            oname = null;
  -        } 
  -        
       }
   
       /**
  @@ -5233,8 +5242,13 @@
               this.addLifecycleListener(config);
   
               log.debug( "AddChild " + parentName + " " + this);
  -            mserver.invoke(parentName, "addChild", new Object[] { this },
  -                    new String[] {"org.apache.catalina.Container"});
  +            try {
  +                mserver.invoke(parentName, "addChild", new Object[] { this },
  +                               new String[] {"org.apache.catalina.Container"});
  +            } catch (Exception e) {
  +                destroy();
  +                throw e;
  +            }
           }
           super.init();
           
  
  
  

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

Reply via email to