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 WeblogicSelector extends FactorySelector {
34 private static final Logger LOG = LoggerFactory.getLogger(WeblogicSelector.class);
35
36
39 public WeblogicSelector() {
40 super("Weblogic", "weblogic.transaction.TxHelper", "getTransactionManager");
41 }
42
43
46 @Override
47 public void registerResource(EhcacheXAResource ehcacheXAResource, boolean forRecovery) {
48 if (!forRecovery) {
49 return;
50 }
51
52 String uniqueName = ehcacheXAResource.getCacheName();
53 try {
54 Class tmImplClass = ClassLoaderUtil.loadClass("weblogic.transaction.TransactionManager");
55
56 Class[] signature = new Class[] {String.class, XAResource.class};
57 Object[] args = new Object[] {uniqueName, ehcacheXAResource};
58 Method method = tmImplClass.getMethod("registerResource", signature);
59 method.invoke(getTransactionManager(), args);
60 } catch (Exception e) {
61 LOG.error("unable to register resource of cache " + uniqueName + " with Weblogic", e);
62 }
63 }
64
65
68 @Override
69 public void unregisterResource(final EhcacheXAResource ehcacheXAResource, final boolean forRecovery) {
70 if (!forRecovery) {
71 return;
72 }
73
74 String uniqueName = ehcacheXAResource.getCacheName();
75 try {
76 Class tmImplClass = ClassLoaderUtil.loadClass("weblogic.transaction.TransactionManager");
77
78 Class[] signature = new Class[] {String.class, Boolean.TYPE};
79 Object[] args = new Object[] {uniqueName, Boolean.TRUE};
80 Method method = tmImplClass.getMethod("unregisterResource", signature);
81 method.invoke(getTransactionManager(), args);
82 } catch (Exception e) {
83 LOG.error("unable to unregister resource of cache " + uniqueName + " with Weblogic", e);
84 }
85 }
86
87 }
88