1 23 24 package com.sun.enterprise.server.ondemand; 25 26 27 import java.io.*; 28 import java.util.Properties ; 29 import java.util.Vector ; 30 import java.net.*; 31 import java.rmi.RemoteException ; 32 import javax.rmi.CORBA.Tie ; 33 import javax.rmi.PortableRemoteObject ; 34 import javax.management.ObjectName ; 35 import org.omg.CORBA.ORB ; 36 import com.sun.corba.ee.impl.orbutil.ORBConstants; 37 38 import com.sun.enterprise.*; 39 import com.sun.enterprise.util.*; 40 import com.sun.enterprise.log.*; 41 import com.sun.enterprise.naming.*; 42 import com.sun.enterprise.distributedtx.*; 43 import com.sun.enterprise.iiop.POAProtocolMgr; 44 import com.sun.enterprise.iiop.PEORBConfigurator; 45 import com.sun.enterprise.iiop.ORBMonitoring; 46 import com.sun.enterprise.naming.java.javaURLContext; 47 import java.util.logging.*; 48 import com.sun.logging.*; 49 50 import com.sun.appserv.server.LifecycleEvent; 51 import com.sun.appserv.server.ServerLifecycleException; 52 53 import com.sun.enterprise.server.ResourcesUtil; 54 import com.sun.enterprise.server.ServerContext; 55 import com.sun.enterprise.server.ServerContextImpl; 56 import com.sun.enterprise.server.ApplicationServer; 57 import com.sun.enterprise.config.*; 58 import com.sun.enterprise.config.serverbeans.*; 59 import com.sun.enterprise.transaction.monitor.JTSMonitorMBean; 60 61 62 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactoryMgr; 63 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactory; 64 65 import com.sun.enterprise.deployment.backend.OptionalPkgDependency; 66 import com.sun.enterprise.deployment.*; 67 68 import com.sun.enterprise.server.ondemand.entry.EntryContext; 69 import com.sun.enterprise.server.ondemand.entry.EntryPoint; 70 import com.sun.enterprise.connectors.ConnectorRuntime; 71 72 80 public class EjbServiceGroup extends ServiceGroup { 81 82 public static final String J2EE_APPNAME = 83 "com.sun.enterprise.appname"; 84 public static final String JTS_SERVER_ID = 85 "com.sun.jts.persistentServerId"; 86 public static final String J2EE_SERVER_ID_PROP = 87 "com.sun.enterprise.J2EEServerId"; 88 89 private static final boolean debug = 91 com.sun.enterprise.util.logging.Debug.enabled; 92 93 private static LocalStringManagerImpl localStrings = 94 new LocalStringManagerImpl(com.sun.enterprise.server.J2EEServer.class); 95 96 private static final int DEFAULT_SERVER_ID = 100 ; 97 98 private final String MEJB_JNDI_NAME="ejb/mgmt/MEJB"; 99 100 101 private File repositoryDir; 104 105 private int orbInitialPort; 107 private ORB orb; 108 private ProtocolManager protocolMgr; 109 110 118 public void start(EntryContext context) 119 throws ServiceGroupException { 120 _start(context); 121 if (context.getEntryPointType() != EntryPoint.STARTUP) { 122 loadSystemApps(); 123 } 124 } 125 126 private void _start(EntryContext context) 128 throws ServiceGroupException { 129 ServerContext serverContext = context.getServerContext(); 130 String [] args = serverContext.getCmdLineArgs(); 131 if (args == null) args = new String [0]; 132 try { 133 startORB(args); 134 J2EETransactionManagerImpl.createJTSTransactionManager(); 136 } catch (Exception e) { 137 throw new ServiceGroupException (e); 138 } 139 } 140 141 145 public void stop(EntryContext context) throws ServiceGroupException { 146 super.stopLifecycleServices(); 147 } 148 149 152 public void abort(EntryContext context) { 153 super.stopLifecycleServices(); 154 } 155 156 161 private void loadSystemApps() { 162 SystemAppLoader loader = OnDemandServer.getSystemAppLoader(); 163 loader.loadSystemApps(loader.getEjbServiceGroupSystemApps()); 164 } 165 166 174 public boolean analyseEntryContext( EntryContext context ) { 175 176 if (_logger.isLoggable(Level.FINER)) { 177 _logger.log(Level.FINER, 178 "Analysing the context in EJB ServiceGroup :" + context); 179 } 180 181 boolean result = false; 182 try { 183 ConfigContext ctxt = context.getServerContext().getConfigContext(); 184 Config conf = ServerBeansFactory.getConfigBean( ctxt ); 185 186 if (context.getEntryPointType() == EntryPoint.STARTUP) { 189 boolean onDemandStartup = ((Boolean ) context.get()).booleanValue(); 190 if (onDemandStartup == false) { 191 result = true; 192 } 193 } else if (context.get() == null) { 194 return false; 195 } 196 197 if (context.getEntryPointType() == EntryPoint.APPLOADER ) { 202 Descriptor desc = (Descriptor) context.get(); 203 if (desc instanceof Application) { 204 Application app = (Application) desc; 205 if (app.getEjbComponentCount() > 0) { 206 result = true; 207 } else { 208 for (ConnectorDescriptor cd : 209 (java.util.Set <ConnectorDescriptor>) app.getRarDescriptors()) { 210 if (!ResourcesUtil.getInstance().belongToSystemRar(cd.getName())) { 211 String raClass = cd.getResourceAdapterClass(); 212 if (raClass != null && !raClass.trim().equals("")) { 213 result = true; 214 break; 215 } 216 } 217 } 218 } 219 } else if (desc instanceof ConnectorDescriptor ) { 220 ConnectorDescriptor cd = (ConnectorDescriptor) desc; 221 if (!ResourcesUtil.getInstance().belongToSystemRar(cd.getName())) { 222 String raClass = cd.getResourceAdapterClass(); 223 if (raClass != null && !raClass.trim().equals("")) { 224 result = true; 225 } 226 } 227 } else { 228 result = desc instanceof EjbBundleDescriptor || 229 desc instanceof EjbAbstractDescriptor; 230 } 231 } 232 233 if ( context.getEntryPointType() == EntryPoint.JNDI ) { 238 String jndiName = (String ) context.get(); 239 String JAVA = "java"; 240 String COMP = "comp"; 241 String ENV = "env"; 242 int minSize = (JAVA + ":" + COMP + "/" + ENV).length(); 243 244 String txMgr = javaURLContext.APPSERVER_TRANSACTION_MGR; 247 248 if (jndiName.equals(txMgr)) { 249 return true; 250 } 251 252 if (_logger.isLoggable(Level.FINER)) { 253 _logger.log(Level.FINER, "Jndi name being analysed is :" + jndiName); 254 } 255 256 if (jndiName.length() > minSize && jndiName.startsWith(JAVA)) { 257 jndiName = jndiName.substring(JAVA.length() + 1); 258 if (jndiName.startsWith(COMP)) { 259 jndiName = jndiName.substring(COMP.length() + 1); 260 if (jndiName.startsWith(ENV)) { 261 jndiName = jndiName.substring(ENV.length() + 1); 262 } 263 } 264 } 265 266 if (jndiName.equalsIgnoreCase(MEJB_JNDI_NAME)) { 267 result = true; 268 } else { 269 result = isXAResource(jndiName, ctxt); 270 } 271 } 272 273 if (context.getEntryPointType() == EntryPoint.MBEAN) { 276 result = analyseObjectName((ObjectName ) context.get()); 277 } 278 279 if ( context.getEntryPointType() == EntryPoint.PORT ) { 281 IiopService iiopService = conf.getIiopService(); 283 IiopListener[] iiopListeners = iiopService.getIiopListener(); 284 for ( int i=0; i<iiopListeners.length; i++ ) { 285 int port = Integer.parseInt(iiopListeners[i].getPort()); 286 if (port == ((Integer ) context.get()).intValue() ) { 287 result = true; 288 } 289 } 290 } 291 } catch (Exception e) { 292 e.printStackTrace(); 293 result = false; 294 } 295 return result; 296 } 297 298 private boolean isXAResource(String jndiName, ConfigContext conf) { 300 301 try { 302 ConfigBean res = ResourceHelper.findResource(conf, jndiName); 303 if (res != null) { 304 if(_logger.isLoggable(Level.FINE)) 305 _logger.log(Level.FINE,"Got the resource :" + res); 306 if (res instanceof JdbcResource) { 307 String poolName = ((JdbcResource) res).getPoolName(); 308 JdbcConnectionPool pool = 309 (JdbcConnectionPool) ResourceHelper.findResource(conf, poolName); 310 if(_logger.isLoggable(Level.FINE)) 311 _logger.log(Level.FINE,"Got the Pool :" + pool); 312 if (pool.getResType() != null && 313 pool.getResType().equals("javax.sql.XADataSource")) { 314 return true; 315 } else { 316 return false; 317 } 318 } 319 320 if (res instanceof ConnectorResource) { 321 String poolName = ((ConnectorResource) res).getPoolName(); 322 Resources root = ((Domain)conf.getRootConfigBean()).getResources(); 323 ConnectorConnectionPool pool = (ConnectorConnectionPool) 324 root. getConnectorConnectionPoolByName(poolName); 325 if(_logger.isLoggable(Level.FINE)) 326 _logger.log(Level.FINE,"Got the Pool :" + pool); 327 String txSupport = pool.getTransactionSupport(); 328 if (txSupport == null || 331 txSupport.trim().equals("") || 332 txSupport.trim().equals 333 (ConnectorRuntime.XA_TRANSACTION_TX_SUPPORT_STRING) ) { 334 return true; 335 } else { 336 return false; 337 } 338 } 339 } 340 } catch (Exception e) { 341 e.printStackTrace(); 342 return false; 343 } 344 345 return false; 346 347 } 348 349 private boolean analyseObjectName(ObjectName name) { 352 353 363 364 String nameStr = name.getKeyProperty("name"); 365 String ref = name.getKeyProperty("ref"); 366 String app = name.getKeyProperty("J2EEApplication"); 367 368 return belongsToThisServiceGroup(nameStr) || 369 belongsToThisServiceGroup(ref) || 370 belongsToThisServiceGroup(app); 371 372 } 373 374 private boolean belongsToThisServiceGroup(String name) { 375 SystemAppLoader appLoader = OnDemandServer.getSystemAppLoader(); 376 if (appLoader != null) { 377 for (Object n : appLoader.getEjbServiceGroupSystemApps()) { 378 if (((String ) n).equals(name)) { 379 return true; 380 } 381 } 382 } 383 return false; 384 } 385 386 private void startORB(String [] args) 388 { 389 try { 390 Properties jtsProperties ; 391 392 try { 394 Properties props = System.getProperties(); 396 397 props.setProperty(J2EE_APPNAME, "j2ee"); 400 401 jtsProperties = initJTSProperties(true); 405 406 orb = createORB(); 407 408 try { 411 org.omg.CORBA.Object obj = 412 orb.resolve_initial_references("RootPOA"); 413 } catch(org.omg.CORBA.ORBPackage.InvalidName in) { 414 _logger.log(Level.SEVERE,"enterprise.orb_reference_exception",in); 415 } 416 } catch ( Exception ex ) { 417 if(_logger.isLoggable(Level.SEVERE)) 418 _logger.log(Level.SEVERE,"enterprise.createorb_exception",ex.toString()); 419 if ( debug ) 420 _logger.log(Level.FINEST,"Exception while creating ORB: ",ex); 421 throw new RuntimeException ("Unable to create ORB"); 422 } 423 424 if (Switch.getSwitch().getContainerType() == Switch.EJBWEB_CONTAINER) { 427 new ORBMonitoring( orb ); 428 } 429 430 Switch theSwitch = Switch.getSwitch(); 431 432 protocolMgr = new com.sun.enterprise.iiop.POAProtocolMgr(orb); 434 theSwitch.setProtocolManager(protocolMgr); 435 436 protocolMgr.initializeNaming(repositoryDir, orbInitialPort); 437 ((POAProtocolMgr)protocolMgr).initializePOAs(); 438 439 if(_logger.isLoggable(Level.FINE)) 440 _logger.log(Level.FINE,localStrings.getLocalString("j2ee.naming", 441 "Naming service started: ") + orbInitialPort); 442 444 try { 445 Switch.getSwitch().getProviderManager().initRemoteProvider(); 446 } catch (RemoteException re) { 447 _logger.log(Level.WARNING, "init.remote.provider", re); 448 } 449 450 PEORBConfigurator.initTransactionService( 452 "com.sun.jts.CosTransactions.DefaultTransactionService", jtsProperties ); 453 454 } catch (Exception ex) { 455 if(_logger.isLoggable(Level.SEVERE)) 456 _logger.log(Level.SEVERE,"enterprise.j2eeservice_running_exception",ex.toString()); 457 if ( debug ) 458 _logger.log(Level.FINEST,"Exception running j2ee services",ex); 459 Log.err.flush(); 460 throw new RuntimeException (ex.getMessage(), ex); 461 } 462 } 463 464 467 private ORB createORB() 468 throws Exception 469 { 470 ORB orb = ORBManager.getORB() ; 471 472 orbInitialPort = ORBManager.getORBInitialPort(); 474 475 if(_logger.isLoggable(Level.FINE)) 476 _logger.log(Level.FINE,localStrings.getLocalString( 477 "j2ee.listenPort","J2EE server listen port: " ) + orbInitialPort); 478 479 return orb ; 480 } 481 482 487 public static Properties initJTSProperties(boolean lateRegistration) 488 { 489 Properties props = new Properties () ; 490 491 if (!lateRegistration) { 492 props.put("com.sun.corba.ee.CosTransactions.ORBJTSClass", 493 "com.sun.jts.CosTransactions.DefaultTransactionService"); 494 } 495 496 com.sun.jts.CosTransactions.Configuration.setAsAppClientConatiner(false); 497 ConfigContext ctx = 501 ApplicationServer.getServerContext().getConfigContext(); 502 TransactionService txnService = null; 503 try{ 504 txnService = 505 ServerBeansFactory.getTransactionServiceBean(ctx); 506 props.put(com.sun.jts.CosTransactions.Configuration.HEURISTIC_DIRECTION, 509 txnService.getHeuristicDecision()); 510 props.put(com.sun.jts.CosTransactions.Configuration.KEYPOINT_COUNT, 511 txnService.getKeypointInterval()); 512 513 if (txnService.isAutomaticRecovery()) { 514 if(debug) { 515 _logger.log(Level.FINE,"Recoverable J2EE Server"); 516 } 517 props.put(com.sun.jts.CosTransactions.Configuration.MANUAL_RECOVERY, 518 "true"); 519 } 520 521 boolean disable_distributed_transaction_logging = false; 522 String dbLoggingResource = null ; 523 ElementProperty[] eprops = txnService.getElementProperty(); 524 for (int index = 0; index < eprops.length; index++) { 525 if ("disable-distributed-transaction-logging".equals(eprops[index].getName())) { 526 if (!("true".equals(eprops[index].getValue()))) 527 disable_distributed_transaction_logging = false; 528 else 529 disable_distributed_transaction_logging = true; 530 } else if("xaresource-txn-timeout".equals(eprops[index].getName())){ 531 String value = eprops[index].getValue(); 532 _logger.log(Level.FINE,"XAResource transaction timeout is"+value); 533 if (value != null) { 534 com.sun.jts.jta.TransactionManagerImpl.setXAResourceTimeOut( 535 Integer.parseInt(value)); 536 } 537 } else if ("db-logging-resource".equals(eprops[index].getName())) { 538 dbLoggingResource = eprops[index].getValue(); 539 _logger.log(Level.FINE,"Transaction DB Logging Resource Name" + dbLoggingResource); 540 if (dbLoggingResource == null || " ".equals(dbLoggingResource)) { 541 dbLoggingResource = "jdbc/TxnDS"; 542 } 543 } 544 } 545 if (dbLoggingResource != null) { 546 disable_distributed_transaction_logging = true; 547 props.put(com.sun.jts.CosTransactions.Configuration.DB_LOG_RESOURCE, 548 dbLoggingResource); 549 } 550 551 557 String jtsServerId = 558 String.valueOf(DEFAULT_SERVER_ID); IiopService iiopServiceBean = 560 ServerBeansFactory.getIiopServiceBean(ctx); 561 if (iiopServiceBean != null) { 562 IiopListener iiopListener = iiopServiceBean.getIiopListener(0); 563 if (iiopListener != null) { 564 jtsServerId = iiopListener.getPort(); 565 } 566 } 567 props.put(JTS_SERVER_ID,jtsServerId); 568 569 574 575 580 String serverId = String.valueOf(DEFAULT_SERVER_ID); 581 System.setProperty(J2EE_SERVER_ID_PROP, serverId); 582 583 if (_logger.isLoggable(Level.FINE)) { 584 _logger.log(Level.FINE, 585 "++++ Server id: " 586 + props.getProperty(ORBConstants.SERVER_ID_PROPERTY)); 587 } 588 589 596 if (!txnService.isAutomaticRecovery() && disable_distributed_transaction_logging) { 597 com.sun.jts.CosTransactions.Configuration.disableFileLogging(); 598 } 599 if (dbLoggingResource == null) { 600 String logdir=txnService.getTxLogDir(); 601 if(logdir==null){ 602 Domain svr = null; 603 svr = ServerBeansFactory.getDomainBean(ctx); 604 logdir = svr.getLogRoot(); 605 if(logdir == null){ 606 logdir = FileUtil.getAbsolutePath(".."+File.separator+"logs"); 607 } 608 } else if( ! (new File(logdir)).isAbsolute()) { 609 if(_logger.isLoggable(Level.FINE)) 610 _logger.log(Level.FINE,"enterprise.relative_tx_log_dir" , logdir); 611 Domain svr = null; 612 svr = ServerBeansFactory.getDomainBean(ctx); 613 String logroot=svr.getLogRoot(); 614 if(logroot != null){ 615 logdir = logroot + File.separator + logdir; 616 } else { 617 logdir = FileUtil.getAbsolutePath(".."+File.separator+"logs" 618 +File.separator+logdir); 619 } 620 } 621 String instanceName = ApplicationServer.getServerContext().getInstanceName(); 622 logdir += File.separator + instanceName + File.separator+"tx"; 623 624 if (debug) { 625 _logger.log(Level.FINE,"JTS log directory: " + logdir); 626 _logger.log(Level.FINE,"JTS Server id " + jtsServerId); 627 } 628 (new File(logdir)).mkdirs(); 629 props.put(com.sun.jts.CosTransactions.Configuration.LOG_DIRECTORY, 630 logdir); 631 } 632 props.put(com.sun.jts.CosTransactions.Configuration.COMMIT_RETRY, 633 txnService.getRetryTimeoutInSeconds()); 634 635 } catch(ConfigException e){ 636 throw new RuntimeException ("Error reading configuration : "+e); 637 } 638 com.sun.jts.CosTransactions.Configuration.setProperties(props); 639 return props ; 640 } 641 } 642 643 | Popular Tags |