allow for identifying a specific JBossWorkManagerMBean (SPR-6648)
This commit is contained in:
parent
431fd5bb22
commit
2ba1dd47b0
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.jca.work.glassfish;
|
package org.springframework.jca.work.glassfish;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import javax.resource.spi.work.WorkManager;
|
import javax.resource.spi.work.WorkManager;
|
||||||
|
|
||||||
import org.springframework.jca.work.WorkManagerTaskExecutor;
|
import org.springframework.jca.work.WorkManagerTaskExecutor;
|
||||||
|
|
@ -54,15 +53,13 @@ public class GlassFishWorkManagerTaskExecutor extends WorkManagerTaskExecutor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identify a specific GlassFish thread pool to talk to.
|
* Identify a specific GlassFish thread pool to talk to.
|
||||||
* <p>The thread pool name matches the resource adapter name
|
* <p>The thread pool name matches the resource adapter name
|
||||||
* in default RAR deployment scenarios.
|
* in default RAR deployment scenarios.
|
||||||
*/
|
*/
|
||||||
public void setThreadPoolName(String threadPoolName) {
|
public void setThreadPoolName(String threadPoolName) {
|
||||||
WorkManager wm = (WorkManager)
|
WorkManager wm = (WorkManager) ReflectionUtils.invokeMethod(this.getWorkManagerMethod, null, threadPoolName);
|
||||||
ReflectionUtils.invokeMethod(this.getWorkManagerMethod, null, new Object[] {threadPoolName});
|
|
||||||
if (wm == null) {
|
if (wm == null) {
|
||||||
throw new IllegalArgumentException("Specified thread pool name '" + threadPoolName +
|
throw new IllegalArgumentException("Specified thread pool name '" + threadPoolName +
|
||||||
"' does not correspond to an actual pool definition in GlassFish. Check your configuration!");
|
"' does not correspond to an actual pool definition in GlassFish. Check your configuration!");
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -35,6 +35,16 @@ import org.springframework.jca.work.WorkManagerTaskExecutor;
|
||||||
*/
|
*/
|
||||||
public class JBossWorkManagerTaskExecutor extends WorkManagerTaskExecutor {
|
public class JBossWorkManagerTaskExecutor extends WorkManagerTaskExecutor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identify a specific JBossWorkManagerMBean to talk to,
|
||||||
|
* through its JMX object name.
|
||||||
|
* <p>The default MBean name is "jboss.jca:service=WorkManager".
|
||||||
|
* @see JBossWorkManagerUtils#getWorkManager(String)
|
||||||
|
*/
|
||||||
|
public void setWorkManagerMBeanName(String mbeanName) {
|
||||||
|
setWorkManager(JBossWorkManagerUtils.getWorkManager(mbeanName));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains the default JBoss JCA WorkManager through a JMX lookup
|
* Obtains the default JBoss JCA WorkManager through a JMX lookup
|
||||||
* for the JBossWorkManagerMBean.
|
* for the JBossWorkManagerMBean.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.jca.work.jboss;
|
package org.springframework.jca.work.jboss;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import javax.management.MBeanServerConnection;
|
import javax.management.MBeanServerConnection;
|
||||||
import javax.management.MBeanServerInvocationHandler;
|
import javax.management.MBeanServerInvocationHandler;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
@ -37,23 +36,33 @@ public abstract class JBossWorkManagerUtils {
|
||||||
|
|
||||||
private static final String MBEAN_SERVER_CONNECTION_JNDI_NAME = "jmx/invoker/RMIAdaptor";
|
private static final String MBEAN_SERVER_CONNECTION_JNDI_NAME = "jmx/invoker/RMIAdaptor";
|
||||||
|
|
||||||
private static final String WORK_MANAGER_OBJECT_NAME = "jboss.jca:service=WorkManager";
|
private static final String DEFAULT_WORK_MANAGER_MBEAN_NAME = "jboss.jca:service=WorkManager";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain the default JBoss JCA WorkManager through a JMX lookup
|
* Obtain the default JBoss JCA WorkManager through a JMX lookup
|
||||||
* for the JBossWorkManagerMBean.
|
* for the default JBossWorkManagerMBean.
|
||||||
* @see org.jboss.resource.work.JBossWorkManagerMBean
|
* @see org.jboss.resource.work.JBossWorkManagerMBean
|
||||||
*/
|
*/
|
||||||
public static WorkManager getWorkManager() {
|
public static WorkManager getWorkManager() {
|
||||||
|
return getWorkManager(DEFAULT_WORK_MANAGER_MBEAN_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain the default JBoss JCA WorkManager through a JMX lookup
|
||||||
|
* for the JBossWorkManagerMBean.
|
||||||
|
* @param workManagerObjectName the JMX object name to use
|
||||||
|
* @see org.jboss.resource.work.JBossWorkManagerMBean
|
||||||
|
*/
|
||||||
|
public static WorkManager getWorkManager(String mbeanName) {
|
||||||
try {
|
try {
|
||||||
Class mbeanClass = JBossWorkManagerUtils.class.getClassLoader().loadClass(JBOSS_WORK_MANAGER_MBEAN_CLASS_NAME);
|
Class<?> mbeanClass = JBossWorkManagerUtils.class.getClassLoader().loadClass(JBOSS_WORK_MANAGER_MBEAN_CLASS_NAME);
|
||||||
InitialContext jndiContext = new InitialContext();
|
InitialContext jndiContext = new InitialContext();
|
||||||
MBeanServerConnection mconn = (MBeanServerConnection) jndiContext.lookup(MBEAN_SERVER_CONNECTION_JNDI_NAME);
|
MBeanServerConnection mconn = (MBeanServerConnection) jndiContext.lookup(MBEAN_SERVER_CONNECTION_JNDI_NAME);
|
||||||
ObjectName objectName = ObjectName.getInstance(WORK_MANAGER_OBJECT_NAME);
|
ObjectName objectName = ObjectName.getInstance(mbeanName);
|
||||||
Object workManagerMBean = MBeanServerInvocationHandler.newProxyInstance(mconn, objectName, mbeanClass, false);
|
Object workManagerMBean = MBeanServerInvocationHandler.newProxyInstance(mconn, objectName, mbeanClass, false);
|
||||||
Method getInstanceMethod = workManagerMBean.getClass().getMethod("getInstance", new Class[0]);
|
Method getInstanceMethod = workManagerMBean.getClass().getMethod("getInstance");
|
||||||
return (WorkManager) getInstanceMethod.invoke(workManagerMBean, new Object[0]);
|
return (WorkManager) getInstanceMethod.invoke(workManagerMBean);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue