1 6 7 package org.jfox.tm; 8 9 import java.util.Hashtable ; 10 import javax.naming.Context ; 11 import javax.naming.Name ; 12 import javax.naming.NamingException ; 13 import javax.naming.Reference ; 14 import javax.naming.Referenceable ; 15 import javax.naming.spi.ObjectFactory ; 16 17 import org.jfox.ioc.common.AbstractService; 18 import org.jfox.ioc.ext.ActiveComponent; 19 import org.jfox.jndi.InitialContextHelper; 20 21 24 25 public class TransactionManagerService extends AbstractService implements ActiveComponent, ObjectFactory , Referenceable { 26 27 public final static String JNDI_NAME = "TransactionManager"; 28 private static TxManager tm = null; 29 private static Context jndiContext = null; 30 private static Reference ref = null; 31 32 protected void doStart() throws Exception { 33 jndiContext.rebind(JNDI_NAME, this); 34 } 35 36 protected void doStop() throws Exception { 37 jndiContext.unbind(JNDI_NAME); 38 } 39 40 protected void doInit() throws Exception { 41 jndiContext = InitialContextHelper.getInitialContext(); 42 tm = TxManager.getInstance(); 43 } 44 45 protected void doDestroy() throws Exception { 46 jndiContext = null; 47 tm = null; 48 } 49 50 public void run() { 51 } 53 54 public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception { 55 if(tm == null) { 56 tm = TxManager.getInstance(); 57 } 58 return tm; 59 } 60 61 public synchronized Reference getReference() throws NamingException { 62 if(ref == null) { 63 ref = new Reference (getClass().getName(), getClass().getName(), null); 64 } 65 return ref; 66 } 67 68 public int getNumTransactions() { 69 return tm.getNumTransactions(); 70 } 71 72 public int getNumSuspendedTransactions() { 73 return tm.getNumSuspendedTransactions(); 74 } 75 76 81 public static void main(String [] args) { 82 83 } 84 } | Popular Tags |