tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kfuj...@apache.org
Subject svn commit: r1790792 - in /tomcat/trunk/java/org/apache/catalina/tribes: group/GroupChannel.java jmx/JmxRegistry.java
Date Mon, 10 Apr 2017 08:31:43 GMT
Author: kfujino
Date: Mon Apr 10 08:31:42 2017
New Revision: 1790792

URL: http://svn.apache.org/viewvc?rev=1790792&view=rev
Log:
Add cleanup codes of JmxRegistry and channel MBeans.

Modified:
    tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannel.java
    tomcat/trunk/java/org/apache/catalina/tribes/jmx/JmxRegistry.java

Modified: tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannel.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannel.java?rev=1790792&r1=1790791&r2=1790792&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannel.java (original)
+++ tomcat/trunk/java/org/apache/catalina/tribes/group/GroupChannel.java Mon Apr 10 08:31:42
2017
@@ -22,6 +22,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
 import org.apache.catalina.tribes.ByteMessage;
@@ -703,6 +704,28 @@ public class GroupChannel extends Channe
         this.jmxPrefix = jmxPrefix;
     }
 
+    @Override
+    public ObjectName preRegister(MBeanServer server, ObjectName name)
+            throws Exception {
+        // NOOP
+        return null;
+    }
+
+    @Override
+    public void postRegister(Boolean registrationDone) {
+        // NOOP
+    }
+
+    @Override
+    public void preDeregister() throws Exception {
+        // NOOP
+    }
+
+    @Override
+    public void postDeregister() {
+        JmxRegistry.removeRegistry(this, true);
+    }
+
     /**
      *
      * <p>Title: Interceptor Iterator</p>

Modified: tomcat/trunk/java/org/apache/catalina/tribes/jmx/JmxRegistry.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/jmx/JmxRegistry.java?rev=1790792&r1=1790791&r2=1790792&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/jmx/JmxRegistry.java (original)
+++ tomcat/trunk/java/org/apache/catalina/tribes/jmx/JmxRegistry.java Mon Apr 10 08:31:42
2017
@@ -17,6 +17,7 @@
 package org.apache.catalina.tribes.jmx;
 
 import java.lang.management.ManagementFactory;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.management.InstanceNotFoundException;
@@ -60,6 +61,15 @@ public class JmxRegistry {
         return registry;
     }
 
+    public static void removeRegistry(Channel channel, boolean clear) {
+        JmxRegistry registry = registryCache.get(channel.getName());
+        if (registry == null) return;
+        if (clear) {
+            registry.clearMBeans();
+        }
+        registryCache.remove(channel.getName());
+    }
+
     private static ObjectName createBaseObjectName(String domain, String prefix, String name)
{
         if (domain == null) {
             log.warn(sm.getString("jmxRegistry.no.domain"));
@@ -109,4 +119,17 @@ public class JmxRegistry {
         }
     }
 
+    private void clearMBeans() {
+        String query = baseOname.toString() + ",*";
+        try {
+            ObjectName name = new ObjectName(query);
+            Set<ObjectName> onames = mbserver.queryNames(name, null);
+            for (ObjectName objectName : onames) {
+                unregisterJmx(objectName);
+            }
+        } catch (MalformedObjectNameException e) {
+            log.error(sm.getString("jmxRegistry.objectName.failed", query), e);
+        }
+    }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message