1
16 package net.sf.ehcache.transaction.manager.selector;
17
18 import net.sf.ehcache.transaction.xa.EhcacheXAResource;
19 import net.sf.ehcache.util.ClassLoaderUtil;
20
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 import java.lang.reflect.Method;
25
26 import javax.transaction.xa.XAResource;
27
28
33 public class BitronixSelector extends FactorySelector {
34 private static final Logger LOG = LoggerFactory.getLogger(BitronixSelector.class);
35
36
39 public BitronixSelector() {
40 super("Bitronix", "bitronix.tm.TransactionManagerServices", "getTransactionManager");
41 }
42
43
46 @Override
47 public void registerResource(EhcacheXAResource ehcacheXAResource, boolean forRecovery) {
48 String uniqueName = ehcacheXAResource.getCacheName();
49 try {
50
51 Class producerClass = ClassLoaderUtil.loadClass("bitronix.tm.resource.ehcache.EhCacheXAResourceProducer");
52
53 Class[] signature = new Class[] {String.class, XAResource.class};
54 Object[] args = new Object[] {uniqueName, ehcacheXAResource};
55 Method method = producerClass.getMethod("registerXAResource", signature);
56 method.invoke(null, args);
57 } catch (Exception e) {
58 LOG.error("unable to register resource of cache " + uniqueName + " with BTM", e);
59 }
60 }
61
62
65 @Override
66 public void unregisterResource(EhcacheXAResource ehcacheXAResource, boolean forRecovery) {
67 String uniqueName = ehcacheXAResource.getCacheName();
68 try {
69 Class producerClass = ClassLoaderUtil.loadClass("bitronix.tm.resource.ehcache.EhCacheXAResourceProducer");
70
71 Class[] signature = new Class[] {String.class, XAResource.class};
72 Object[] args = new Object[] {uniqueName, ehcacheXAResource};
73 Method method = producerClass.getMethod("unregisterXAResource", signature);
74 method.invoke(null, args);
75 } catch (Exception e) {
76 LOG.error("unable to unregister resource of cache " + uniqueName + " with BTM", e);
77 }
78 }
79 }
80