You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ib...@apache.org on 2021/05/24 11:38:34 UTC

[ignite-3] branch main updated: IGNITE-14770 Added unregistration of scalecube mx bean. (#144)

This is an automated email from the ASF dual-hosted git repository.

ibessonov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 8bc40bd  IGNITE-14770 Added unregistration of scalecube mx bean. (#144)
8bc40bd is described below

commit 8bc40bd5b72839c84307640d5d8517b64c6b7f9b
Author: ibessonov <be...@gmail.com>
AuthorDate: Mon May 24 14:38:25 2021 +0300

    IGNITE-14770 Added unregistration of scalecube mx bean. (#144)
    
    Co-authored-by: Aleksandr Polovtsev <al...@gmail.com>
---
 .../scalecube/ScaleCubeClusterServiceFactory.java  | 27 +++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeClusterServiceFactory.java b/modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeClusterServiceFactory.java
index f7042e1..d436f8e 100644
--- a/modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeClusterServiceFactory.java
+++ b/modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeClusterServiceFactory.java
@@ -17,9 +17,15 @@
 
 package org.apache.ignite.network.scalecube;
 
-import io.scalecube.cluster.ClusterConfig;
+import java.lang.management.ManagementFactory;
 import java.util.List;
 import java.util.stream.Collectors;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import io.scalecube.cluster.ClusterConfig;
 import io.scalecube.cluster.ClusterImpl;
 import io.scalecube.cluster.ClusterMessageHandler;
 import io.scalecube.cluster.membership.MembershipEvent;
@@ -81,10 +87,29 @@ public class ScaleCubeClusterServiceFactory implements ClusterServiceFactory {
 
             /** {@inheritDoc} */
             @Override public void shutdown() {
+                stopJmxMonitor();
+
                 cluster.shutdown();
                 cluster.onShutdown().block();
                 connectionManager.stop();
             }
+
+            /**
+             * Removes the JMX MBean registered by the "io.scalecube.cluster.ClusterImpl#startJmxMonitor()" method.
+             * Current ScaleCube implementation does not do that which leads to memory leaks.
+             */
+            private void stopJmxMonitor() {
+                MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+
+                try {
+                    var pattern = new ObjectName("io.scalecube.cluster", "name", cluster.member().id() + "@*");
+
+                    for (ObjectName name : server.queryNames(pattern, null))
+                        server.unregisterMBean(name);
+                }
+                catch (MalformedObjectNameException | InstanceNotFoundException | MBeanRegistrationException ignore) {
+                }
+            }
         };
     }