--- /dev/null
+/*
+ * 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();
+
+}
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;
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();
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);
}
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}]