Author: markt
Date: Sun May  2 17:34:33 2010
New Revision: 940271

URL: http://svn.apache.org/viewvc?rev=940271&view=rev
Log:
Add MBean registration and de-registration to LifecycleBase
The new interface will need to be added to each component to get this to work.

Added:
    tomcat/trunk/java/org/apache/catalina/LifecycleMBeanRegistration.java   
(with props)
Modified:
    tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java
    tomcat/trunk/java/org/apache/catalina/util/LocalStrings.properties

Added: tomcat/trunk/java/org/apache/catalina/LifecycleMBeanRegistration.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/LifecycleMBeanRegistration.java?rev=940271&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/LifecycleMBeanRegistration.java 
(added)
+++ tomcat/trunk/java/org/apache/catalina/LifecycleMBeanRegistration.java Sun 
May  2 17:34:33 2010
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.catalina;
+
+import javax.management.MBeanRegistration;
+import javax.management.ObjectName;
+
+/**
+ * This interface extends the {...@link MBeanRegistration} interface and adds
+ * methods for obtaining the domain and object name used to register this
+ * component. This interface is intended to be implemented by components that
+ * already implement {...@link Lifecycle} to indicate that they require
+ * registration during {...@link Lifecycle#init()} and de-registration during
+ * {...@link Lifecycle#destroy()}. 
+ */
+public interface LifecycleMBeanRegistration extends MBeanRegistration {
+
+    /**
+     * Obtain the {...@link ObjectName} under which this component will be / 
has
+     * been registered.
+     */
+    public ObjectName getObjectName();
+
+
+    /**
+     * Obtain the domain under which this component will be / has been
+     * registered.
+     */
+    public String getDomain();
+
+}

Propchange: 
tomcat/trunk/java/org/apache/catalina/LifecycleMBeanRegistration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java?rev=940271&r1=940270&r2=940271&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java Sun May  2 
17:34:33 2010
@@ -17,12 +17,16 @@
 
 package org.apache.catalina.util;
 
+import javax.management.ObjectName;
+
 import org.apache.catalina.Lifecycle;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.LifecycleMBeanRegistration;
 import org.apache.catalina.LifecycleState;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.modeler.Registry;
 import org.apache.tomcat.util.res.StringManager;
 
 
@@ -95,7 +99,19 @@ public abstract class LifecycleBase impl
             invalidTransition(Lifecycle.INIT_EVENT);
         }
 
-        // TODO - Check for JMX support and register if required
+        // Register MBean if required
+        if (this instanceof LifecycleMBeanRegistration) {
+            ObjectName oname =
+                ((LifecycleMBeanRegistration) this).getObjectName();
+            
+            try {
+                Registry.getRegistry(null, null).registerComponent(
+                        this, oname, null);
+            } catch (Exception e) {
+                log.warn(sm.getString("lifecycleBase.initMBeanFail", 
toString(),
+                        oname), e);
+            }
+        }
         
         initInternal();
         
@@ -247,10 +263,15 @@ public abstract class LifecycleBase impl
             invalidTransition(Lifecycle.DESTROY_EVENT);
         }
 
-        // TODO - Check for JMX support and de-register if required
-        
         destroyInternal();
         
+        // De-register MBean if required
+        if (this instanceof LifecycleMBeanRegistration) {
+            ObjectName oname =
+                ((LifecycleMBeanRegistration) this).getObjectName();
+            Registry.getRegistry(null, null).unregisterComponent(oname);
+        }
+
         setState(LifecycleState.DESTROYED);
     }
     

Modified: tomcat/trunk/java/org/apache/catalina/util/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/LocalStrings.properties?rev=940271&r1=940270&r2=940271&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/LocalStrings.properties 
(original)
+++ tomcat/trunk/java/org/apache/catalina/util/LocalStrings.properties Sun May  
2 17:34:33 2010
@@ -22,6 +22,7 @@ extensionValidator.web-application-manif
 extensionValidator.extension-not-found-error=ExtensionValidator[{0}][{1}]: 
Required extension [{2}] not found.
 extensionValidator.extension-validation-error=ExtensionValidator[{0}]: Failure 
to find [{1}] required extension(s).
 extensionValidator.failload=Failure loading extension [{0}]
+lifecycleBase.initMBeanFail=Failed to register component [{0}] with MBean name 
[{1}]
 lifecycleBase.alreadyStarted=The start() method was called on component [{0}] 
after start() had already been called. The second call will be ignored.
 lifecycleBase.alreadyStopped=The stop() method was called on component [{0}] 
after stop() had already been called. The second call will be ignored.
 lifecycleBase.invalidTransition=An invalid Lifecycle transition was attempted 
([{0}]) for component [{1}] in state [{2}]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to