1 23 24 package com.sun.enterprise.admin; 25 26 import java.io.File ; 28 import java.io.InputStream ; 29 import java.net.URL ; 30 31 import javax.management.MBeanServer ; 33 import javax.management.ObjectInstance ; 34 35 36 49 import com.sun.appserv.server.ServerLifecycleException; 50 51 62 63 import com.sun.enterprise.config.ConfigFactory; 64 65 import java.io.File ; 66 import javax.management.MBeanServerFactory ; 67 import javax.management.MBeanServer ; 68 import javax.management.MBeanServerBuilder ; 69 70 80 import com.sun.enterprise.admin.meta.MBeanRegistry; 81 import com.sun.enterprise.admin.config.ConfigMBeansManager; 82 import com.sun.enterprise.management.ManagementObjectManager; 83 import com.sun.enterprise.management.util.J2EEManagementObjectManager; 84 85 86 94 public class AdminService { 95 96 99 public static final boolean ENABLE_PERFORMANCE_THREAD = true; 100 101 102 105 106 111 private static AdminService adminService = null; 112 private static String adminType = null; 113 private static final String DASD_TYPE = "DASD"; 114 private static final String DAS_TYPE = "DAS"; 115 private static final String INSTANCE_TYPE = "INSTANCE"; 116 117 private static String kTempDirNamePrefix = "s1astemp"; 118 private static String kGUITempDirName = "gui"; 119 124 125 128 129 private static int sMBeanServerID; 130 public static final int kDefaultImpl = 0; 131 132 134 private String mTempDirPath; 135 private String mGUITempDirPath; 136 137 141 AdminService() { 142 sMBeanServerID = kDefaultImpl; } 144 145 150 static void setAdminService(AdminService srv) { 151 adminService = srv; 152 } 153 154 158 public static AdminService getAdminService() { 159 return adminService; 160 } 161 162 172 void init() throws ServerLifecycleException { 173 210 211 213 createConfigContext(); 214 createRegistry(); 215 createMBS(); 216 createAdminServiceMBean(); 217 } 218 219 220 225 void start() throws ServerLifecycleException { 226 if (isAdminInstance()) { 227 startAdminInstance(); 228 } else { 229 startNormalInstance(); 230 } 231 } 232 233 236 void ready() throws ServerLifecycleException { 237 if (isAdminInstance()) { 238 readyAdminInstance(); 239 } else { 240 readyNormalInstance(); 241 } 242 } 243 244 247 void stop() throws ServerLifecycleException { 248 if (isAdminInstance()) { 249 stopAdminInstance(); 252 } else { 253 stopNormalInstance(); 254 } 255 } 256 257 260 void destroy() throws ServerLifecycleException { 261 } 262 263 281 public String getInstanceName() { 282 return "PE"; 283 } 286 287 298 private void startAdminInstance() throws ServerLifecycleException { 299 301 303 305 registerAdminMBeans(); 307 308 if(DASD_TYPE.equals(adminType)) { 309 } 311 312 315 320 } 323 324 328 private void readyAdminInstance() throws ServerLifecycleException { 329 333 } 334 335 338 private void stopAdminInstance() throws ServerLifecycleException { 339 343 } 344 345 348 private void startNormalInstance() throws ServerLifecycleException { 349 } 359 360 363 private void readyNormalInstance() throws ServerLifecycleException { 364 } 366 367 370 private void stopNormalInstance() throws ServerLifecycleException { 371 } 373 374 380 public boolean isAdminInstance() { 382 return true; 383 390 } 391 392 421 public String getTempDirPath() { 422 if (mTempDirPath == null) { 423 430 } 432 433 return ( mTempDirPath ); 434 } 435 436 444 public String getGUITempDirPath() { 445 if (mGUITempDirPath == null) { 446 453 } 455 456 return ( mGUITempDirPath ); 457 } 458 459 467 468 473 474 479 485 491 492 503 504 533 534 602 603 610 private static String getAdminType() { 611 612 if(adminType != null) return adminType; 613 614 616 adminType = "DAS"; return adminType; 620 } 621 622 623 626 private static void createRegistry() { 627 System.out.println("Create configuration registry ..."); 628 try { 629 URL url = AdminService.class.getResource 630 ("/mbeans-descriptors.xml"); 631 InputStream stream = url.openStream(); 632 MBeanRegistry registry = new MBeanRegistry(); 633 registry.loadMBeanRegistry(stream); 634 stream.close(); 635 } catch (Throwable t) { 636 t.printStackTrace(System.out); 637 System.exit(1); 638 } 639 640 } 641 642 645 private void createConfigContext() { 646 try { 648 ConfigFactory.createConfigContext("../config-api/dtds/domain.xml"); 650 } catch (Throwable t) { 651 t.printStackTrace(System.out); 652 System.exit(1); 653 } 654 655 } 656 657 private void createMBS() { 660 661 System.out.println("Creating MBeanServer ..."); 662 try { 663 System.setProperty("javax.management.builder.initial", 664 "com.sun.enterprise.admin.jmx.AppServerMBeanServerBuilder"); 665 666 MBeanServer server = MBeanServerFactory.createMBeanServer("com.sun.appserv"); 668 } catch (Throwable t) { 669 t.printStackTrace(System.out); 670 System.exit(1); 671 } 672 673 } 674 675 private void createAdminServiceMBean() { 676 677 System.out.println("Creating AdminServiceMBean ..."); 678 try { 679 ; 682 } catch (Throwable t) { 683 t.printStackTrace(System.out); 684 System.exit(1); 685 } 686 687 } 688 689 692 private void registerAdminMBeans() { 693 ConfigMBeansManager cmbm = new ConfigMBeansManager(); 695 ManagementObjectManager mom = new J2EEManagementObjectManager(); 696 697 String domain = "com.sun.appserv"; 699 mom.registerJ2EEDomain(domain); 700 cmbm.registerAllConfigJ2EEServers(); 701 } 702 703 } 707 | Popular Tags |