1 23 24 package com.sun.enterprise.management.util; 25 26 import com.sun.enterprise.ManagementObjectManager; 27 import com.sun.enterprise.admin.common.MBeanServerFactory; 28 import com.sun.enterprise.admin.meta.MBeanRegistry; 29 import com.sun.enterprise.admin.meta.MBeanRegistryFactory; 30 import com.sun.enterprise.admin.server.core.AdminService; 31 32 import com.sun.enterprise.deployment.*; 33 import com.sun.enterprise.deployment.Application; 34 import com.sun.enterprise.deployment.ApplicationClientDescriptor; 35 import com.sun.enterprise.deployment.WebServiceEndpoint; 36 import com.sun.enterprise.deployment.WebServicesDescriptor; 37 import com.sun.enterprise.deployment.BundleDescriptor; 38 import com.sun.enterprise.deployment.util.ModuleDescriptor; 39 import com.sun.enterprise.deployment.ConnectorDescriptor; 40 import com.sun.enterprise.deployment.EjbBundleDescriptor; 41 import com.sun.enterprise.deployment.EjbDescriptor; 42 import com.sun.enterprise.deployment.EjbSessionDescriptor; 43 import com.sun.enterprise.deployment.WebBundleDescriptor; 44 import com.sun.enterprise.deployment.WebComponentDescriptor; 45 import com.sun.enterprise.deployment.io.AppClientDeploymentDescriptorFile; 46 import com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile; 47 import com.sun.enterprise.deployment.io.ConnectorDeploymentDescriptorFile; 48 import com.sun.enterprise.deployment.io.EjbDeploymentDescriptorFile; 49 import com.sun.enterprise.deployment.io.WebDeploymentDescriptorFile; 50 import com.sun.enterprise.deployment.node.J2EEDocumentBuilder; 51 import com.sun.enterprise.management.agent.MEJB; 52 import com.sun.enterprise.management.agent.MEJBUtility; 53 import com.sun.enterprise.management.model.*; 54 import com.sun.enterprise.management.util.J2EEModuleCallBack; 56 import com.sun.enterprise.server.*; 57 import com.sun.enterprise.server.ApplicationServer; 58 import com.sun.jmx.trace.Trace; 59 import java.io.File ; 62 import java.lang.reflect.Method ; 63 import java.lang.reflect.Constructor ; 64 import java.rmi.RemoteException ; 65 import java.security.AccessController ; 66 import java.security.PrivilegedAction ; 67 import java.util.*; 68 import java.util.logging.*; 69 import javax.management.*; 70 import javax.management.modelmbean.ModelMBean ; 71 import javax.naming.*; 72 import javax.rmi.PortableRemoteObject ; 73 import com.sun.enterprise.instance.*; 74 import com.sun.enterprise.deployment.io.DescriptorConstants; 75 import java.io.*; 76 import com.sun.enterprise.config.ConfigException; 77 import com.sun.enterprise.util.io.FileUtils; 78 79 import java.util.logging.Level ; 80 import java.util.logging.Logger ; 81 import com.sun.enterprise.admin.common.constant.AdminConstants; 82 import com.sun.enterprise.config.ConfigContext; 83 import com.sun.enterprise.config.serverbeans.Server; 84 import com.sun.enterprise.config.serverbeans.ServerHelper; 85 import com.sun.enterprise.management.j2ee.DASJ2EEServerImpl; 86 import com.sun.enterprise.admin.mbeans.DomainStatus; 87 import com.sun.enterprise.admin.mbeans.DomainStatusHelper; 88 import com.sun.enterprise.admin.mbeans.DomainStatusMBean; 89 import com.sun.appserv.management.j2ee.StateManageable; 90 91 import com.sun.enterprise.management.support.LoaderMBean; 92 import com.sun.appserv.management.base.Util; 93 import com.sun.appserv.management.util.misc.SetUtil; 94 95 96 98 import com.sun.enterprise.config.serverbeans.Cluster; 99 import com.sun.enterprise.config.serverbeans.ClusterHelper; 100 import com.sun.appserv.management.base.AMX; 101 import com.sun.appserv.management.base.Util; 102 import com.sun.appserv.management.j2ee.J2EEDomain; 103 import com.sun.appserv.management.j2ee.J2EECluster; 104 import com.sun.appserv.management.client.ProxyFactory; 105 import com.sun.enterprise.management.support.BootUtil; 106 import com.sun.enterprise.management.support.ObjectNames; 107 import com.sun.enterprise.management.j2ee.J2EEClusterImpl; 108 import com.sun.appserv.management.util.jmx.MBeanServerConnectionSource; 109 import com.sun.appserv.management.util.jmx.JMXUtil; 110 import com.sun.enterprise.management.support.WebModuleSupport; 111 112 127 128 public class J2EEManagementObjectManager implements ManagementObjectManager { 129 130 private MEJB mejbRef = null; 131 private MEJBUtility mejbUtility = null; 132 private static MBeanServer server = null; 133 private static String domain = J2EEDomainMdl.DOMAINNAME; 134 private static final String QUEUE = "javax.jms.Queue"; 136 private static final String TOPIC = "javax.jms.Topic"; 137 private static final String DEFAULT_VIRTUAL_SERVER = "server"; 138 139 private static Logger _logger = Logger.getLogger(AdminConstants.kLoggerName); 140 141 142 144 145 static { 146 if (server == null) { 147 initMBeanServer(); 148 } 149 if ((server != null)) { 150 registerHTMLAdaptor(); 151 } 152 } 153 154 public J2EEManagementObjectManager() { 155 156 } 165 166 167 private static void initMBeanServer() { 168 169 try { 171 server = MBeanServerFactory.getMBeanServer(); 172 } catch (Exception e) { 173 e.printStackTrace(); 174 } 175 } 176 177 181 private static boolean _bHtmlAdaptorServerRegistered = false; 182 private static void registerHTMLAdaptor() { 183 184 if(_bHtmlAdaptorServerRegistered) 185 return; 186 try { 187 String strPort = System.getProperty("html.adaptor.port"); 188 if(strPort==null || strPort.trim().length()<1) 189 return; 190 int port = (new Integer (strPort.trim())).intValue(); 192 Class cl = Class.forName("com.sun.jdmk.comm.HtmlAdaptorServer"); 193 Constructor contr = cl.getConstructor(new Class []{Integer.TYPE}); 194 Object adaptor = contr.newInstance(new Object []{new Integer (port)}); 195 Method method = cl.getMethod("start"); 196 ObjectName htmlAdaptorObjectName = new ObjectName( 197 "Adaptor:name=html,port="+port); 198 server.registerMBean(adaptor, htmlAdaptorObjectName); 199 method.invoke(adaptor); 200 _bHtmlAdaptorServerRegistered = true; 201 } catch (Exception e) { 202 e.printStackTrace(); 203 } 204 205 } 206 207 public MEJBUtility getMEJBUtility(){ 208 if(this.mejbUtility == null){ 209 this.mejbUtility = MEJBUtility.getMEJBUtility(); 210 } 211 return this.mejbUtility; 212 } 213 214 public void registerJ2EEDomain() { 215 instantiateAndRegisterRuntimeMBean("J2EEDomain", null); 216 registerDomainStatusMBean(); 217 } 218 219 public void registerJ2EEServer() { 220 J2EEServerMdl managedServerMdlObject = new J2EEServerMdl( 221 ApplicationServer.getServerContext().getInstanceName(), 222 com.sun.appserv.server.util.Version.getVersion()); 223 instantiateAndRegisterRuntimeMBean("J2EEServer", managedServerMdlObject); 224 } 225 226 public void registerJCAConnectionFactory(String jcaResName, 227 String jcaConnFactName, String managedConFact) 228 { 229 Object managedBean = (Object )new JCAConnectionFactoryMdl( 230 jcaResName, ApplicationServer.getServerContext().getInstanceName(), 231 jcaConnFactName, managedConFact); 232 instantiateAndRegisterRuntimeMBean("JCAConnectionFactory", managedBean, jcaResName, jcaConnFactName); 233 } 234 235 public void registerJCAManagedConnectionFactory(String connFactName) { 236 Object managedBean = (Object )new JCAManagedConnectionFactoryMdl( 237 connFactName, ApplicationServer.getServerContext().getInstanceName()); 238 instantiateAndRegisterRuntimeMBean("JCAManagedConnectionFactory", managedBean, connFactName); 239 } 240 241 public void registerJCAResource(String name, String raName, 242 String username, String password, 243 String [] propNames, String [] propValues) { 244 Object managedBean = (Object )new JCAResourceMdl(name, 245 ApplicationServer.getServerContext().getInstanceName(), 246 raName, username, password, propNames, propValues); 247 instantiateAndRegisterRuntimeMBean("JCAResource", managedBean, raName, name); 248 249 } 250 251 public void registerAdminObjectResource(String name, String raName, String resType, 252 String [] propNames, String [] propValues) { 253 if(QUEUE.equals(resType) || TOPIC.equals(resType)) { 255 registerJMSResource(name, resType, null, null, propNames, propValues); 256 } 257 } 258 259 public void registerJDBCDataSource(String dsJndiName, String dsName, String url, 260 String username, 261 String password, 262 String [] propNames, 263 String [] propValues) { 264 Object managedBean = (Object )new JDBCDataSourceMdl(dsJndiName, dsName, url, 265 username, 266 ApplicationServer.getServerContext().getInstanceName(), 267 password, 268 propNames, 269 propValues); 270 instantiateAndRegisterRuntimeMBean("JDBCDataSource", managedBean, dsJndiName, dsJndiName); } 272 273 public void registerJDBCDriver(String name) { 274 instantiateAndRegisterRuntimeMBean("JDBCDriver", null, name); 275 } 276 277 public void registerJDBCResource(String name) { 278 instantiateAndRegisterRuntimeMBean("JDBCResource", null, name); 279 } 280 281 282 public void registerJMSResource(String name, String resType, 283 String username, String password, 284 String [] propNames, String [] propValues) { 285 Object managedBean = (Object )new JMSResourceMdl(name, 286 ApplicationServer.getServerContext().getInstanceName(), 287 resType, username, password, propNames, propValues); 288 instantiateAndRegisterRuntimeMBean("JMSResource", managedBean, name); 289 } 290 291 public void registerJNDIResource(String name) { 292 instantiateAndRegisterRuntimeMBean("JNDIResource", null, name); 293 } 294 295 public void registerJTAResource(String name) { 296 instantiateAndRegisterRuntimeMBean("JTAResource", null, name); 297 } 298 299 public void registerJVM() { 300 instantiateAndRegisterRuntimeMBean("JVM", null, 303 getJVMId()); 304 } 305 306 public void registerJavaMailResource(String name) { 307 instantiateAndRegisterRuntimeMBean("JavaMailResource", null, name); 308 } 309 310 311 public void registerRMI_IIOPResource(String name) { 312 instantiateAndRegisterRuntimeMBean("RMI_IIOPResource", null, name); 313 } 314 315 MEJB getMEJB() throws Exception { 316 if ( mejbRef == null ) { 317 InitialContext ic = new InitialContext(); 318 java.lang.Object objref = ic.lookup( 319 System.getProperty("mejb.name","ejb/mgmt/MEJB")); 320 } 321 return mejbRef; 322 } 323 324 public void unregisterStandAloneModule(String moduleType, String name) { 325 try { 326 unregisterStandAloneAndItsComponents(moduleType, name); 327 } catch ( Exception ex ) { 328 throw new RuntimeException (ex); 329 } 330 } 331 332 private void unregisterStandAloneAndItsComponents( 333 String moduleType, String moduleName)throws Exception { 334 } 335 336 public void unregisterJCAResource(String moduleName)throws Exception { 337 } 338 339 343 public void unregisterAdminObjectResource( 344 String name, String resourceType) throws Exception { 345 if(QUEUE.equals(resourceType) || TOPIC.equals(resourceType)) { 346 unregisterResource(name,"JMSResource"); 347 } 348 } 349 350 public void unregisterJMSResource(String name) throws Exception { 351 unregisterResource(name,"JMSResource"); 352 } 353 354 public void unregisterJavaMailResource(String name) throws Exception { 355 unregisterResource(name,"JavaMailResource"); 356 } 357 358 public void unregisterJDBCResource(String name) throws Exception { 359 unregisterResource(name,"JDBCResource"); 360 } 361 362 363 371 void unregisterResource(String name, String type) throws Exception { 372 final MBeanRegistry registry = 373 MBeanRegistryFactory.getRuntimeMBeanRegistry(); 374 final String domainName = 375 ApplicationServer.getServerContext().getDefaultDomainName(); 376 final String serverName = 377 ApplicationServer.getServerContext().getInstanceName(); 378 final String [] location = new String [] {domainName, serverName, name}; 379 final ObjectName on = registry.getMbeanObjectName(type, location); 380 if (on == null) { 381 return; 382 } 383 final MBeanServer mbs = 384 AdminService.getAdminService().getAdminContext().getMBeanServer(); 385 if (mbs.isRegistered(on)) { 386 mbs.unregisterMBean(on); 387 } 388 } 389 390 391 public Object getModuleUserData( 392 String moduleID, int moduleType) throws Exception { 393 return null; 394 } 395 396 public void setModuleUserData( 397 String moduleID, Object obj, int moduleType)throws Exception { 398 } 399 400 private ObjectName getManagedObjectModule( 401 String moduleID, int moduleType) throws Exception { 402 403 return null; 404 } 405 406 407 408 public void registerConfigJ2EEServer(String instance) { 411 throw new RuntimeException (">>>>>>>>>>>>>>>>>>>> registerConfigJ2EEServer not implemented <<<<<<<<<<<<<<<<<"); 412 } 414 415 416 418 private void instantiateAndRegisterRuntimeMBean(String type, Object managed) 419 { 420 instantiateAndRegisterRuntimeMBean(type, managed, null, null, null); 421 } 422 423 424 private void instantiateAndRegisterRuntimeMBean( 426 String type, Object managed, String name) 427 { 428 instantiateAndRegisterRuntimeMBean(type, managed, null, null, name); 429 } 430 431 private void instantiateAndRegisterRuntimeMBean( 433 String type, Object managed, String parentName, String name) 434 { 435 instantiateAndRegisterRuntimeMBean(type, managed, null, parentName, name); 436 } 437 438 439 441 private void instantiateAndRegisterRuntimeMBean( 442 String type, Object managed, String grandParentName, 443 String parentName, String name) { 444 445 MBeanRegistry registry = MBeanRegistryFactory.getRuntimeMBeanRegistry(); 446 String domainName = ApplicationServer.getServerContext().getDefaultDomainName(); 447 String serverName = ApplicationServer.getServerContext().getInstanceName(); 448 449 try { 450 if(grandParentName!=null) { 451 452 registry.instantiateMBean( 453 type, 454 new String []{domainName, serverName, grandParentName, 455 parentName, name}, 456 managed, AdminService.getAdminService().getAdminContext().getAdminConfigContext(), true); } else { 458 if(parentName!=null) { 459 registry.instantiateMBean( 460 type, 461 new String []{domainName, serverName, 462 parentName, name}, 463 managed, AdminService.getAdminService().getAdminContext().getAdminConfigContext(), true); } else { 465 if(name!=null) { 466 registry.instantiateMBean( 467 type, new String []{domainName, serverName,name}, 468 managed, AdminService.getAdminService().getAdminContext().getAdminConfigContext(), true); } else { 470 registry.instantiateMBean( 471 type, new String []{domainName, serverName}, 472 managed, AdminService.getAdminService().getAdminContext().getAdminConfigContext(), true); } 474 } 475 } 476 } catch (Exception e) { 477 System.out.println("Exception msg:"+e.getMessage()); 478 e.printStackTrace(); 479 } 480 } 481 482 484 485 public void createAppMBean(Application application, String serverName, 486 String appLocation) 487 throws MBeanException { 488 489 String xmlDesc = null; 491 492 String j2eeDDLocation = application.getGeneratedXMLDirectory() + 493 File.separator + 494 DescriptorConstants.APPLICATION_DD_ENTRY; 495 496 xmlDesc = getStringForDDxml(j2eeDDLocation); 498 499 StartStopCallback sscb = new StartStopCallback(); 500 501 J2EEModuleCallBackImpl module = new J2EEModuleCallBackImpl( 502 application.getRegistrationName(), 503 application.getRegistrationName(), serverName, xmlDesc, sscb); 504 505 J2EEApplicationMdl managedResource = new J2EEApplicationMdl(module, application); 506 instantiateAndRegisterRuntimeMBean( "J2EEApplication", managedResource, 507 application.getRegistrationName()); 508 509 } 510 511 512 public void deleteAppMBean(Application application, String serverName) 513 throws MBeanException { 514 515 try { 516 String namePattern = 517 (domain + ":" + 518 "j2eeType=J2EEApplication" + "," + 519 "name=" + application.getRegistrationName() + "," + 520 "J2EEServer=" + serverName + "," + 521 "*"); 522 523 ObjectName objName = findObjectName(namePattern); 524 525 if (objName != null) { 526 unregister(objName); 527 } 528 } catch (Exception e) { 529 throw new MBeanException(e); 530 } 531 } 532 533 538 public void createAppMBeanModules(Application application, 539 String serverName, String appLocation) throws MBeanException { 540 541 boolean registerComponents = false; 542 543 java.util.Set ejbBundles = application.getEjbBundleDescriptors(); 545 546 for (Iterator it = ejbBundles.iterator(); it.hasNext();) { 547 EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor) it.next(); 548 registerEjbModuleAndItsComponents(bundleDesc, serverName, 549 registerComponents, appLocation); 550 } 551 552 564 565 java.util.Set rarBundles = application.getRarDescriptors(); 567 568 for (Iterator it = rarBundles.iterator(); it.hasNext();) { 569 ConnectorDescriptor bundleDesc = (ConnectorDescriptor) it.next(); 570 registerResourceAdapterModuleAndItsComponents(bundleDesc, 571 serverName, registerComponents, appLocation); 572 } 573 574 java.util.Set appClientBundles = application.getApplicationClientDescriptors(); 576 577 for (Iterator it = appClientBundles.iterator(); it.hasNext();) { 578 ApplicationClientDescriptor bundleDesc = (ApplicationClientDescriptor) it.next(); 579 registerAppClient(bundleDesc, serverName, appLocation); 580 } 581 } 582 583 587 public void createAppMBeans(Application application, 588 String serverName, String appLocation) throws MBeanException { 589 590 boolean registerComponents = true; 591 592 java.util.Set ejbBundles = application.getEjbBundleDescriptors(); 594 595 for (Iterator it = ejbBundles.iterator(); it.hasNext();) { 596 EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor) it.next(); 597 registerEjbModuleAndItsComponents(bundleDesc, serverName, 598 registerComponents, appLocation); 599 } 600 601 613 614 java.util.Set rarBundles = application.getRarDescriptors(); 616 617 for (Iterator it = rarBundles.iterator(); it.hasNext();) { 618 ConnectorDescriptor bundleDesc = (ConnectorDescriptor) it.next(); 619 registerResourceAdapterModuleAndItsComponents(bundleDesc, 620 serverName, registerComponents, appLocation); 621 } 622 623 java.util.Set appClientBundles = application.getApplicationClientDescriptors(); 625 626 for (Iterator it = appClientBundles.iterator(); it.hasNext();) { 627 ApplicationClientDescriptor bundleDesc = (ApplicationClientDescriptor) it.next(); 628 registerAppClient(bundleDesc, serverName, appLocation); 629 } 630 } 631 632 633 public void registerEjbModuleAndItsComponents( 634 EjbBundleDescriptor ejbBundleDescriptor, String serverName, 635 boolean registerComponents, String appLocation) throws MBeanException { 636 637 638 createEJBModuleMBean(ejbBundleDescriptor, serverName, appLocation); 639 640 if (registerComponents) { 641 createEJBMBeans(ejbBundleDescriptor, serverName); 642 } 643 } 644 645 646 public void registerWebModuleAndItsComponents( 647 WebBundleDescriptor webBundleDescriptor, String serverName, 648 boolean registerComponents, String appLocation) throws MBeanException { 649 650 String xmlDesc = getStringForDDxml( 652 getModuleLocation(webBundleDescriptor, "WebModule")); 653 654 String applicationName = "null"; 655 656 if (webBundleDescriptor.getApplication() != null) { 657 if (!webBundleDescriptor.getModuleDescriptor().isStandalone()) { 658 applicationName = webBundleDescriptor.getApplication() 659 .getRegistrationName(); 660 661 if (applicationName == null) { 662 applicationName = "null"; 663 } 664 } 665 } 666 667 createWebModuleMBean(webBundleDescriptor.getModuleID(), 668 applicationName, serverName, xmlDesc); 669 670 if (registerComponents) { 671 createWebMBeans(webBundleDescriptor, serverName); 672 } 673 try { 674 createWSEndpointMBeans(webBundleDescriptor, serverName); 675 } catch (MBeanException mbe) { 676 _logger.log(Level.WARNING, 677 "admin.registerWebModuleAndItsComponents exception", mbe); 678 } 679 } 680 681 682 public void registerResourceAdapterModuleAndItsComponents( 683 ConnectorDescriptor bundleDesc, String serverName, 684 boolean registerComponents, String appLocation) throws MBeanException { 685 686 687 688 createRARModuleMBean(bundleDesc, serverName, appLocation); 689 690 if (registerComponents) { 691 createRARMBeans(bundleDesc, serverName); 692 } 693 } 694 695 696 public void registerAppClient( 697 ApplicationClientDescriptor bundleDesc, String serverName, 698 String appLocation) 699 throws MBeanException { 700 701 String xmlDesc = getStringForDDxml( 703 getModuleLocation(bundleDesc, "AppClientModule")); 704 705 String applicationName = "null"; 706 707 if (bundleDesc.getApplication() != null) { 708 if (!bundleDesc.getModuleDescriptor().isStandalone()) { 709 applicationName = bundleDesc.getApplication() 710 .getRegistrationName(); 711 712 if (applicationName == null) { 713 applicationName = "null"; 714 } 715 } 716 } 717 718 createAppClientModuleMBean(getModuleName(bundleDesc), applicationName, 719 serverName, xmlDesc); 720 } 721 722 723 public void unregisterAppClient( 724 ApplicationClientDescriptor bundleDesc, String serverName) 725 throws MBeanException { 726 727 String applicationName = "null"; 728 729 if (bundleDesc.getApplication() != null) { 730 if (!bundleDesc.getModuleDescriptor().isStandalone()) { 731 applicationName = bundleDesc.getApplication() 732 .getRegistrationName(); 733 734 if (applicationName == null) { 735 applicationName = "null"; 736 } 737 } 738 } 739 740 deleteAppClientModuleMBean(getModuleName(bundleDesc), applicationName, 741 serverName); 742 } 743 744 745 746 public void deleteAppMBeans(Application application, 747 String serverName) throws MBeanException { 748 749 try { 750 String namePattern = 751 (domain + ":" + 752 "j2eeType=J2EEApplication" + "," + 753 "name=" + application.getRegistrationName() + "," + 754 "J2EEServer=" + serverName + "," + 755 "*"); 756 757 ObjectName objName = findObjectName(namePattern); 758 759 if (objName != null) { 760 String [] modulesArr = (String []) server.getAttribute(objName, 761 "modules"); 762 ObjectName[] deployedModules = toObjectNameArray(modulesArr); 763 764 for (int moduleIndex = 0; moduleIndex < deployedModules.length; 765 moduleIndex++) { 766 unregisterModuleAndItsComponents(deployedModules[moduleIndex]); 767 } 768 } 769 } catch (Exception e) { 770 throw new MBeanException(e); 771 } 772 } 773 774 775 public void unregisterModuleAndItsComponents(ObjectName objectName) 776 throws MBeanException { 777 778 ObjectName[] comps = getComponents(objectName); 780 781 for (int compsIndex = 0; compsIndex < comps.length; compsIndex++) { 782 unregister(comps[compsIndex]); 783 } 784 785 unregister(objectName); 787 } 788 789 790 private ObjectName[] getComponents(ObjectName module) 791 throws MBeanException { 792 793 ObjectName[] components = null; 794 795 try { 796 if (module.getKeyProperty("j2eeType").equals("AppClientModule")) { 797 components = new ObjectName[] { }; 799 } else if (module.getKeyProperty("j2eeType").equals("EJBModule")) { 800 components = toObjectNameArray((String []) server.getAttribute( 801 module, "ejbs")); 802 } else if (module.getKeyProperty("j2eeType").equals("WebModule")) { 803 components = toObjectNameArray((String []) server.getAttribute( 804 module, "servlets")); 805 } else if (module.getKeyProperty("j2eeType").equals("ResourceAdapterModule")) { 806 components = toObjectNameArray((String []) server.getAttribute( 807 module, "resourceAdapters")); 808 } 809 } catch (Exception e) { 810 throw new MBeanException(e); 811 } 812 813 return components; 814 } 815 816 817 public void createEJBModuleMBean(EjbBundleDescriptor ejbBundleDescriptor, 818 String serverName, String appLocation) throws MBeanException { 819 820 821 String xmlDesc = getStringForDDxml( 823 getModuleLocation(ejbBundleDescriptor, "EJBModule")); 824 825 String moduleName = getModuleName(ejbBundleDescriptor); 826 String applicationName = getApplicationName(ejbBundleDescriptor); 827 828 StartStopCallback sscb = new StartStopCallback(); 829 J2EEModuleCallBackImpl module = new J2EEModuleCallBackImpl(moduleName, 830 applicationName, serverName, xmlDesc, sscb); 831 832 EJBModuleMdl managedResource = new EJBModuleMdl(module, ejbBundleDescriptor); 833 834 instantiateAndRegisterRuntimeMBean( "EJBModule", managedResource, 835 null, applicationName, moduleName); 836 try { 837 createWSEndpointMBeans(ejbBundleDescriptor, serverName); 838 } catch (MBeanException mbe) { 839 _logger.log(Level.WARNING, 840 "admin.registerEjbModuleAndItsComponents exception", mbe); 841 } 842 } 843 844 845 public void deleteEJBModuleMBean(EjbBundleDescriptor ejbBundleDescriptor, 846 String serverName) throws MBeanException { 847 848 849 String moduleName = getModuleName(ejbBundleDescriptor); 850 String applicationName = getApplicationName(ejbBundleDescriptor); 851 852 try { 853 String namePattern = 854 (domain + ":" + 855 "j2eeType=EJBModule" + "," + 856 "name=" + moduleName + "," + 857 "J2EEApplication=" + applicationName + "," + 858 "J2EEServer=" + serverName + "," + 859 "*"); 860 861 ObjectName objName = findObjectName(namePattern); 862 863 if (objName != null) { 864 unregister(objName); 865 } 866 } catch (Exception e) { 867 throw new MBeanException(e); 868 } 869 } 870 871 872 public void createEJBMBeans( 873 EjbBundleDescriptor ejbBundleDescriptor, String serverName) 874 throws MBeanException { 875 876 877 java.util.Set ejbs = ejbBundleDescriptor.getEjbs(); 879 880 for (Iterator it = ejbs.iterator(); it.hasNext();) { 881 EjbDescriptor nextDescriptor = (EjbDescriptor) it.next(); 882 883 createEJBMBean(nextDescriptor, serverName); 884 } 885 } 886 887 888 public void deleteEJBMBeans( 889 EjbBundleDescriptor ejbBundleDescriptor, String serverName) 890 throws MBeanException { 891 892 893 java.util.Set ejbs = ejbBundleDescriptor.getEjbs(); 894 895 for (Iterator it = ejbs.iterator(); it.hasNext();) { 896 897 EjbDescriptor nextDescriptor = (EjbDescriptor) it.next(); 898 899 deleteEJBMBean(nextDescriptor, serverName); 900 } 901 902 } 903 904 913 public void createWSEndpointMBeans( 914 BundleDescriptor bundleDescriptor, String serverName) 915 throws MBeanException { 916 917 if ( bundleDescriptor == null) { 918 return; 919 } 920 921 String ctxRoot = null; 922 if ( bundleDescriptor instanceof WebBundleDescriptor) { 923 ctxRoot = ((WebBundleDescriptor) bundleDescriptor).getContextRoot(); 924 } 925 926 WebServicesDescriptor wss = bundleDescriptor.getWebServices(); 927 if ( wss != null) { 928 java.util.Collection wsEps = wss.getEndpoints(); 929 930 for (Iterator it = wsEps.iterator(); it.hasNext();) { 931 WebServiceEndpoint nextDescriptor = 932 (WebServiceEndpoint) it.next(); 933 934 createWSEndpointMBean(ctxRoot, nextDescriptor, serverName); 935 } 936 } 937 } 938 939 948 public void deleteWSEndpointMBeans( 949 BundleDescriptor bundleDescriptor, String serverName) 950 throws MBeanException { 951 952 if ( bundleDescriptor == null) { 953 return; 954 } 955 956 String ctxRoot = null; 957 if ( bundleDescriptor instanceof WebBundleDescriptor) { 958 ctxRoot = ((WebBundleDescriptor) bundleDescriptor).getContextRoot(); 959 } 960 961 WebServicesDescriptor wsd = bundleDescriptor.getWebServices(); 962 if ( wsd == null) { 963 return; 964 } 965 966 java.util.Collection wsEps = wsd.getEndpoints(); 967 968 for (Iterator it = wsEps.iterator(); it.hasNext();) { 969 WebServiceEndpoint nextDescriptor = (WebServiceEndpoint) it.next(); 970 971 try { 972 deleteWSEndpointMBean(ctxRoot, nextDescriptor, serverName); 973 } catch (MBeanException mbe) { 974 _logger.log(Level.WARNING, 975 "admin.deleteEJBMBeans exception", mbe); 976 } 977 } 978 979 980 } 981 982 983 public void createEJBMBean(EjbDescriptor ejbDescriptor, String serverName) 984 throws MBeanException { 985 986 987 String ejbName = ejbDescriptor.getName(); 988 String ejbType = ejbDescriptor.getType(); 989 String ejbSessionType = null; 990 if (ejbType.equals("Session")) { 991 ejbSessionType = ((EjbSessionDescriptor) ejbDescriptor).getSessionType(); 992 } 993 994 String moduleName = getModuleName(ejbDescriptor.getEjbBundleDescriptor()); 995 String appName = getApplicationName(ejbDescriptor.getEjbBundleDescriptor()); 996 997 Object ejbMB = null; 998 String j2eeType = null; 999 1000 if (ejbType.equals("Entity")) { 1001 j2eeType = "EntityBean"; 1002 } else if (ejbType.equals("Message-driven")) { 1003 j2eeType = "MessageDrivenBean"; 1004 } else if (ejbType.equals("Session")) { 1005 if (ejbSessionType.equals("Stateless")) { 1006 j2eeType = "StatelessSessionBean"; 1007 } else if (ejbSessionType.equals("Stateful")) { 1008 j2eeType = "StatefulSessionBean"; 1009 } 1010 } 1011 1012 if (ejbType.equals("Entity")) { 1013 EntityBeanMdl managedResource = 1014 new EntityBeanMdl(ejbName, moduleName, appName, serverName); 1015 instantiateAndRegisterRuntimeMBean("EntityBean", managedResource, 1016 appName, moduleName, ejbName); 1017 } else if (ejbType.equals("Message-driven")) { 1018 MessageDrivenBeanMdl managedResource = 1019 new MessageDrivenBeanMdl( 1020 ejbName, moduleName, appName, serverName); 1021 instantiateAndRegisterRuntimeMBean("MessageDrivenBean", managedResource, 1022 appName, moduleName, ejbName); 1023 } else if (ejbType.equals("Session")) { 1024 if (ejbSessionType.equals("Stateless")) { 1025 StatelessSessionBeanMdl managedResource = 1026 new StatelessSessionBeanMdl( 1027 ejbName, moduleName, appName, serverName); 1028 instantiateAndRegisterRuntimeMBean("StatelessSessionBean", managedResource, 1029 appName, moduleName, ejbName); 1030 } else if (ejbSessionType.equals("Stateful")) { 1031 StatefulSessionBeanMdl managedResource = 1032 new StatefulSessionBeanMdl( 1033 ejbName, moduleName, appName, serverName); 1034 instantiateAndRegisterRuntimeMBean("StatefulSessionBean", managedResource, 1035 appName, moduleName, ejbName); 1036 } 1037 } 1038 1039 } 1040 1041 1042 public void deleteEJBMBean(EjbDescriptor ejbDescriptor, String serverName) 1043 throws MBeanException { 1044 1045 1046 String ejbName = ejbDescriptor.getName(); 1047 String ejbType = ejbDescriptor.getType(); 1048 String ejbSessionType = null; 1049 if (ejbType.equals("Session")) { 1050 ejbSessionType = ((EjbSessionDescriptor) ejbDescriptor).getSessionType(); 1051 } 1052 1053 String moduleName = getModuleName(ejbDescriptor.getEjbBundleDescriptor()); 1054 String appName = getApplicationName(ejbDescriptor.getEjbBundleDescriptor()); 1055 1056 String j2eeType = null; 1057 1058 if (ejbType.equals("Entity")) { 1059 j2eeType = "EntityBean"; 1060 } else if (ejbType.equals("Message-driven")) { 1061 j2eeType = "MessageDrivenBean"; 1062 } else if (ejbType.equals("Session")) { 1063 if (ejbSessionType.equals("Stateless")) { 1064 j2eeType = "StatelessSessionBean"; 1065 } else if (ejbSessionType.equals("Stateful")) { 1066 j2eeType = "StatefulSessionBean"; 1067 } 1068 } 1069 1070 try { 1071 String namePattern = 1072 (domain + ":" + 1073 "j2eeType=" + j2eeType + "," + 1074 "name=" + ejbName + "," + 1075 "EJBModule=" + moduleName + "," + 1076 "J2EEApplication=" + appName + "," + 1077 "J2EEServer=" + serverName + "," + 1078 "*"); 1079 1080 ObjectName objName = findObjectName(namePattern); 1081 1082 if (objName != null) { 1083 unregister(objName); 1084 } 1085 } catch (Exception e) { 1086 throw new MBeanException(e); 1087 } 1088 } 1089 1090 1099 public void createWSEndpointMBean(String ctxRoot, 1100 WebServiceEndpoint wsDescriptor, 1101 String serverName) throws MBeanException { 1102 1103 1104 BundleDescriptor bd = wsDescriptor.getBundleDescriptor(); 1105 boolean isEjb = false; 1106 1107 if ( bd instanceof EjbBundleDescriptor) { 1108 isEjb = true; 1109 } 1110 1111 String epName = wsDescriptor.getEndpointName(); 1112 String appName = getApplicationName(bd); 1113 String regName = bd.getApplication().getRegistrationName(); 1114 String moduleName = getModuleName(bd); 1115 1116 if (ctxRoot != null ) { 1117 ServletWebServiceEndpointMdl managedResource = 1118 new ServletWebServiceEndpointMdl(epName, moduleName, regName, 1119 serverName, bd.getApplication().isVirtual(), isEjb); 1120 String cRoot = null; 1121 if (( ctxRoot.length() > 0) && (ctxRoot.charAt(0) != '/')){ 1122 cRoot = "/" + ctxRoot; 1123 } else { 1124 cRoot = ctxRoot; 1125 } 1126 instantiateAndRegisterRuntimeMBean(managedResource.getMBeanName(), 1127 managedResource, appName, WebModuleSupport.VIRTUAL_SERVER_PREFIX 1128 + DEFAULT_VIRTUAL_SERVER + cRoot, epName); 1129 } else { 1130 EJBWebServiceEndpointMdl managedResource = 1131 new EJBWebServiceEndpointMdl(epName, moduleName,regName, serverName, 1132 bd.getApplication().isVirtual(),isEjb); 1133 instantiateAndRegisterRuntimeMBean(managedResource.getMBeanName(), 1134 managedResource, appName, moduleName, epName); 1135 } 1136 } 1137 1138 1146 public void deleteWSEndpointMBean(String ctxRoot, 1147 WebServiceEndpoint wsDescriptor, String serverName) 1148 throws MBeanException { 1149 1150 String epName = wsDescriptor.getEndpointName(); 1151 BundleDescriptor bd = wsDescriptor.getBundleDescriptor(); 1152 1153 String moduleName = getModuleName(bd); 1154 String appName = getApplicationName(bd); 1155 1156 try { 1157 String namePattern = null; 1158 1159 if ( bd instanceof EjbBundleDescriptor) { 1160 namePattern = (domain + ":" + 1161 "j2eeType=WebServiceEndpoint," + 1162 "name=" + epName + "," + 1163 "EJBModule=" + moduleName + "," + 1164 "J2EEApplication=" + appName + "," + 1165 "J2EEServer=" + serverName + "," + 1166 "*"); 1167 } else if ( bd instanceof WebBundleDescriptor) { 1168 namePattern = (domain + ":" + 1169 "j2eeType=WebServiceEndpoint," + 1170 "name=" + epName + "," + 1171 "WebModule=" + WebModuleSupport.VIRTUAL_SERVER_PREFIX 1172 + DEFAULT_VIRTUAL_SERVER + ctxRoot + "," + 1173 "J2EEApplication=" + appName + "," + 1174 "J2EEServer=" + serverName + "," + 1175 "*"); 1176 } 1177 1178 ObjectName objName = findObjectName(namePattern); 1179 1180 if (objName != null) { 1181 unregister(objName); 1182 } 1183 } catch (Exception e) { 1184 throw new MBeanException(e); 1185 } 1186 } 1187 1188 1189 1201 1202 1203 1204 public void createWebModuleMBean(String appName, String parentName, 1205 String serverName, String deploymentDescriptor) 1206 throws MBeanException { 1207 1208 StartStopCallback sscb = new StartStopCallback(); 1209 J2EEModuleCallBackImpl module = new J2EEModuleCallBackImpl(appName, 1210 parentName, serverName, deploymentDescriptor, sscb); 1211 1212 WebModuleMdl managedResource = new WebModuleMdl(module); 1213 1214 instantiateAndRegisterRuntimeMBean( "WebModule", managedResource, 1215 null, parentName, appName); 1216 } 1217 1218 1219 public void deleteWebModuleMBean(String appName, String parentName, 1220 String serverName) throws MBeanException { 1221 1222 try { 1223 String namePattern = 1224 (domain + ":" + 1225 "j2eeType=WebModule" + "," + 1226 "name=" + appName + "," + 1227 "J2EEApplication=" + parentName + "," + 1228 "J2EEServer=" + serverName + "," + 1229 "*"); 1230 1231 ObjectName objName = findObjectName(namePattern); 1232 1233 if (objName != null) { 1234 unregister(objName); 1235 } 1236 } catch (Exception e) { 1237 throw new MBeanException(e); 1238 } 1239 } 1240 1241 1242 public void createWebMBeans( 1243 WebBundleDescriptor webBundleDescriptor, String serverName) 1244 throws MBeanException { 1245 1246 Set set = webBundleDescriptor.getWebComponentDescriptorsSet(); 1247 1248 String applicationName = webBundleDescriptor.getApplication() 1249 .getRegistrationName(); 1250 1251 if (applicationName == null) { 1252 applicationName = "null"; 1253 } 1254 1255 for (Iterator it = set.iterator(); it.hasNext();) { 1256 WebComponentDescriptor nextDescriptor = (WebComponentDescriptor) it.next(); 1257 createWebMBean(nextDescriptor.getCanonicalName(), 1258 webBundleDescriptor.getModuleID(), applicationName, serverName); 1259 } 1260 } 1261 1262 1263 public void deleteWebMBeans( 1264 WebBundleDescriptor webBundleDescriptor, String serverName) 1265 throws MBeanException { 1266 1267 Set set = webBundleDescriptor.getWebComponentDescriptorsSet(); 1268 1269 String applicationName = webBundleDescriptor.getApplication() 1270 .getRegistrationName(); 1271 1272 if (applicationName == null) { 1273 applicationName = "null"; 1274 } 1275 1276 for (Iterator it = set.iterator(); it.hasNext();) { 1277 WebComponentDescriptor nextDescriptor = (WebComponentDescriptor) it.next(); 1278 deleteWebMBean(nextDescriptor.getCanonicalName(), 1279 webBundleDescriptor.getModuleID(), applicationName, serverName); 1280 } 1281 } 1282 1283 1284 public void createWebMBean(String servletName, String moduleName, 1285 String appName, String serverName) throws MBeanException { 1286 1287 ServletMdl managedResource = new ServletMdl(servletName, moduleName, 1288 appName, serverName); 1289 1290 instantiateAndRegisterRuntimeMBean( "Servlet", managedResource, 1291 appName, moduleName, servletName); 1292 1293 } 1294 1295 1296 public void deleteWebMBean(String servletName, String moduleName, 1297 String appName, String serverName) throws MBeanException { 1298 1299 if (server == null) { 1300 initMBeanServer(); 1301 } 1302 1303 try { 1304 String namePattern = 1305 (domain + ":" + 1306 "j2eeType=Servlet" + "," + 1307 "name=" + servletName + "," + 1308 "WebModule=" + moduleName + "," + 1309 "J2EEApplication=" + appName + "," + 1310 "J2EEServer=" + serverName + "," + 1311 "*"); 1312 ObjectName objName = findObjectName(namePattern); 1313 1314 if (objName != null) { 1315 unregister(objName); 1316 } 1317 } catch (Exception e) { 1318 throw new MBeanException(e); 1319 } 1320 } 1321 1322 1323 public void createRARModuleMBean(ConnectorDescriptor bundleDesc, 1324 String serverName, String appLocation) throws MBeanException { 1325 1326 1328 1334 String modLocation = ""; 1335 if (bundleDesc.getModuleDescriptor().isStandalone()) { 1336 modLocation = appLocation + File.separator + 1337 DescriptorConstants.RAR_DD_ENTRY; 1338 } else { 1339 String moduleName = FileUtils.makeFriendlyFileName( 1340 bundleDesc.getModuleDescriptor().getArchiveUri()); 1341 modLocation = appLocation + File.separator + moduleName + File.separator + 1342 DescriptorConstants.RAR_DD_ENTRY; 1343 } 1344 1345 String xmlDesc = getStringForDDxml(modLocation); 1346 1347 String applicationName = getApplicationName(bundleDesc); 1348 1349 String resAdName = getModuleName(bundleDesc); 1350 1351 StartStopCallback sscb = new StartStopCallback(); 1352 J2EEModuleCallBackImpl module = new J2EEModuleCallBackImpl(resAdName, 1353 applicationName, serverName, xmlDesc, sscb); 1354 1355 ResourceAdapterModuleMdl managedResource = 1356 new ResourceAdapterModuleMdl(module, resAdName); 1357 1358 instantiateAndRegisterRuntimeMBean( "ResourceAdapterModule", managedResource, 1359 null, applicationName, resAdName); 1360 1361 } 1362 1363 1364 public void deleteRARModuleMBean(ConnectorDescriptor cd, 1365 String serverName) throws MBeanException { 1366 1367 1368 String moduleName = getModuleName(cd); 1369 String applicationName = getApplicationName(cd); 1370 1371 try { 1372 String namePattern = 1373 (domain + ":" + 1374 "j2eeType=ResourceAdapterModule" + "," + 1375 "name=" + moduleName + "," + 1376 "J2EEApplication=" + applicationName + "," + 1377 "J2EEServer=" + serverName + "," + 1378 "*"); 1379 1380 ObjectName objName = findObjectName(namePattern); 1381 1382 if (objName != null) { 1383 unregister(objName); 1384 } 1385 } catch (Exception e) { 1386 throw new MBeanException(e); 1387 } 1388 } 1389 1390 1391 public void createRARMBeans(ConnectorDescriptor cd, 1392 String serverName) throws MBeanException { 1393 1394 createRARMBean(cd, serverName); 1395 } 1396 1397 1398 public void deleteRARMBeans(ConnectorDescriptor cd, 1399 String serverName) throws MBeanException { 1400 1401 1402 deleteRARMBean(cd, serverName); 1403 } 1404 1405 1406 public void createRARMBean(ConnectorDescriptor cd, 1407 String serverName) throws MBeanException { 1408 1409 1410 String rarName = cd.getName(); 1411 String moduleName = getModuleName(cd); 1412 String appName = getApplicationName(cd); 1413 1414 ResourceAdapterMdl managedResource = 1415 new ResourceAdapterMdl(rarName, moduleName, appName, serverName); 1416 1417 instantiateAndRegisterRuntimeMBean( "ResourceAdapter", managedResource, 1418 appName, moduleName, rarName); 1419 1420 } 1421 1422 1423 public void deleteRARMBean(ConnectorDescriptor cd, 1424 String serverName) throws MBeanException { 1425 1426 1427 String rarName = cd.getName(); 1428 String moduleName = getModuleName(cd); 1429 String appName = getApplicationName(cd); 1430 1431 try { 1432 String namePattern = 1433 (domain + ":" + 1434 "j2eeType=ResourceAdapter" + "," + 1435 "name=" + rarName + "," + 1436 "ResourceAdapterModule=" + moduleName + "," + 1437 "J2EEApplication=" + appName + "," + 1438 "J2EEServer=" + serverName + "," + 1439 "*"); 1440 ObjectName objName = findObjectName(namePattern); 1441 1442 if (objName != null) { 1443 unregister(objName); 1444 } 1445 } catch (Exception e) { 1446 throw new MBeanException(e); 1447 } 1448 } 1449 1450 1451 public void createAppClientModuleMBean(String appName, 1452 String parentName, String serverName, String deploymentDescriptor) 1453 throws MBeanException { 1454 1455 StartStopCallback sscb = new StartStopCallback(); 1456 J2EEModuleCallBackImpl module = new J2EEModuleCallBackImpl(appName, 1457 parentName, serverName, deploymentDescriptor, sscb); 1458 1459 AppClientModuleMdl managedResource = new AppClientModuleMdl(module); 1460 instantiateAndRegisterRuntimeMBean( "AppClientModule", managedResource, 1461 null, parentName, appName); 1462 } 1463 1464 1465 public void deleteAppClientModuleMBean(String applicationName, 1466 String parentName, String serverName) throws MBeanException { 1467 1468 try { 1469 String namePattern = 1470 (domain + ":" + 1471 "j2eeType=AppClientModule" + "," + 1472 "name=" + applicationName + "," + 1473 "J2EEApplication=" + parentName + "," + 1474 "J2EEServer=" + serverName + "," + 1475 "*"); 1476 ObjectName objName = findObjectName(namePattern); 1477 if (objName != null) { 1478 unregister(objName); 1479 } 1480 } catch (Exception e) { 1481 throw new MBeanException(e); 1482 } 1483 } 1484 1485 1486 public void setApplicationState(int state, Application application, 1487 String serverName) throws MBeanException { 1488 1489 String applicationName = application.getRegistrationName(); 1490 String namePattern = 1491 (domain + ":" + 1492 "j2eeType=J2EEApplication" + "," + 1493 "name=" + applicationName + "," + 1494 "J2EEServer=" + serverName + "," + 1495 "*"); 1496 ObjectName objName = findObjectName(namePattern); 1497 if (objName != null) { 1498 setState(objName, state); 1499 } 1500 } 1501 1502 1503 public void setRARModuleState(int state, ConnectorDescriptor connectorDescriptor, 1504 String serverName) throws MBeanException { 1505 1506 String moduleName = getModuleName(connectorDescriptor); 1507 String applicationName = getApplicationName(connectorDescriptor); 1508 String namePattern = 1509 (domain + ":" + 1510 "j2eeType=ResourceAdapterModule" + "," + 1511 "name=" + moduleName + "," + 1512 "J2EEApplication=" + applicationName + "," + 1513 "J2EEServer=" + serverName + "," + 1514 "*"); 1515 ObjectName objName = findObjectName(namePattern); 1516 if (objName != null) { 1517 setState(objName, state); 1518 } 1519 } 1520 1521 1522 1523 public void setEJBModuleState(int state, EjbBundleDescriptor ejbBundleDescriptor, 1524 String serverName) throws MBeanException { 1525 1526 String moduleName = getModuleName(ejbBundleDescriptor); 1527 String applicationName = getApplicationName(ejbBundleDescriptor); 1528 String namePattern = 1529 (domain + ":" + 1530 "j2eeType=EJBModule" + "," + 1531 "name=" + moduleName + "," + 1532 "J2EEApplication=" + applicationName + "," + 1533 "J2EEServer=" + serverName + "," + 1534 "*"); 1535 ObjectName objName = findObjectName(namePattern); 1536 if (objName != null) { 1537 setState(objName, state); 1538 } 1539 } 1540 1541 1545 1546 private void setState(ObjectName objName, int state) throws MBeanException { 1547 try { 1548 if (server.isRegistered(objName)) { 1549 Integer stateValueObj = new Integer (state); 1550 server.setAttribute(objName, 1551 (new javax.management.Attribute ("state", stateValueObj))); 1552 } 1553 } catch (javax.management.InstanceNotFoundException infe) { 1554 } catch (Exception e) { 1555 throw new MBeanException(e); 1556 } 1557 } 1558 1559 1560 1561 public Integer getState(String namePattern) throws MBeanException { 1562 ObjectName objName = findObjectName(namePattern); 1563 if (objName != null) { 1564 try { 1565 Integer intObj = (Integer ) server.getAttribute(objName, "state"); 1566 return intObj; 1567 } catch (javax.management.InstanceNotFoundException infe) { 1568 } catch (Exception e) { 1569 throw new MBeanException(e); 1570 } 1571 } 1572 return null; 1573 } 1574 1575 1576 1577 private void register(Object object, ObjectName objectName) 1578 throws MBeanException { 1579 if (server == null) { 1580 initMBeanServer(); 1581 } 1582 1583 try { 1584 if (!server.isRegistered(objectName)) { 1585 server.registerMBean(object, objectName); 1586 } 1587 } catch (Exception e) { 1588 throw new MBeanException(e); 1589 } 1590 } 1591 1592 1593 public void unregister(ObjectName objectName) 1594 throws MBeanException { 1595 1596 try { 1597 if (server.isRegistered(objectName)) { 1598 server.unregisterMBean(objectName); 1599 } 1600 } catch (javax.management.InstanceNotFoundException infe) { 1601 } catch (Exception e) { 1602 throw new MBeanException(e); 1603 } 1604 } 1605 1606 1610 public ObjectName[] toObjectNameArray(String [] strings) 1611 throws MBeanException { 1612 if (strings != null) { 1614 ObjectName[] objectNames = new ObjectName[strings.length]; 1615 1616 for (int i = 0; i < strings.length; i++) { 1617 try { 1618 objectNames[i] = new ObjectName(strings[i]); 1619 } catch (MalformedObjectNameException mne) { 1620 throw new MBeanException(mne); 1621 } 1622 } 1623 1624 return objectNames; 1625 } 1626 1627 return new ObjectName[] { }; 1629 } 1630 1631 1632 public String getModuleName(BundleDescriptor bd) 1633 throws MBeanException { 1634 1635 String moduleName = null; 1636 1637 if (bd.getModuleDescriptor().isStandalone()) { 1638 moduleName = bd.getApplication().getRegistrationName(); 1639 } else { 1640 moduleName = bd.getModuleDescriptor().getArchiveUri(); 1641 } 1642 1643 return moduleName; 1644 1645 } 1646 1647 1648 1649 private String getModuleLocation(BundleDescriptor bd, String j2eeType) 1650 throws MBeanException { 1651 1652 String moduleName = null; 1653 String modLocation = null; 1654 String ddRoot = bd.getApplication().getGeneratedXMLDirectory(); 1655 1656 if (bd.getModuleDescriptor().isStandalone()) { 1657 1658 moduleName = bd.getApplication().getRegistrationName(); 1659 1660 if (j2eeType.equals("AppClientModule")) { 1661 modLocation = ddRoot + File.separator + 1662 DescriptorConstants.APP_CLIENT_DD_ENTRY; 1663 } else if (j2eeType.equals("EJBModule")) { 1664 modLocation = ddRoot + File.separator + 1665 DescriptorConstants.EJB_DD_ENTRY; 1666 } else if (j2eeType.equals("WebModule")) { 1667 modLocation = ddRoot + File.separator + 1668 DescriptorConstants.WEB_DD_ENTRY; 1669 } else if (j2eeType.equals("ResourceAdapterModule")) { 1670 modLocation = ddRoot + File.separator + 1671 DescriptorConstants.RAR_DD_ENTRY; 1672 } 1673 1674 } else { 1675 1676 moduleName = FileUtils.makeFriendlyFileName( 1677 bd.getModuleDescriptor().getArchiveUri()); 1678 1679 if (j2eeType.equals("AppClientModule")) { 1680 modLocation = ddRoot + File.separator + moduleName + File.separator + 1681 DescriptorConstants.APP_CLIENT_DD_ENTRY; 1682 } else if (j2eeType.equals("EJBModule")) { 1683 modLocation = ddRoot + File.separator + moduleName + File.separator + 1684 DescriptorConstants.EJB_DD_ENTRY; 1685 } else if (j2eeType.equals("WebModule")) { 1686 modLocation = ddRoot + File.separator + moduleName + File.separator + 1687 DescriptorConstants.WEB_DD_ENTRY; 1688 } else if (j2eeType.equals("ResourceAdapterModule")) { 1689 modLocation = ddRoot + File.separator + moduleName + File.separator + 1690 DescriptorConstants.RAR_DD_ENTRY; 1691 } 1692 } 1693 1694 return modLocation; 1695 } 1696 1697 1698 1699 public String getApplicationName(BundleDescriptor bd) { 1700 1701 String applicationName = "null"; 1702 1703 if (bd.getModuleDescriptor().isStandalone()) { 1704 return applicationName; 1705 } else { 1706 if (bd.getApplication() != null) { 1707 applicationName = bd.getApplication().getRegistrationName(); 1708 1709 if (applicationName == null) { 1710 applicationName = "null"; 1711 } 1712 } 1713 } 1714 return applicationName; 1715 } 1716 1717 1719 1721 public ObjectName findObjectName(String namePattern) 1722 throws MBeanException { 1723 1724 ObjectName [] objNameArr = findObjectNames(namePattern); 1725 1726 if ((objNameArr != null) && (objNameArr.length > 0)) { 1727 if (objNameArr.length > 1) { 1728 throw new MBeanException(new Exception ( 1729 "Found more than one mBean matchin the given object name pattern")); 1730 } 1731 return objNameArr[0]; 1732 } 1733 1734 return null; 1735 } 1736 1737 1738 1740 private ObjectName[] findObjectNames(String namePattern) 1741 throws MBeanException { 1742 1743 ObjectName [] objNameArr = null; 1744 ObjectName objNamePattern = null; 1745 1746 1748 try { 1749 objNamePattern = new ObjectName(namePattern); 1750 } catch (javax.management.MalformedObjectNameException mfone) { 1751 throw new MBeanException(mfone); 1752 } 1753 1754 Set s = new HashSet(); 1755 s = server.queryNames(objNamePattern, null); 1756 if (s != null) { 1757 objNameArr = (ObjectName[]) s.toArray( new ObjectName[s.size()]); 1758 return objNameArr; 1759 } 1760 1761 return objNameArr; 1762 } 1763 1764 1767 private String getStringForDDxml(String fileName) 1768 throws MBeanException { 1769 FileReader fr = null; 1770 try { 1771 1772 if (!(new File(fileName)).exists()) { 1773 _logger.log(Level.FINE, "Descriptor does not exist " + fileName); 1774 return null; 1775 } 1776 1777 fr = new FileReader(fileName); 1778 StringWriter sr = new StringWriter(); 1779 1780 char[] buf = new char[1024]; 1781 int len = 0; 1782 while (len != -1) { 1783 try { 1784 len = fr.read(buf, 0, buf.length); 1785 } catch (EOFException eof) { 1786 break; 1787 } 1788 if (len != -1) { 1789 sr.write(buf, 0, len); 1790 } 1791 } 1792 1793 fr.close(); 1794 sr.close(); 1795 1796 return sr.toString(); 1797 1798 } catch (FileNotFoundException fnfe) { 1799 throw new MBeanException(fnfe); 1801 } catch (IOException ioe) { 1802 throw new MBeanException(ioe); 1804 } finally { 1805 if (fr != null) { 1806 try { 1807 fr.close(); 1808 } catch (IOException ioe) { 1809 } 1810 } 1811 } 1812 } 1813 1814 1815 1816 public String getJ2eeTypeForEjb(EjbDescriptor ejbDescriptor) 1817 throws MBeanException { 1818 1819 1820 String ejbType = ejbDescriptor.getType(); 1821 String ejbSessionType = null; 1822 if (ejbType.equals("Session")) { 1823 ejbSessionType = ((EjbSessionDescriptor) ejbDescriptor).getSessionType(); 1824 } 1825 1826 String j2eeType = null; 1827 1828 if (ejbType.equals("Entity")) { 1829 j2eeType = "EntityBean"; 1830 } else if (ejbType.equals("Message-driven")) { 1831 j2eeType = "MessageDrivenBean"; 1832 } else if (ejbType.equals("Session")) { 1833 if (ejbSessionType.equals("Stateless")) { 1834 j2eeType = "StatelessSessionBean"; 1835 } else if (ejbSessionType.equals("Stateful")) { 1836 j2eeType = "StatefulSessionBean"; 1837 } 1838 } 1839 1840 return j2eeType; 1841 } 1842 1843 1844 private void registerDomainStatusMBean() { 1846 try { 1847 ObjectName on = DomainStatusHelper.getDomainStatusObjectName(); 1848 1849 server.registerMBean(new DomainStatus(), on); 1850 1851 Object [] params = new Object [2]; 1853 params[0] = (Object ) ApplicationServer.getServerContext().getInstanceName(); 1854 params[1] = (Object ) new Integer (StateManageable.STATE_RUNNING); 1855 String [] signature = {"java.lang.String", "java.lang.Integer"}; 1856 server.invoke(on, "setstate", params, signature); 1857 1858 } catch (MalformedObjectNameException mne) { 1859 throw new RuntimeException (mne); 1860 } catch (InstanceNotFoundException infe) { 1861 throw new RuntimeException (infe); 1862 } catch (InstanceAlreadyExistsException iae) { 1863 throw new RuntimeException (iae); 1864 } catch (MBeanRegistrationException mre) { 1865 throw new RuntimeException (mre); 1866 } catch (NotCompliantMBeanException ncmbe) { 1867 throw new RuntimeException (ncmbe); 1868 } catch (MBeanException mbe) { 1869 throw new RuntimeException (mbe); 1870 } catch (ReflectionException rfe) { 1871 throw new RuntimeException (rfe); 1872 } 1873 } 1874 1875 public void registerDasJ2EEServers() { 1877 String [] allServers = getAllServerNamesInDomain(); 1879 if ((allServers == null) || (allServers.length == 0)) return; 1880 for (int i=0; i<allServers.length; i++) { 1882 registerDasJ2EEServer(allServers[i]); 1883 } 1884 } 1885 1886 1887 private String [] getAllServerNamesInDomain() { 1889 ConfigContext configContext = 1891 AdminService.getAdminService().getAdminContext().getAdminConfigContext(); 1892 Server [] serverArr = null; 1893 try { 1894 serverArr = ServerHelper.getServersInDomain(configContext); 1895 } catch (ConfigException ce) { 1896 ce.printStackTrace(); 1897 _logger.log(Level.WARNING, "admin.get_servers_in_domain_error", ce); 1898 } 1899 if ((serverArr == null) || (serverArr.length == 0)) { 1900 return null; 1901 } 1902 1903 String [] strServerArr = new String [serverArr.length]; 1904 1905 for (int i=0; i<serverArr.length; i++) { 1906 strServerArr[i] = serverArr[i].getName(); 1907 } 1908 1909 return strServerArr; 1910 } 1911 1912 public void registerDasJ2EEServer(String serverName) { 1914 1915 DomainStatusHelper dsh = new DomainStatusHelper(); 1917 1918 try { 1919 if (! server.isRegistered(dsh.getDomainStatusObjectName())) { 1921 registerDomainStatusMBean(); 1922 } 1923 1924 try { 1926 dsh.getstate(serverName); 1927 } catch (Exception e) { 1928 Object [] params = new Object [2]; 1929 params[0] = (Object ) serverName; 1930 params[1] = (Object ) new Integer (StateManageable.STATE_STARTING); 1931 String [] signature = {"java.lang.String", "java.lang.Integer"}; 1932 server.invoke(dsh.getDomainStatusObjectName(), "setstate", params, signature); 1933 } 1934 1935 1945 ObjectName on = new ObjectName(getServerBaseON(true, serverName)); 1946 1947 DASJ2EEServerImpl ds = new DASJ2EEServerImpl(); 1948 ObjectInstance oi = server.registerMBean(ds, on); 1949 1950 server.addNotificationListener( 1952 dsh.getDomainStatusObjectName(), 1953 oi.getObjectName(), 1954 null, null); 1955 } catch(MalformedObjectNameException e) { 1956 e.printStackTrace(); 1957 _logger.log(Level.WARNING, "admin.registerDasJ2EEServer exception", e); 1958 } catch(javax.management.InstanceAlreadyExistsException iae) { 1959 } catch(javax.management.InstanceNotFoundException infe) { 1960 infe.printStackTrace(); 1961 _logger.log(Level.WARNING, "admin.registerDasJ2EEServer exception", infe); 1962 } catch(javax.management.MBeanRegistrationException mre) { 1963 mre.printStackTrace(); 1964 _logger.log(Level.WARNING, "admin.registerDasJ2EEServer exception", mre); 1965 } catch(javax.management.NotCompliantMBeanException ncmbe) { 1966 ncmbe.printStackTrace(); 1967 _logger.log(Level.WARNING, "admin.registerDasJ2EEServer exception", ncmbe); 1968 } catch(javax.management.MBeanException mbe) { 1969 mbe.printStackTrace(); 1970 _logger.log(Level.WARNING, "admin.registerDasJ2EEServer exception", mbe); 1971 } catch(javax.management.ReflectionException rfe) { 1972 rfe.printStackTrace(); 1973 _logger.log(Level.WARNING, "admin.registerDasJ2EEServer exception", rfe); 1974 } 1975 } 1976 1977 1978 public void unregisterDasJ2EEServer(String serverName) { 1980 try { 1981 1990 ObjectName onPattern = new ObjectName( 1991 getServerBaseON(true, serverName) + 1992 ",*" 1993 ); 1994 Set s = new HashSet(); 1996 s = server.queryNames(onPattern, null); 1997 if ((s != null) && (s.size() > 0)) { 1998 ObjectName [] objNameArr = 1999 (ObjectName[]) s.toArray( new ObjectName[s.size()]); 2000 server.unregisterMBean(objNameArr[0]); 2001 } 2002 } catch(MalformedObjectNameException e) { 2003 e.printStackTrace(); 2004 _logger.log(Level.WARNING, "admin.unregisterDASJ2EEServer exception", e); 2005 } catch (javax.management.InstanceNotFoundException infe) { 2006 _logger.log(Level.FINE, "admin.unregisterDASJ2EEServer exception", infe); 2007 } catch (MBeanException mbe) { 2008 _logger.log(Level.FINE, "admin.unregisterDASJ2EEServer exception", mbe); 2009 } catch (Exception ex) { 2010 ex.printStackTrace(); 2011 _logger.log(Level.FINE, "admin.unregisterDASJ2EEServer exception", ex); 2012 } 2013 } 2014 2015 2028 2029 public String getServerBaseON(boolean amx, String serverName) { 2030 2031 String domainName = null; 2032 2033 if (amx) { 2035 try { 2036 ObjectName pattern = Util.newObjectNamePattern( 2037 "*", LoaderMBean.LOADER_NAME_PROPS ); 2038 Set names = server.queryNames(pattern, null); 2039 assert( names.size() == 1 ); 2040 ObjectName loaderON = (ObjectName) SetUtil.getSingleton(names); 2041 domainName = 2042 (String ) server.getAttribute(loaderON, "AdministrativeDomainName"); 2043 } catch (Exception e) { 2044 throw new RuntimeException (e); 2045 } 2046 } else { 2048 2056 domainName = 2057 ApplicationServer.getServerContext().getDefaultDomainName(); 2058 } 2059 2060 return getServerBaseON(domainName, serverName); 2061 2062 } 2063 2064 2065 public void registerTransactionService() { 2066 TransactionServiceMdl ts = new TransactionServiceMdl(); 2067 instantiateAndRegisterRuntimeMBean("TransactionService", ts); 2068 } 2069 2070 private String getServerBaseON(String domainName, String serverName) { 2071 return( domainName + ":" + "j2eeType=J2EEServer,name=" + serverName); 2072 } 2073 2074 public void registerAllJ2EEClusters() { 2075 try { 2076 final Cluster[] clusters = ClusterHelper.getClustersInDomain( 2077 getAdminConfigContext()); 2078 if ((null == clusters) || (clusters.length == 0)) { 2079 return; 2080 } 2081 final ArrayList al = new ArrayList(clusters.length); 2082 for (int i = 0; i < clusters.length; i++) { 2083 al.add(clusters[i].getName()); 2084 } 2085 final String [] sa = (String [])al.toArray(new String [0]); 2086 _registerJ2EEClusters(sa); 2087 } catch (ConfigException ce) { 2088 throw new RuntimeException (ce.getMessage()); 2089 } 2090 } 2091 2092 public void registerJ2EECluster(String clusterName) { 2093 try { 2094 if (!ClusterHelper.isACluster(getAdminConfigContext(), clusterName)) { 2095 throw new RuntimeException (clusterName + " is not a valid cluster."); 2096 } 2097 } catch (ConfigException ce) { 2098 throw new RuntimeException (ce.getMessage()); 2099 } 2100 _registerJ2EEClusters(new String [] {clusterName}); 2101 } 2102 2103 public void unregisterJ2EECluster(String clusterName) { 2104 if ((null == clusterName) || "".equals(clusterName)) { 2105 throw new IllegalArgumentException (); 2106 } 2107 ObjectName on = null; 2108 final MBeanServer mbs = getAdminMBeanServer(); 2109 final ProxyFactory proxyFactory = ProxyFactory.getInstance( 2110 new MBeanServerConnectionSource(mbs)); 2111 final Set proxies = proxyFactory.getDomainRoot().getQueryMgr(). 2112 queryJ2EETypeSet(J2EECluster.J2EE_TYPE); 2113 final Iterator it = proxies.iterator(); 2114 while (it.hasNext()) { 2115 J2EECluster cluster = (J2EECluster)it.next(); 2116 if (cluster.getName().equals(clusterName)) { 2117 on = Util.getObjectName(cluster); 2118 break; 2119 } 2120 } 2121 try { 2122 mbs.unregisterMBean(on); 2123 } catch (Exception e) { 2124 throw new RuntimeException (e.getMessage()); 2125 } 2126 } 2127 2128 private void _registerJ2EEClusters(String [] clusters) { 2129 final ConfigContext ctx = getAdminConfigContext(); 2130 final MBeanServer mbs = getAdminMBeanServer(); 2131 final String amxJMXDomain = BootUtil.getInstance().getAMXJMXDomainName(); 2132 final String j2eeTypeProp = AMX.J2EE_TYPE_KEY + '=' + J2EECluster.J2EE_TYPE; 2133 for (int i = 0; i < clusters.length; i++) { 2134 final String nameProp = AMX.NAME_KEY + '=' + clusters[i]; 2135 final String props = Util.concatenateProps(j2eeTypeProp, nameProp); 2136 final ObjectName on = JMXUtil.newObjectName(amxJMXDomain, props); 2137 try { 2138 mbs.registerMBean(new J2EEClusterImpl(null), on); 2139 _logger.info(on + " is registered."); 2140 } catch (Exception e) { 2141 throw new RuntimeException (e.getMessage()); 2142 } 2143 } 2144 } 2145 2146 private ConfigContext getAdminConfigContext() { 2147 return AdminService.getAdminService().getAdminContext(). 2148 getAdminConfigContext(); 2149 } 2150 2151 private MBeanServer getAdminMBeanServer() { 2152 return AdminService.getAdminService().getAdminContext(). 2153 getMBeanServer(); 2154 } 2155 2156 private String getJVMId() { 2157 final String serverName = 2158 ApplicationServer.getServerContext().getInstanceName(); 2159 return serverName + System.currentTimeMillis(); 2160 } 2161 2162} 2163 | Popular Tags |