1 22 package org.jboss.tm.iiop; 23 24 import javax.naming.Context ; 25 import javax.naming.InitialContext ; 26 import javax.naming.NamingException ; 27 28 import org.jboss.iiop.CorbaNamingService; 29 import org.jboss.iiop.CorbaORBService; 30 import org.jboss.system.ServiceMBeanSupport; 31 import org.jboss.tm.TMUtil; 32 import org.jboss.tm.TxManager; 33 import org.omg.CORBA.ORB ; 34 import org.omg.CosNaming.NameComponent ; 35 import org.omg.CosNaming.NamingContextExt ; 36 import org.omg.CosNaming.NamingContextExtHelper ; 37 import org.omg.CosNaming.NamingContextPackage.CannotProceed ; 38 import org.omg.CosNaming.NamingContextPackage.InvalidName ; 39 import org.omg.CosNaming.NamingContextPackage.NotFound ; 40 import org.omg.PortableServer.POA ; 41 import org.omg.PortableServer.POAManagerPackage.AdapterInactive ; 42 43 49 public class CorbaTransactionService 50 extends ServiceMBeanSupport 51 implements CorbaTransactionServiceMBean 52 { 53 public static String COSNAMING_NAME = "TransactionService"; 55 public static String COSNAMING_USERTX_NAME = "UserTransaction"; 56 public static String STR_TO_REMOTE_CONVERTER = "OtsStrToRemoteRefConverter"; 57 58 60 61 private POA poa; 62 63 64 private POA resourcePoa; 65 66 68 protected void startService() 69 throws Exception 70 { 71 Context jndiContext; 72 ORB orb; 73 74 try 75 { 76 jndiContext = new InitialContext (); 77 } 78 catch (NamingException e) 79 { 80 throw new RuntimeException ("Cannot get intial JNDI context: " + e); 81 } 82 try 83 { 84 orb = (ORB )jndiContext.lookup("java:/" + CorbaORBService.ORB_NAME); 85 } 86 catch (NamingException e) 87 { 88 throw new RuntimeException ("Cannot lookup java:/" 89 + CorbaORBService.ORB_NAME + ": " + e); 90 } 91 92 poa = CorbaORBService.getOtsPoa(); 94 95 resourcePoa = CorbaORBService.getOtsResourcePoa(); 100 101 OTSServant theDefaultServant = new OTSServant(orb, poa, resourcePoa); 103 poa.set_servant(theDefaultServant); 104 resourcePoa.set_servant(theDefaultServant.getResourceServant()); 105 106 poa.the_POAManager().activate(); 109 org.omg.CORBA.Object theTransactionFactory = 110 poa.create_reference_with_id(OTSServant.theFactoryId(), 111 TransactionFactoryExtHelper.id()); 112 113 NamingContextExt rootContext = null; 115 try 116 { 117 rootContext = NamingContextExtHelper.narrow((org.omg.CORBA.Object ) 119 jndiContext.lookup("java:/" + CorbaNamingService.NAMING_NAME)); 120 } 121 catch (NamingException e) 122 { 123 throw new Exception ("Cannot lookup java:/" + 124 CorbaNamingService.NAMING_NAME + ":\n" + e); 125 } 126 try 127 { 128 rootContext.rebind(rootContext.to_name(COSNAMING_NAME), 130 theTransactionFactory); 131 getLog().info("CORBA TransactionFactory started"); 132 getLog().debug("TransactionFactory: [" 133 + orb.object_to_string(theTransactionFactory) 134 + "]"); 135 136 rootContext.rebind(rootContext.to_name(COSNAMING_USERTX_NAME), 138 theTransactionFactory); 139 } 140 catch (Exception e) 141 { 142 getLog().error("Cannot bind transaction factory in CORBA naming service:", e); 143 throw new Exception ("Cannot bind transaction factory in CORBA naming service:\n" 144 + e); 145 } 146 147 TxManager tm = (TxManager)TMUtil.getTransactionManager(); 150 tm.setOTSResourceFactory(theDefaultServant); 151 tm.setOTSContextFactory(theDefaultServant); 152 tm.setOTSStringRemoteRefConverter(theDefaultServant); 153 } 154 155 protected void stopService() 156 { 157 try 158 { 159 poa.the_POAManager().hold_requests(false); 162 163 TxManager tm = (TxManager)TMUtil.getTransactionManager(); 165 tm.setOTSResourceFactory(null); 166 167 Context jndiContext = new InitialContext (); 169 NamingContextExt rootContext = 170 NamingContextExtHelper.narrow((org.omg.CORBA.Object ) 171 jndiContext.lookup("java:/" 172 + CorbaNamingService.NAMING_NAME)); 173 174 try 176 { 177 NameComponent [] name = rootContext.to_name(COSNAMING_NAME); 178 rootContext.unbind(name); 179 } 180 catch (InvalidName invalidName) 181 { 182 getLog().error("Cannot unregister transaction factory from CORBA naming service", 183 invalidName); 184 } 185 catch (NotFound notFound) 186 { 187 getLog().error("Cannot unregister transaction factory from CORBA naming service", 188 notFound); 189 } 190 catch (CannotProceed cannotProceed) 191 { 192 getLog().error("Cannot unregister transaction factory from CORBA naming service", 193 cannotProceed); 194 } 195 } 196 catch (NamingException namingException) 197 { 198 getLog().error("Unexpected error in JNDI lookup", namingException); 199 } 200 catch (AdapterInactive adapterInactive) 201 { 202 getLog().error("Unexpected error when stopping OTS POAs", adapterInactive); 203 } 204 } 205 206 } 207 | Popular Tags |