Skip to content

Commit

Permalink
Adjustments to support WildFly 10 [IMMUTANT-574]
Browse files Browse the repository at this point in the history
WF 10 uses ActiveMQ instead of HornetQ, which really only affects us on
queue creation and deletion. We still use the same WF API for doing
that, but it has moved to a new package in WF 10.
  • Loading branch information
tobias committed Aug 24, 2015
1 parent 352c1d8 commit f609563
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 20 deletions.
Expand Up @@ -16,7 +16,6 @@

package org.projectodd.wunderboss.as;

import org.jboss.as.messaging.jms.JMSServices;
import org.jboss.msc.service.ServiceController;
import org.projectodd.wunderboss.Options;
import org.projectodd.wunderboss.WunderBoss;
Expand Down Expand Up @@ -68,8 +67,7 @@ protected Topic createTopic(final String name) throws Exception {

@Override
protected void destroyQueue(final String name) {
ServiceController controller = this.mscService.serviceRegistry()
.getService(JMSServices.getJmsQueueBaseServiceName(MSCService.hqServiceName()).append(name));
ServiceController controller = this.mscService.serviceRegistry().getService(ASUtils.queueServiceName(name));
controller.setMode(ServiceController.Mode.REMOVE);

this.destinationManager.removeDestination(controller, name,
Expand All @@ -79,8 +77,7 @@ protected void destroyQueue(final String name) {

@Override
protected void destroyTopic(final String name) {
ServiceController controller = this.mscService.serviceRegistry()
.getService(JMSServices.getJmsTopicBaseServiceName(MSCService.hqServiceName()).append(name));
ServiceController controller = this.mscService.serviceRegistry().getService(ASUtils.topicServiceName(name));
controller.setMode(ServiceController.Mode.REMOVE);

this.destinationManager.removeDestination(controller, name,
Expand Down
Expand Up @@ -32,11 +32,11 @@ public Messaging create(String name, Options options) {

if (ASUtils.containerType() == ASUtils.ContainerType.EAP) {
destManager = new EAPDestinationManager(service.serviceTarget(),
MSCService.hqServiceName(),
ASUtils.messagingServiceName(),
service.namingContext());
} else {
destManager = new WildFlyDestinationManager(service.serviceTarget(),
MSCService.hqServiceName());
ASUtils.messagingServiceName());
}

return new ASMessaging(name, service, destManager, options);
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.projectodd.wunderboss.as;

import org.jboss.logging.Logger;
import org.jboss.msc.service.ServiceName;

import javax.management.MBeanException;
import javax.management.MBeanServer;
Expand All @@ -27,6 +28,8 @@
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import java.lang.management.ManagementFactory;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ASUtils {

Expand All @@ -44,6 +47,10 @@ public static boolean containerIsWildFly9() {
return CONTAINER_IS_WILDFLY_9;
}

public static boolean containerIsWildFly10() {
return CONTAINER_IS_WILDFLY_10;
}

public static boolean containerIsEAP() {
return containerType() == ContainerType.EAP;
}
Expand All @@ -63,7 +70,8 @@ public static String containerVersion() {
public static boolean isAsyncStreamingSupported() {
if (asyncSupported == null) {
asyncSupported = containerType() == ContainerType.EAP ||
containerIsWildFly9();
containerIsWildFly9() ||
containerIsWildFly10();

if (!asyncSupported) {
log.warn("NOTE: HTTP stream sends are synchronous in WildFly " + CONTAINER_VERSION +
Expand All @@ -74,6 +82,81 @@ public static boolean isAsyncStreamingSupported() {
return asyncSupported;
}

private static final String WF10_MESSAGING_PREFIX = "org.wildfly.extension.messaging.activemq.";
private static final String NOT_WF10_MESSAGING_PREFIX = "org.jboss.as.messaging.";

public static ServiceName messagingServiceName() {
String prefix;
String methodName;
try {
if (containerIsWildFly10()) {
prefix = WF10_MESSAGING_PREFIX;
methodName = "getActiveMQServiceName";
} else {
prefix = NOT_WF10_MESSAGING_PREFIX;
methodName = "getHornetQServiceName";
}

Method method = loadClass(prefix + "MessagingServices").getMethod(methodName, String.class);

return (ServiceName) method.invoke(null, "default");
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Failed to determine messaging service name", e);
}
}

public static ServiceName queueServiceName(String name) {
return ((ServiceName) callJMSServicesMethod("getJmsQueueBaseServiceName",
messagingServiceName()))
.append(name);
}

public static ServiceName topicServiceName(String name) {
return ((ServiceName) callJMSServicesMethod("getJmsTopicBaseServiceName",
messagingServiceName()))
.append(name);
}

private static Object callJMSServicesMethod(String methodName, Object... args) {
try {
Class clazz = loadClass((containerIsWildFly10() ? WF10_MESSAGING_PREFIX : NOT_WF10_MESSAGING_PREFIX)
+ "jms.JMSServices");
Method method = null;
for(Method each : clazz.getMethods()) {
if (methodName.equals(each.getName())) {
method = each;
break;
}
}

if (method == null) {
throw new NoSuchMethodException("No method " + methodName + " on class " + clazz);
}

return method.invoke(null, args);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Failed to invoke JMSSservices method", e);
}
}

public static Class queueServiceClass() {
return loadClass((containerIsWildFly10() ? WF10_MESSAGING_PREFIX : NOT_WF10_MESSAGING_PREFIX) +
"jms.JMSQueueService");
}

public static Class topicServiceClass() {
return loadClass((containerIsWildFly10() ? WF10_MESSAGING_PREFIX : NOT_WF10_MESSAGING_PREFIX) +
"jms.JMSTopicService");
}

private static Class loadClass(String name) {
try {
return ASUtils.class.getClassLoader().loadClass(name);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Failed to load class " + name, e);
}
}

// this can't be recursive, as it can blow the stack
public static Object waitForAppearanceInJNDI(final Context ctx, final String jndiName, long timeout) {
while (timeout > 0) {
Expand Down Expand Up @@ -148,7 +231,6 @@ public static boolean waitForRemovalFromJNDI(final Context ctx, final String jnd
// WF 8 doesn't set the productName, so we can't identify solely based on it

ContainerType type = ContainerType.UNKNOWN;
boolean wf9 = false;
if ("EAP".equals(productName)) {
type = ContainerType.EAP;
} else if (version != null &&
Expand All @@ -158,15 +240,20 @@ public static boolean waitForRemovalFromJNDI(final Context ctx, final String jnd
productName.startsWith("WildFly")) {
// WF 9 (and up) actually set the productName
type = ContainerType.WILDFLY;
wf9 = true;
}

CONTAINER_TYPE = type;
CONTAINER_IS_WILDFLY_9 = wf9;
CONTAINER_IS_WILDFLY_9 = type == ContainerType.WILDFLY &&
version != null &&
version.startsWith("9.");
CONTAINER_IS_WILDFLY_10 = type == ContainerType.WILDFLY &&
version != null &&
version.startsWith("10.");
}
private static final String CONTAINER_VERSION;
private static final ContainerType CONTAINER_TYPE;
private static final boolean CONTAINER_IS_WILDFLY_9;
private static final boolean CONTAINER_IS_WILDFLY_10;
private static final Logger log = Logger.getLogger("org.projectodd.wunderboss.as");
private static Boolean asyncSupported;

Expand Down
Expand Up @@ -16,7 +16,6 @@

package org.projectodd.wunderboss.as;

import org.jboss.as.messaging.MessagingServices;
import org.jboss.logging.Logger;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceName;
Expand Down Expand Up @@ -91,10 +90,6 @@ public MSCService getValue() throws IllegalStateException, IllegalArgumentExcept
return this;
}

public static ServiceName hqServiceName() {
return MessagingServices.getHornetQServiceName("default");
}

public ServiceTarget serviceTarget() {
return this.serviceTarget;
}
Expand Down
Expand Up @@ -16,13 +16,12 @@

package org.projectodd.wunderboss.as.wildfly;

import org.jboss.as.messaging.jms.JMSQueueService;
import org.jboss.as.messaging.jms.JMSTopicService;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.value.Value;
import org.projectodd.wunderboss.as.ASDestinationManager;
import org.projectodd.wunderboss.as.ASUtils;
import org.projectodd.wunderboss.messaging.jms.JMSDestination;

import javax.jms.Queue;
Expand All @@ -43,7 +42,7 @@ public WildFlyDestinationManager(ServiceTarget target, ServiceName hqServiceName
public Queue installQueueService(String name, String jndiName,
String selector, boolean durable) throws Exception {
Queue queue = (Queue) waitForValueAvailabilityChange(
installService(JMSQueueService.class, name, target(),
installService(ASUtils.queueServiceClass(), name, target(),
hqServiceName(),
selector, durable,
new String[]{jndiName}),
Expand All @@ -59,7 +58,7 @@ public Queue installQueueService(String name, String jndiName,
@Override
public Topic installTopicService(String name, String jndiName) throws Exception {
Topic topic = (Topic) waitForValueAvailabilityChange(
installService(JMSTopicService.class, name, hqServiceName(),
installService(ASUtils.topicServiceClass(), name, hqServiceName(),
target(),
new String[]{jndiName}),
false);
Expand Down

0 comments on commit f609563

Please sign in to comment.