From fcce3bac2a78fe57775d56e38425354f5ca7f0c9 Mon Sep 17 00:00:00 2001 From: Martyn Taylor Date: Thu, 24 Aug 2017 10:24:40 +0100 Subject: [PATCH] Revert "Changing the way to interact with JGroups in the ResourceAdapter" This reverts commit 2493158d1168bd6a93cafbecab68ba6c19901061. This is causing some problems with the classloader used in the RA, resulting in NPEs. Reverting this. We can revist when we have a more stable solution. --- .../activemq/artemis/ra/ActiveMQRaUtils.java | 16 ++++++++-------- .../artemis/ra/ActiveMQResourceAdapter.java | 8 ++++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRaUtils.java b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRaUtils.java index 47c95bfe2a..bc2b42f5f6 100644 --- a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRaUtils.java +++ b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRaUtils.java @@ -27,7 +27,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import org.apache.activemq.artemis.api.core.BroadcastEndpointFactory; +import org.jgroups.JChannel; /** * Various utility functions @@ -236,19 +236,19 @@ public final class ActiveMQRaUtils { /** * Within AS7 the RA is loaded by JCA. properties can only be passed in String form. However if - * RA is configured using jgroups stack, we need to pass a BroadcastEndpointFactory object. As is impossible with - * JCA, we use this method to allow a BroadcastEndpointFactory object to be located. + * RA is configured using jgroups stack, we need to pass a Channel object. As is impossible with + * JCA, we use this method to allow a JChannel object to be located. */ - public static BroadcastEndpointFactory locateBroadcastEndpointFactory(final String locatorClass, final String name) { - return AccessController.doPrivileged(new PrivilegedAction() { + public static JChannel locateJGroupsChannel(final String locatorClass, final String name) { + return AccessController.doPrivileged(new PrivilegedAction() { @Override - public BroadcastEndpointFactory run() { + public JChannel run() { try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class aClass = loader.loadClass(locatorClass); Object o = aClass.newInstance(); - Method m = aClass.getMethod("locateBroadcastEndpointFactory", new Class[]{String.class}); - return (BroadcastEndpointFactory) m.invoke(o, name); + Method m = aClass.getMethod("locateChannel", new Class[]{String.class}); + return (JChannel) m.invoke(o, name); } catch (Throwable e) { ActiveMQRALogger.LOGGER.debug(e.getMessage(), e); return null; diff --git a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQResourceAdapter.java b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQResourceAdapter.java index 98129804cd..bd4b8c919d 100644 --- a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQResourceAdapter.java +++ b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQResourceAdapter.java @@ -42,6 +42,7 @@ import java.util.regex.Pattern; import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.api.core.BroadcastEndpointFactory; +import org.apache.activemq.artemis.api.core.ChannelBroadcastEndpointFactory; import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration; import org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpointFactory; import org.apache.activemq.artemis.api.core.Pair; @@ -60,6 +61,7 @@ import org.apache.activemq.artemis.service.extensions.ServiceUtils; import org.apache.activemq.artemis.service.extensions.xa.recovery.XARecoveryConfig; import org.apache.activemq.artemis.utils.SensitiveDataCodec; import org.jboss.logging.Logger; +import org.jgroups.JChannel; /** * The resource adapter for ActiveMQ @@ -1714,7 +1716,8 @@ public class ActiveMQResourceAdapter implements ResourceAdapter, Serializable { if (jgroupsLocatorClassName != null) { String jchannelRefName = raProperties.getJgroupsChannelRefName(); - endpointFactory = ActiveMQRaUtils.locateBroadcastEndpointFactory(jgroupsLocatorClassName, jchannelRefName); + JChannel jchannel = ActiveMQRaUtils.locateJGroupsChannel(jgroupsLocatorClassName, jchannelRefName); + endpointFactory = new ChannelBroadcastEndpointFactory(jchannel, jgroupsChannel); } else if (discoveryAddress != null) { Integer discoveryPort = overrideProperties.getDiscoveryPort() != null ? overrideProperties.getDiscoveryPort() : getDiscoveryPort(); if (discoveryPort == null) { @@ -1814,7 +1817,8 @@ public class ActiveMQResourceAdapter implements ResourceAdapter, Serializable { String jgroupsLocatorClass = raProperties.getJgroupsChannelLocatorClass(); if (jgroupsLocatorClass != null) { String jgroupsChannelRefName = raProperties.getJgroupsChannelRefName(); - endpointFactory = ActiveMQRaUtils.locateBroadcastEndpointFactory(jgroupsLocatorClass, jgroupsChannelRefName); + JChannel jchannel = ActiveMQRaUtils.locateJGroupsChannel(jgroupsLocatorClass, jgroupsChannelRefName); + endpointFactory = new ChannelBroadcastEndpointFactory(jchannel, jgroupsChannel); } if (endpointFactory == null) { throw new IllegalArgumentException("must provide either TransportType or DiscoveryGroupAddress and DiscoveryGroupPort for ResourceAdapter Connection Factory");