remm 2004/07/29 08:33:38 Modified: catalina/src/share/org/apache/catalina/core StandardContext.java StandardWrapper.java Log: - Add support for JMX notifications in Context and Wrapper. This needs JMX 1.2. - Submitted by Peter Rossbach, bug 29869. Revision Changes Path 1.138 +86 -2 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.137 retrieving revision 1.138 diff -u -r1.137 -r1.138 --- StandardContext.java 26 Jul 2004 16:04:01 -0000 1.137 +++ StandardContext.java 29 Jul 2004 15:33:38 -0000 1.138 @@ -34,11 +34,16 @@ import java.util.Stack; import java.util.TreeMap; +import javax.management.ListenerNotFoundException; +import javax.management.MBeanNotificationInfo; import javax.management.MBeanRegistrationException; import javax.management.MBeanServer; import javax.management.MalformedObjectNameException; import javax.management.Notification; import javax.management.NotificationBroadcasterSupport; +import javax.management.NotificationEmitter; +import javax.management.NotificationFilter; +import javax.management.NotificationListener; import javax.management.ObjectName; import javax.naming.NamingException; import javax.naming.directory.DirContext; @@ -104,7 +109,7 @@ public class StandardContext extends ContainerBase - implements Context, Serializable + implements Context, Serializable, NotificationEmitter { private static transient Log log = LogFactory.getLog(StandardContext.class); @@ -5120,6 +5125,85 @@ init(); } + /* Remove a JMX notficationListener + * @see javax.management.NotificationEmitter#removeNotificationListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object) + */ + public void removeNotificationListener(NotificationListener listener, + NotificationFilter filter, Object object) throws ListenerNotFoundException { + broadcaster.removeNotificationListener(listener,filter,object); + + } + + private MBeanNotificationInfo[] notificationInfo; + + /* Get JMX Broadcaster Info + * @TODO use StringManager for international support! + * @TODO This two events we not send j2ee.state.failed and j2ee.attribute.changed! + * @see javax.management.NotificationBroadcaster#getNotificationInfo() + */ + public MBeanNotificationInfo[] getNotificationInfo() { + // FIXME: i18n + if(notificationInfo == null) { + notificationInfo = new MBeanNotificationInfo[]{ + new MBeanNotificationInfo(new String[] { + "j2ee.object.created"}, + Notification.class.getName(), + "web application is created" + ), + new MBeanNotificationInfo(new String[] { + "j2ee.state.starting"}, + Notification.class.getName(), + "change web application is starting" + ), + new MBeanNotificationInfo(new String[] { + "j2ee.state.running"}, + Notification.class.getName(), + "web application is running" + ), + new MBeanNotificationInfo(new String[] { + "j2ee.state.stopped"}, + Notification.class.getName(), + "web application start to stopped" + ), + new MBeanNotificationInfo(new String[] { + "j2ee.object.stopped"}, + Notification.class.getName(), + "web application is stopped" + ), + new MBeanNotificationInfo(new String[] { + "j2ee.object.deleted"}, + Notification.class.getName(), + "web application is deleted" + ) + }; + + } + + return notificationInfo; + } + + + /* Add a JMX-NotificationListener + * @see javax.management.NotificationBroadcaster#addNotificationListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object) + */ + public void addNotificationListener(NotificationListener listener, + NotificationFilter filter, Object object) throws IllegalArgumentException { + broadcaster.addNotificationListener(listener,filter,object); + + } + + + /** + * Remove a JMX-NotificationListener + * @see javax.management.NotificationBroadcaster#removeNotificationListener(javax.management.NotificationListener) + */ + public void removeNotificationListener(NotificationListener listener) + throws ListenerNotFoundException { + broadcaster.removeNotificationListener(listener); + + } + + // ------------------------------------------------------------- Attributes 1.45 +85 -3 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.44 retrieving revision 1.45 diff -u -r1.44 -r1.45 --- StandardWrapper.java 23 Jun 2004 16:59:41 -0000 1.44 +++ StandardWrapper.java 29 Jul 2004 15:33:38 -0000 1.45 @@ -34,8 +34,13 @@ import javax.servlet.ServletResponse; import javax.servlet.SingleThreadModel; import javax.servlet.UnavailableException; +import javax.management.ListenerNotFoundException; +import javax.management.MBeanNotificationInfo; import javax.management.Notification; import javax.management.NotificationBroadcasterSupport; +import javax.management.NotificationEmitter; +import javax.management.NotificationFilter; +import javax.management.NotificationListener; import javax.management.ObjectName; import org.apache.catalina.Container; @@ -63,7 +68,7 @@ */ public class StandardWrapper extends ContainerBase - implements ServletConfig, Wrapper { + implements ServletConfig, Wrapper, NotificationEmitter { private static org.apache.commons.logging.Log log= org.apache.commons.logging.LogFactory.getLog( StandardWrapper.class ); @@ -1630,7 +1635,84 @@ } - // ------------------------------------------------------------- Attributes + /* Remove a JMX notficationListener + * @see javax.management.NotificationEmitter#removeNotificationListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object) + */ + public void removeNotificationListener(NotificationListener listener, + NotificationFilter filter, Object object) throws ListenerNotFoundException { + broadcaster.removeNotificationListener(listener,filter,object); + + } + + private MBeanNotificationInfo[] notificationInfo; + + /* Get JMX Broadcaster Info + * @TODO use StringManager for international support! + * @TODO This two events we not send j2ee.state.failed and j2ee.attribute.changed! + * @see javax.management.NotificationBroadcaster#getNotificationInfo() + */ + public MBeanNotificationInfo[] getNotificationInfo() { + + if(notificationInfo == null) { + notificationInfo = new MBeanNotificationInfo[]{ + new MBeanNotificationInfo(new String[] { + "j2ee.object.created"}, + Notification.class.getName(), + "servlet is created" + ), + new MBeanNotificationInfo(new String[] { + "j2ee.state.starting"}, + Notification.class.getName(), + "servlet is starting" + ), + new MBeanNotificationInfo(new String[] { + "j2ee.state.running"}, + Notification.class.getName(), + "servlet is running" + ), + new MBeanNotificationInfo(new String[] { + "j2ee.state.stopped"}, + Notification.class.getName(), + "servlet start to stopped" + ), + new MBeanNotificationInfo(new String[] { + "j2ee.object.stopped"}, + Notification.class.getName(), + "servlet is stopped" + ), + new MBeanNotificationInfo(new String[] { + "j2ee.object.deleted"}, + Notification.class.getName(), + "servlet is deleted" + ) + }; + + } + + return notificationInfo; + } + + + /* Add a JMX-NotificationListener + * @see javax.management.NotificationBroadcaster#addNotificationListener(javax.management.NotificationListener, javax.management.NotificationFilter, java.lang.Object) + */ + public void addNotificationListener(NotificationListener listener, + NotificationFilter filter, Object object) throws IllegalArgumentException { + broadcaster.addNotificationListener(listener,filter,object); + } + + + /** + * Remove a JMX-NotificationListener + * @see javax.management.NotificationBroadcaster#removeNotificationListener(javax.management.NotificationListener) + */ + public void removeNotificationListener(NotificationListener listener) + throws ListenerNotFoundException { + broadcaster.removeNotificationListener(listener); + } + + + // ------------------------------------------------------------- Attributes public boolean isEventProvider() {
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]