1 23 24 package org.objectweb.perseus.connector.ra.fos; 25 26 import org.objectweb.perseus.fos.api.FosException; 27 import org.objectweb.perseus.fos.api.FosLoggerFactory; 28 import org.objectweb.perseus.fos.api.FosManager; 29 import org.objectweb.perseus.fos.api.FosTransaction; 30 import org.objectweb.perseus.fos.lib.FosTxContext; 31 import org.objectweb.util.monolog.api.BasicLevel; 32 import org.objectweb.util.monolog.api.Logger; 33 34 import java.util.HashMap ; 35 import javax.transaction.xa.Xid ; 36 37 40 public class FosXAResourceFactory { 41 44 private Logger logger; 45 48 private Logger entityLogger; 49 52 private FosManager txContextFactory; 53 57 private HashMap txContexts = new HashMap (); 58 59 62 Xid [] getXidForRecovery() { 63 return txContextFactory.getXidForRecovery(); 64 } 65 66 71 FosXAResourceFactory(FosLoggerFactory flf, FosManager fm) { 72 logger = flf.getLogger(FosLoggerFactory.XARESOURCE, true); 73 entityLogger = flf.getLogger(FosLoggerFactory.XARESOURCE, false); 74 if (FosLoggerFactory.DEBUG) 75 logger.log(BasicLevel.DEBUG, 76 "Constructs a new FosXAResourceFactory"); 77 txContextFactory = fm; 78 } 79 80 84 FosXAResource createXAResource() throws FosException { 85 FosXAResource res = new FosXAResource(entityLogger, this); 86 if (FosLoggerFactory.DEBUG) 87 logger.log(BasicLevel.DEBUG, "Creates a XAResource: " + res); 88 return res; 89 } 90 91 95 void releaseXAResource(FosXAResource xar) { 96 if (FosLoggerFactory.DEBUG) 97 logger.log(BasicLevel.DEBUG, "Releases a XAResource: " + xar); 98 } 99 100 104 FosTxContext getTxContext(Xid xid) { 105 if (FosLoggerFactory.DEBUG) 106 logger.log(BasicLevel.DEBUG, "Looks for the TxContext associated with XID: " + xid); 107 FosTxContext txc = (FosTxContext) txContexts.get(xid); 108 if (FosLoggerFactory.DEBUG) 109 logger.log(BasicLevel.DEBUG, "Found: " + txc); 110 return txc; 111 } 112 113 117 FosTxContext createTxContext(Xid xid) throws FosException { 118 if (FosLoggerFactory.DEBUG) 119 logger.log(BasicLevel.DEBUG, "Creates a FosTxContext to be associated with XID: " + xid); 120 FosTxContext txc = (FosTxContext) txContextFactory.createTxContext(); 121 txc.begin(xid); 122 txContexts.put(xid, txc); 123 if (FosLoggerFactory.DEBUG) 124 logger.log(BasicLevel.DEBUG, "New one is: " + txc); 125 return txc; 126 } 127 128 132 void releaseTxContext(Xid xid) throws FosException { 133 if (FosLoggerFactory.DEBUG) 134 logger.log(BasicLevel.DEBUG, "Dissociates the FosTxContext associated with XID: " + xid); 135 FosTxContext txc = getTxContext(xid); 136 if (FosLoggerFactory.DEBUG) 137 logger.log(BasicLevel.DEBUG, "Releases FosTxContext: " + txc); 138 if (txc == null) { 139 logger.log(BasicLevel.WARN, "Try to release unknow XID context: " + xid); 140 return; 141 } 142 txContexts.remove(xid); 143 txContextFactory.releaseTxContext(txc); 144 } 145 } 146 | Popular Tags |