This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push:
new 8cbe4ba Remove apparent Registry code duplication
8cbe4ba is described below
commit 8cbe4ba594dc41615faafb216fcb4ff3e0d8fafc
Author: remm <[email protected]>
AuthorDate: Thu Mar 28 15:31:09 2019 +0100
Remove apparent Registry code duplication
mserver field seems useless overall, so deprecate it. Use the resgistry
register/unregister rather than duplicated code.
---
java/org/apache/catalina/core/StandardServer.java | 12 ++++---
.../apache/catalina/util/LifecycleMBeanBase.java | 40 +++-------------------
.../apache/catalina/util/LocalStrings.properties | 2 --
3 files changed, 12 insertions(+), 42 deletions(-)
diff --git a/java/org/apache/catalina/core/StandardServer.java
b/java/org/apache/catalina/core/StandardServer.java
index 5c38e19..2bf87a1 100644
--- a/java/org/apache/catalina/core/StandardServer.java
+++ b/java/org/apache/catalina/core/StandardServer.java
@@ -38,6 +38,7 @@ import java.util.concurrent.TimeUnit;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
+import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.apache.catalina.Context;
@@ -56,6 +57,7 @@ import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.ExceptionUtils;
import org.apache.tomcat.util.buf.StringCache;
+import org.apache.tomcat.util.modeler.Registry;
import org.apache.tomcat.util.res.StringManager;
import org.apache.tomcat.util.threads.TaskThreadFactory;
@@ -849,8 +851,9 @@ public final class StandardServer extends
LifecycleMBeanBase implements Server {
try {
// Note: Hard-coded domain used since this object is per Server/JVM
ObjectName sname = new ObjectName("Catalina:type=StoreConfig");
- if (mserver.isRegistered(sname)) {
- mserver.invoke(sname, "storeConfig", null, null);
+ MBeanServer server = Registry.getRegistry(null,
null).getMBeanServer();
+ if (server.isRegistered(sname)) {
+ server.invoke(sname, "storeConfig", null, null);
} else {
log.error(sm.getString("standardServer.storeConfig.notAvailable", sname));
}
@@ -878,8 +881,9 @@ public final class StandardServer extends
LifecycleMBeanBase implements Server {
try {
// Note: Hard-coded domain used since this object is per Server/JVM
ObjectName sname = new ObjectName("Catalina:type=StoreConfig");
- if (mserver.isRegistered(sname)) {
- mserver.invoke(sname, "store",
+ MBeanServer server = Registry.getRegistry(null,
null).getMBeanServer();
+ if (server.isRegistered(sname)) {
+ server.invoke(sname, "store",
new Object[] {context},
new String [] { "java.lang.String"});
} else {
diff --git a/java/org/apache/catalina/util/LifecycleMBeanBase.java
b/java/org/apache/catalina/util/LifecycleMBeanBase.java
index def6453..90fc2c8 100644
--- a/java/org/apache/catalina/util/LifecycleMBeanBase.java
+++ b/java/org/apache/catalina/util/LifecycleMBeanBase.java
@@ -17,8 +17,6 @@
package org.apache.catalina.util;
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
@@ -43,6 +41,7 @@ public abstract class LifecycleMBeanBase extends LifecycleBase
/* Cache components of the MBean registration. */
private String domain = null;
private ObjectName oname = null;
+ @Deprecated
protected MBeanServer mserver = null;
/**
@@ -52,7 +51,6 @@ public abstract class LifecycleMBeanBase extends LifecycleBase
*/
@Override
protected void initInternal() throws LifecycleException {
-
// If oname is not null then registration has already happened via
// preRegister().
if (oname == null) {
@@ -157,8 +155,7 @@ public abstract class LifecycleMBeanBase extends
LifecycleBase
try {
on = new ObjectName(name.toString());
-
- Registry.getRegistry(null, null).registerComponent(obj, on, null);
+ Registry.getRegistry(null,
null).registerComponent(name.toString(), on, null);
} catch (MalformedObjectNameException e) {
log.warn(sm.getString("lifecycleMBeanBase.registerFail", obj,
name),
e);
@@ -187,17 +184,7 @@ public abstract class LifecycleMBeanBase extends
LifecycleBase
StringBuilder name = new StringBuilder(getDomain());
name.append(':');
name.append(objectNameKeyProperties);
-
- ObjectName on = null;
-
- try {
- on = new ObjectName(name.toString());
- Registry.getRegistry(null, null).unregisterComponent(on);
- } catch (MalformedObjectNameException e) {
- log.warn(sm.getString("lifecycleMBeanBase.unregisterFail", name),
e);
- } catch (Exception e) {
- log.warn(sm.getString("lifecycleMBeanBase.unregisterFail", name),
e);
- }
+ Registry.getRegistry(null, null).unregisterComponent(name.toString());
}
@@ -211,26 +198,7 @@ public abstract class LifecycleMBeanBase extends
LifecycleBase
* @param on The name of the component to unregister
*/
protected final void unregister(ObjectName on) {
-
- // If null ObjectName, just return without complaint
- if (on == null) {
- return;
- }
-
- // If the MBeanServer is null, log a warning & return
- if (mserver == null) {
- log.warn(sm.getString("lifecycleMBeanBase.unregisterNoServer",
on));
- return;
- }
-
- try {
- mserver.unregisterMBean(on);
- } catch (MBeanRegistrationException e) {
- log.warn(sm.getString("lifecycleMBeanBase.unregisterFail", on), e);
- } catch (InstanceNotFoundException e) {
- log.warn(sm.getString("lifecycleMBeanBase.unregisterFail", on), e);
- }
-
+ Registry.getRegistry(null, null).unregisterComponent(on);
}
diff --git a/java/org/apache/catalina/util/LocalStrings.properties
b/java/org/apache/catalina/util/LocalStrings.properties
index b02af90..7c2fe5b 100644
--- a/java/org/apache/catalina/util/LocalStrings.properties
+++ b/java/org/apache/catalina/util/LocalStrings.properties
@@ -37,8 +37,6 @@ lifecycleBase.startFail=Failed to start component [{0}]
lifecycleBase.stopFail=Failed to stop component [{0}]
lifecycleMBeanBase.registerFail=Failed to register object [{0}] with name
[{1}] during component initialisation
-lifecycleMBeanBase.unregisterFail=Failed to unregister MBean with name [{0}]
during component destruction
-lifecycleMBeanBase.unregisterNoServer=No MBean server was available to
unregister the MBean [{0}]
netmask.cidrNegative=The CIDR [{0}] is negative
netmask.cidrNotNumeric=The CIDR [{0}] is not numeric
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]