You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by iu...@apache.org on 2021/09/06 09:15:02 UTC

[brooklyn-server] branch revert-1097-fix/BROOkLYN-626 created (now 8547fea)

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

iuliana pushed a change to branch revert-1097-fix/BROOkLYN-626
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git.


      at 8547fea  Revert "BROOKLYN-626: fix jmxmp"

This branch includes the following new commits:

     new 8547fea  Revert "BROOKLYN-626: fix jmxmp"

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[brooklyn-server] 01/01: Revert "BROOKLYN-626: fix jmxmp"

Posted by iu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

iuliana pushed a commit to branch revert-1097-fix/BROOkLYN-626
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit 8547fea64ca77f1cfab7fa365640a6c934b22d6a
Author: Iuliana Cosmina <iu...@gmail.com>
AuthorDate: Mon Sep 6 10:14:57 2021 +0100

    Revert "BROOKLYN-626: fix jmxmp"
---
 karaf/features/src/main/feature/feature.xml             |  1 +
 .../java/org/apache/brooklyn/feed/jmx/JmxHelper.java    | 17 ++++++++++-------
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/karaf/features/src/main/feature/feature.xml b/karaf/features/src/main/feature/feature.xml
index abacdc8..0c326b5 100644
--- a/karaf/features/src/main/feature/feature.xml
+++ b/karaf/features/src/main/feature/feature.xml
@@ -260,6 +260,7 @@
 
     <feature name="brooklyn-software-base"  version="${project.version}"  description="Brooklyn Software Base">
         <bundle>mvn:org.apache.brooklyn/brooklyn-software-base/${project.version}</bundle>
+        <bundle dependency="true">wrap:mvn:org.glassfish.external/opendmk_jmxremote_optional_jar/${opendmk_jmxremote_optional_jar.version}$Import-Package=javax.management.openmbean,*</bundle>
         <feature>brooklyn-software-winrm</feature>
         <feature>brooklyn-policy</feature>
     </feature>
diff --git a/software/base/src/main/java/org/apache/brooklyn/feed/jmx/JmxHelper.java b/software/base/src/main/java/org/apache/brooklyn/feed/jmx/JmxHelper.java
index 0fd1384..dd93d72 100644
--- a/software/base/src/main/java/org/apache/brooklyn/feed/jmx/JmxHelper.java
+++ b/software/base/src/main/java/org/apache/brooklyn/feed/jmx/JmxHelper.java
@@ -306,13 +306,16 @@ public class JmxHelper {
      * Handles loading the {@link JMXConnector} in OSGi, where we need to supply the classloader.
      */
     public static JMXConnector newConnector(JMXServiceURL url, Map<String, ?> env) throws IOException {
-        // Fix for BROOKLYN-626
-        // In Karaf 4.2.8, they added jmxmp support via a jar in boot/lib/
-        // This means it's on the root classpath without it being a proper/normal bundle!
-        // We need to use the classes from that ClassLoader rather than our own bundle, otherwise
-        // we get ClassCastException when we deserialize a jmxmp message and try to cast it to
-        // `Message` from the other ClassLoader. 
-        return JMXConnectorFactory.connect(url, env);
+        Map<String, Object> envCopy = MutableMap.copyOf(env);
+        String protocol = url.getProtocol();
+        if ("jmxmp".equalsIgnoreCase(protocol)) {
+            envCopy.put(JMXConnectorFactory.PROTOCOL_PROVIDER_CLASS_LOADER, javax.management.remote.jmxmp.JMXMPConnector.class.getClassLoader());
+            envCopy.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, javax.management.remote.jmxmp.JMXMPConnector.class.getClassLoader());
+        } else if ("rmi".equalsIgnoreCase(protocol)) {
+            envCopy.put(JMXConnectorFactory.PROTOCOL_PROVIDER_CLASS_LOADER, javax.management.remote.rmi.RMIConnector.class.getClassLoader());
+            envCopy.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, javax.management.remote.rmi.RMIConnector.class.getClassLoader());
+        }
+        return JMXConnectorFactory.connect(url, envCopy);
     }
     
     @SuppressWarnings({ "rawtypes", "unchecked" })