amyroh 2003/07/28 17:09:43 Modified: catalina/src/share/org/apache/catalina/core ContainerBase.java StandardContext.java StandardWrapper.java Log: Send JSR77 spec required notifications for J2EE mbeans. Revision Changes Path 1.26 +3 -1 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.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- ContainerBase.java 26 May 2003 22:03:59 -0000 1.25 +++ ContainerBase.java 29 Jul 2003 00:09:42 -0000 1.26 @@ -1461,7 +1461,9 @@ } public String getObjectName() { - return oname.toString(); + if (oname != null) { + return oname.toString(); + } else return null; } public String getDomain() { 1.75 +70 -11 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.74 retrieving revision 1.75 diff -u -r1.74 -r1.75 --- StandardContext.java 22 Jul 2003 21:01:26 -0000 1.74 +++ StandardContext.java 29 Jul 2003 00:09:42 -0000 1.75 @@ -85,11 +85,13 @@ import javax.servlet.ServletRequestListener; import javax.naming.NamingException; import javax.naming.directory.DirContext; -import javax.management.ObjectName; -import javax.management.MBeanServer; -import javax.management.MalformedObjectNameException; import javax.management.InstanceNotFoundException; +import javax.management.MalformedObjectNameException; import javax.management.MBeanRegistrationException; +import javax.management.MBeanServer; +import javax.management.Notification; +import javax.management.NotificationBroadcasterSupport; +import javax.management.ObjectName; import org.apache.naming.ContextBindings; import org.apache.naming.resources.BaseDirContext; import org.apache.naming.resources.FileDirContext; @@ -155,6 +157,7 @@ super(); pipeline.setBasic(new StandardContextValve()); namingResources.setContainer(this); + broadcaster = new NotificationBroadcasterSupport(); } @@ -199,8 +202,12 @@ * The application available flag for this Context. */ private boolean available = false; - - + + /** + * The broadcaster that sends j2ee notifications. + */ + private NotificationBroadcasterSupport broadcaster = null; + /** * The Locale to character set mapper for this application. */ @@ -441,7 +448,11 @@ */ private int sessionTimeout = 30; - + /** + * The notification sequence number. + */ + private long sequenceNumber = 0; + /** * The status code error pages for this web application, keyed by * HTTP status code (as an Integer). @@ -640,8 +651,7 @@ new Boolean(this.available)); } - - + /** * Return the Locale to character set mapper for this Context. */ @@ -4118,6 +4128,15 @@ lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null); startTime=System.currentTimeMillis(); + + // Send j2ee.state.running notification + if (this.getObjectName() != null) { + Notification notification = + new Notification("j2ee.state.running", this.getObjectName(), + sequenceNumber++); + broadcaster.sendNotification(notification); + } + // Close all JARs right away to avoid always opening a peak number // of files on startup if (getLoader() instanceof WebappLoader) { @@ -4198,7 +4217,15 @@ // Notify our interested LifecycleListeners lifecycle.fireLifecycleEvent(BEFORE_STOP_EVENT, null); - + + // Send j2ee.state.stoping notification + if (this.getObjectName() != null) { + Notification notification = + new Notification("j2ee.state.stoping", this.getObjectName(), + sequenceNumber++); + broadcaster.sendNotification(notification); + } + // Mark this application as unavailable while we shut down setAvailable(false); @@ -4262,6 +4289,14 @@ } + // Send j2ee.state.stopped notification + if (this.getObjectName() != null) { + Notification notification = + new Notification("j2ee.state.stopped", this.getObjectName(), + sequenceNumber++); + broadcaster.sendNotification(notification); + } + // Reset application context context = null; @@ -4305,8 +4340,14 @@ 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; - } + } } @@ -4975,6 +5016,15 @@ if(! Registry.getRegistry().getMBeanServer().isRegistered(oname)) { controller = oname; Registry.getRegistry().registerComponent(this, oname, null); + + // Send j2ee.object.created notification + if (this.getObjectName() != null) { + Notification notification = new Notification( + "j2ee.object.created", + this.getObjectName(), + sequenceNumber++); + broadcaster.sendNotification(notification); + } } for (Iterator it = wrappers.iterator(); it.hasNext() ; ) { StandardWrapper wrapper=(StandardWrapper)it.next(); @@ -5040,6 +5090,15 @@ new String[] {"org.apache.catalina.Container"}); } super.init(); + + // Send j2ee.state.starting notification + if (this.getObjectName() != null) { + Notification notification = new Notification("j2ee.state.starting", + this.getObjectName(), + sequenceNumber++); + broadcaster.sendNotification(notification); + } + } public ObjectName getParentName() throws MalformedObjectNameException { 1.30 +66 -8 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardWrapper.java Index: StandardWrapper.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardWrapper.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- StandardWrapper.java 22 Jul 2003 18:51:21 -0000 1.29 +++ StandardWrapper.java 29 Jul 2003 00:09:42 -0000 1.30 @@ -81,6 +81,8 @@ import javax.servlet.ServletResponse; import javax.servlet.SingleThreadModel; import javax.servlet.UnavailableException; +import javax.management.Notification; +import javax.management.NotificationBroadcasterSupport; import javax.management.ObjectName; import org.apache.catalina.Container; @@ -123,6 +125,7 @@ super(); swValve=new StandardWrapperValve(); pipeline.setBasic(swValve); + broadcaster = new NotificationBroadcasterSupport(); } @@ -137,8 +140,12 @@ * servlet is considered permanent. */ private long available = 0L; - - + + /** + * The broadcaster that sends j2ee notifications. + */ + private NotificationBroadcasterSupport broadcaster = null; + /** * The count of allocations that are currently active (even if they * are for the same instance, as will be true on a non-STM servlet). @@ -217,6 +224,10 @@ */ private String runAs = null; + /** + * The notification sequence number. + */ + private long sequenceNumber = 0; /** * The fully qualified servlet class name for this servlet. @@ -1515,7 +1526,15 @@ * @exception LifecycleException if a fatal error occurs during startup */ public void start() throws LifecycleException { - + + // Send j2ee.state.starting notification + if (this.getObjectName() != null) { + Notification notification = new Notification("j2ee.state.starting", + this.getObjectName(), + sequenceNumber++); + broadcaster.sendNotification(notification); + } + // Start up this component super.start(); @@ -1526,6 +1545,14 @@ // MOVED TO StandardContext START() METHOD setAvailable(0L); + + // Send j2ee.state.running notification + if (this.getObjectName() != null) { + Notification notification = + new Notification("j2ee.state.running", this.getObjectName(), + sequenceNumber++); + broadcaster.sendNotification(notification); + } } @@ -1539,7 +1566,15 @@ public void stop() throws LifecycleException { setAvailable(Long.MAX_VALUE); - + + // Send j2ee.state.stoping notification + if (this.getObjectName() != null) { + Notification notification = + new Notification("j2ee.state.stoping", this.getObjectName(), + sequenceNumber++); + broadcaster.sendNotification(notification); + } + // Shut down our servlet instance (if it has been initialized) try { unload(); @@ -1551,8 +1586,22 @@ // Shut down this component super.stop(); + // Send j2ee.state.stopped notification + if (this.getObjectName() != null) { + Notification notification = + new Notification("j2ee.state.stopped", this.getObjectName(), + sequenceNumber++); + broadcaster.sendNotification(notification); + } + 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); } } @@ -1576,6 +1625,15 @@ oname=new ObjectName(onameStr); controller=oname; Registry.getRegistry().registerComponent(this, oname, null ); + + // Send j2ee.object.created notification + if (this.getObjectName() != null) { + Notification notification = new Notification( + "j2ee.object.created", + this.getObjectName(), + sequenceNumber++); + broadcaster.sendNotification(notification); + } } catch( Exception ex ) { log.info("Error registering servlet with jmx " + this); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]