Is there a way to get maven to conditionally compile certain classes
against different artifact versions of ActiveMQ within the same project?
I have a working build against 5.3.0 (replaced 4.1.1), but can't see a
way of keeping 'ActiveMQ4Factory' in the same project (see below) - I
currently have a separate module/jar containing the ActiveMQ4Factory
class, which only gets loaded if mq5 ra jars are swapped out with mq4.
package org.apache.openejb.resource.activemq;
import org.apache.activemq.broker.BrokerService;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Properties;
public class ActiveMQFactory {
private static final Method setThreadProperties;
private static final Method createBroker;
static {
Class c = null;
try {
c =
Class.forName("org.apache.openejb.resource.activemq.ActiveMQ5Factory");
} catch (ClassNotFoundException e1) {
try {
c =
Class.forName("org.apache.openejb.resource.activemq.ActiveMQ4Factory");
} catch (ClassNotFoundException e2) {
throw new RuntimeException("Unable to load
ActiveMQFactory");
}
}
try {
setThreadProperties =
c.getDeclaredMethod("setThreadProperties", new Class[]{Properties.class});
} catch (NoSuchMethodException e) {
throw new RuntimeException("Unable to create
ActiveMQFactory setThreadProperties method");
}
try {
createBroker = c.getDeclaredMethod("createBroker", new
Class[]{URI.class});
} catch (NoSuchMethodException e) {
throw new RuntimeException("Unable to create
ActiveMQFactory setThreadProperties method");
}
}
public static void setThreadProperties(final Properties p) {
try {
setThreadProperties.invoke(null, p);
} catch (IllegalAccessException e) {
throw new
RuntimeException("ActiveMQFactory.setThreadProperties.IllegalAccessException",
e);
} catch (IllegalArgumentException e) {
throw new
RuntimeException("ActiveMQFactory.setThreadProperties.IllegalArgumentException",
e);
} catch (InvocationTargetException e) {
throw new
RuntimeException("ActiveMQFactory.setThreadProperties.InvocationTargetException",
e);
}
}
public BrokerService createBroker(final URI brokerURI) throws
Exception {
try {
return (BrokerService) createBroker.invoke(null, brokerURI);
} catch (IllegalAccessException e) {
throw new
Exception("ActiveMQFactory.createBroker.IllegalAccessException", e);
} catch (IllegalArgumentException e) {
throw new
Exception("ActiveMQFactory.createBroker.IllegalArgumentException", e);
} catch (InvocationTargetException e) {
throw new
Exception("ActiveMQFactory.createBroker.InvocationTargetException", e);
}
}
}
On 21.01.2010 15:29, David Blevins wrote:
On Jan 15, 2010, at 6:54 PM, Quintin Beukes wrote:
Hey,
I'll do this.
To use ActiveMQ with embedded OpenEJB, I just create a MDB and post
messages to it?
To test there are some unit tests that involve MDBs. There are a few
under openejb-core/src/test/java/org/apache/openejb/core/mdb. There
are also tests elsewhere for MDBs -- quite a lot in the iTests.
The work in question is largely on the classes mentioned below.
Initially it would be good enough to have a test case that ensured the
factory built the correct ActiveMQ resource adapter. Presuming it
does just that then all the other tests should still work.
Feel encouraged to keep asking questions. Rather impossible to give
an single answer that has all the info, so hopefully this is, to coin
a new acronym, ETKYG (Enough To Keep You Going).
-David
Quintin Beukes
On Thu, Jan 14, 2010 at 1:39 AM, David Blevins
<[email protected]> wrote:
On Jan 13, 2010, at 11:18 AM, Andy Gumbrecht wrote:
Is there a reason why such an 'old' activemq version is being used?
- 4.x
is really only for jdk1.4.
IIRC some package and class names changed between 4.x and 5.x so it
wasn't
possible to support them both without a bit of reflection (and there
really
wouldn't need to be much).
If someone wanted to give it a whirl here's the factory class that
creates
the broker:
http://svn.apache.org/repos/asf/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQResourceAdapter.java
And I think it was the super class of this class that was moved
between 4.x
and 5.x:
http://svn.apache.org/repos/asf/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/OpenEjbBrokerFactory.java
One approach might be to rename the "OpenEjbBrokerFactory" to
"ActiveMQ4BrokerFactory", create another that is
"ActiveMQ5BrokerFactory"
and have the ActiveMQResourceAdapter use reflection to try and load
each and
use the first one that loads. Or some flavor of that -- could take
the same
approach and have two different ActiveMQ${version}ResourceAdapter
factories
with a generic reflection based ActiveMQResourceAdapter factory.
-David
____________
Virus checked by G Data AntiVirus
Version: AVA 19.9710 dated 21.01.2010