1 23 24 28 50 package com.sun.jts.CosTransactions; 51 52 54 import java.util.*; 55 import java.net.InetAddress ; 56 import java.net.UnknownHostException ; 57 58 import org.omg.CORBA.*; 59 import org.omg.CORBA.ORBPackage.InvalidName ; 60 import org.omg.CosTransactions.*; 61 import org.omg.CORBA.Policy .*; 62 import org.omg.CosNaming.*; 63 import org.omg.CosNaming.NamingContextPackage.*; 64 import org.omg.PortableServer.*; 65 import org.omg.CORBA.LocalObject ; 66 67 import com.sun.corba.ee.spi.costransactions.TransactionService; 68 import com.sun.corba.ee.spi.presentation.rmi.StubAdapter; 69 70 import com.sun.jts.otsidl.*; 71 72 import java.util.logging.Logger ; 73 import java.util.logging.Level ; 74 import com.sun.logging.LogDomains; 75 import com.sun.jts.utils.LogFormatter; 76 77 90 96 public class DefaultTransactionService implements TransactionService, 97 ProxyChecker { 98 private static CurrentImpl currentInstance = null; 99 private static TransactionFactoryImpl factoryInstance = null; 100 private static NamingContext namingContext = null; 102 private static ORB orb = null; 103 private static boolean recoverable = false; 104 private static boolean poasCreated = false; 105 private static boolean active = false; 106 109 static Logger _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER); 110 public static final String JTS_SERVER_ID = "com.sun.jts.persistentServerId"; 111 112 113 121 public DefaultTransactionService() { 122 126 } 127 128 131 public static boolean isActive() { 132 return active; 133 } 134 135 144 public org.omg.CosTransactions.Current get_current() { 145 org.omg.CosTransactions.Current result = null; 146 147 result = (org.omg.CosTransactions.Current)currentInstance; 148 149 return result; 150 } 151 152 167 public void identify_ORB(ORB orb, 168 TSIdentification ident, 169 Properties properties) { 170 if( this.orb == null ) { 171 this.orb = orb; 172 Configuration.setORB(orb); 173 Configuration.setProperties(properties); 174 Configuration.setProxyChecker(this); 175 } 176 177 180 183 if( !poasCreated ) { 184 String serverId = properties.getProperty(JTS_SERVER_ID); 186 if (serverId == null) { 187 serverId = 188 properties.getProperty("com.sun.CORBA.POA.ORBServerId"); 189 } 190 if (serverId != null) { 191 _logger.log(Level.INFO,"jts.startup_msg",serverId); 192 } 193 String serverName = "UnknownHost"; 194 try { 195 serverName = InetAddress.getLocalHost().getHostName(); 196 } catch (UnknownHostException ex) { 197 } 198 if( serverId != null ) { 199 Configuration.setServerName(serverName + ",P" + serverId, true); 200 recoverable = true; 201 } else { 202 long timestamp = System.currentTimeMillis(); 203 Configuration.setServerName(serverName + ",T" + 204 String.valueOf(timestamp), false); 205 } 206 207 209 try { 210 createPOAs(); 211 } catch( Exception exc ) { 212 _logger.log(Level.WARNING,"jts.unexpected_error_when_creating_poa",exc); 213 throw new INTERNAL(MinorCode.TSCreateFailed,CompletionStatus.COMPLETED_NO); 214 } 215 } 216 217 219 if( currentInstance == null ) 220 try { 221 currentInstance = new CurrentImpl(); 222 } catch( Exception exc ) { 223 _logger.log(Level.WARNING,"jts.unexpected_error_when_creating_current",exc); 224 throw new INTERNAL(MinorCode.TSCreateFailed,CompletionStatus.COMPLETED_NO); 225 } 226 227 229 SenderReceiver.identify(ident); 230 231 234 if( recoverable && namingContext == null ) 235 try { 236 namingContext = NamingContextHelper.narrow(orb.resolve_initial_references("NameService")); 237 } catch( InvalidName inexc ) { 238 if (_logger.isLoggable(Level.FINE)) { 240 _logger.log(Level.FINE,"jts.orb_not_running"); 241 } 242 } catch( Exception exc ) { 243 if (_logger.isLoggable(Level.FINE)) { 245 _logger.log(Level.FINE,"jts.orb_not_running"); 246 } 247 } 248 249 252 if( factoryInstance == null ) 253 try { 254 boolean localFactory = true; 255 TransactionFactory factory = null; 256 factoryInstance = new TransactionFactoryImpl(); 257 if (localFactory) { 258 factory = (TransactionFactory) factoryInstance; 259 } else { 260 factory = factoryInstance.object(); 261 } 262 263 266 Configuration.setFactory(factory, localFactory); 267 268 if (Configuration.isLocalFactory() == false && namingContext != null) { 269 NameComponent nc = new NameComponent(TransactionFactoryHelper.id(),""); 270 NameComponent path[] = {nc}; 271 namingContext.rebind(path,factory); 272 } 273 274 } catch( Exception exc ) { 278 _logger.log(Level.WARNING,"jts.cannot_register_with_orb","TransactionFactory"); 279 } 280 281 active = true; } 283 284 292 public static void shutdown( boolean immediate ) { 293 295 if( namingContext != null ) 296 try { 297 NameComponent nc = new NameComponent(TransactionFactoryHelper.id(),""); 298 NameComponent path[] = {nc}; 299 namingContext.unbind(path); 300 301 namingContext = null; 302 } catch( Exception exc ) {} 303 304 307 TransactionFactoryImpl.deactivate(); 308 CurrentImpl.deactivate(); 309 310 312 currentInstance.shutdown(immediate); 313 314 316 currentInstance = null; 317 factoryInstance = null; 318 active = false; 320 } 321 322 330 public final boolean isProxy( org.omg.CORBA.Object obj ) { 331 332 return !( StubAdapter.isStub(obj) && StubAdapter.isLocal(obj) ); 334 } 335 336 346 final static void createPOAs() 347 throws Exception { 348 349 POA rootPOA = (POA)orb.resolve_initial_references("RootPOA"); 350 351 353 POA CRpoa = null; 354 if( recoverable ) { 355 356 358 Policy [] tpolicy = new Policy [2]; 359 tpolicy[0] = rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT); 360 tpolicy[1] = rootPOA.create_request_processing_policy(RequestProcessingPolicyValue.USE_SERVANT_MANAGER); 361 CRpoa = rootPOA.create_POA("com.sun.jts.CosTransactions.CoordinatorResourcePOA", null, tpolicy); 362 363 365 CoordinatorResourceServantActivator crsa = new CoordinatorResourceServantActivator(orb); 366 CRpoa.set_servant_manager(crsa); 367 } 368 369 371 else 372 CRpoa = rootPOA; 373 374 Configuration.setPOA("CoordinatorResource",CRpoa); 375 376 378 POA RCpoa = null; 379 if( recoverable ) { 380 381 383 Policy [] tpolicy = new Policy [2]; 384 tpolicy[0] = rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT); 385 tpolicy[1] = rootPOA.create_request_processing_policy(RequestProcessingPolicyValue.USE_SERVANT_MANAGER); 386 RCpoa = rootPOA.create_POA("com.sun.jts.CosTransactions.RecoveryCoordinatorPOA", null, tpolicy); 387 388 390 RecoveryCoordinatorServantActivator rcsa = new RecoveryCoordinatorServantActivator(orb); 391 RCpoa.set_servant_manager(rcsa); 392 } 393 394 396 else 397 RCpoa = rootPOA; 398 399 Configuration.setPOA("RecoveryCoordinator",RCpoa); 400 401 403 POA Cpoa = rootPOA.create_POA("CoordinatorPOA", null, null); 404 Configuration.setPOA("Coordinator",Cpoa); 406 407 409 Configuration.setPOA("transient",rootPOA); 410 411 CRpoa.the_POAManager().activate(); 413 RCpoa.the_POAManager().activate(); 414 Cpoa.the_POAManager().activate(); 415 rootPOA.the_POAManager().activate(); 416 417 poasCreated = true; 418 419 } 420 } 421 422 432 439 class RecoveryCoordinatorServantActivator extends LocalObject implements ServantActivator { 440 private ORB orb = null; 441 442 449 450 461 462 470 RecoveryCoordinatorServantActivator(ORB orb) { 471 this.orb = orb; 472 } 473 474 484 public Servant incarnate( byte[] oid, POA adapter ) 485 throws org.omg.PortableServer.ForwardRequest { 486 487 Servant servant = new RecoveryCoordinatorImpl(oid); 488 489 return servant; 490 } 491 492 500 public void etherealize( byte[] oid, 501 POA adapter, 502 Servant servant, 503 boolean cleanup_in_progress, 504 boolean remaining_activations ) { 505 } 506 } 507 508 518 525 class CoordinatorResourceServantActivator extends LocalObject implements ServantActivator { 526 private ORB orb = null; 527 528 535 536 547 548 556 CoordinatorResourceServantActivator(ORB orb) { 557 this.orb = orb; 558 } 559 560 570 public Servant incarnate( byte[] oid, POA adapter ) 571 throws org.omg.PortableServer.ForwardRequest { 572 Servant servant = new CoordinatorResourceImpl(oid); 573 return servant; 574 } 575 576 584 public void etherealize( byte[] oid, 585 POA adapter, 586 Servant servant, 587 boolean cleanup_in_progress, 588 boolean remaining_activations ) { 589 } 590 } 591 592 class JTSAdapterActivator extends LocalObject implements AdapterActivator { 593 private ORB orb; 594 595 602 603 613 614 JTSAdapterActivator(ORB orb) { 615 this.orb = orb; 616 } 617 618 public boolean unknown_adapter(POA parent, String name) { 619 620 try { 621 DefaultTransactionService.createPOAs(); 622 } catch( Exception exc ) { 623 } 624 625 return true; 626 } 627 } 628 | Popular Tags |