KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > tm > TransactionManagerService


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6
7 package org.jfox.tm;
8
9 import java.util.Hashtable JavaDoc;
10 import javax.naming.Context JavaDoc;
11 import javax.naming.Name JavaDoc;
12 import javax.naming.NamingException JavaDoc;
13 import javax.naming.Reference JavaDoc;
14 import javax.naming.Referenceable JavaDoc;
15 import javax.naming.spi.ObjectFactory JavaDoc;
16
17 import org.jfox.ioc.common.AbstractService;
18 import org.jfox.ioc.ext.ActiveComponent;
19 import org.jfox.jndi.InitialContextHelper;
20
21 /**
22  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
23  */

24
25 public class TransactionManagerService extends AbstractService implements ActiveComponent, ObjectFactory JavaDoc, Referenceable JavaDoc {
26
27     public final static String JavaDoc JNDI_NAME = "TransactionManager";
28     private static TxManager tm = null;
29     private static Context JavaDoc jndiContext = null;
30     private static Reference JavaDoc ref = null;
31
32     protected void doStart() throws Exception JavaDoc {
33         jndiContext.rebind(JNDI_NAME, this);
34     }
35
36     protected void doStop() throws Exception JavaDoc {
37         jndiContext.unbind(JNDI_NAME);
38     }
39
40     protected void doInit() throws Exception JavaDoc {
41         jndiContext = InitialContextHelper.getInitialContext();
42         tm = TxManager.getInstance();
43     }
44
45     protected void doDestroy() throws Exception JavaDoc {
46         jndiContext = null;
47         tm = null;
48     }
49
50     public void run() {
51         // none
52
}
53
54     public Object JavaDoc getObjectInstance(Object JavaDoc obj, Name JavaDoc name, Context JavaDoc nameCtx, Hashtable JavaDoc environment) throws Exception JavaDoc {
55         if(tm == null) {
56             tm = TxManager.getInstance();
57         }
58         return tm;
59     }
60
61     public synchronized Reference JavaDoc getReference() throws NamingException JavaDoc {
62         if(ref == null) {
63             ref = new Reference JavaDoc(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     /*
77     public static TxManager lookup() throws NamingException {
78       return (TxManager)javax.rmi.PortableRemoteObject.narrow(InitialContextHelper.getInitialConext().lookup(JNDI_NAME),TxManager.class);
79     }
80     */

81     public static void main(String JavaDoc[] args) {
82
83     }
84 }
Popular Tags