1 23 24 29 30 package com.sun.enterprise.admin.server.core.jmx; 31 32 import javax.management.MBeanServer ; 33 import javax.management.MBeanServerDelegate ; 34 import javax.management.MBeanServerBuilder ; 35 36 import java.util.logging.Logger ; 37 import com.sun.enterprise.admin.common.constant.AdminConstants; 38 import java.util.logging.Level ; 39 40 48 public class AppServerMBeanServerBuilder extends javax.management.MBeanServerBuilder { 49 50 private static final MBeanServerBuilder defaultBuilder = new MBeanServerBuilder (); 51 52 protected static final Logger _logger = 53 Logger.getLogger(AdminConstants.kLoggerName); 54 55 58 private static boolean createAppServerMBeanServer = false; 59 60 61 public AppServerMBeanServerBuilder() { 62 } 63 64 96 97 public MBeanServer newMBeanServer(String defaultDomain, 98 MBeanServer outer, 99 MBeanServerDelegate delegate) { 100 101 synchronized (AppServerMBeanServerBuilder.class) { 102 if (!createAppServerMBeanServer) { 103 _logger.log(Level.FINE, 104 "Creating default JMX MBeanServer in AppServerMBeanServerBuilder"); 105 return defaultBuilder.newMBeanServer(defaultDomain, 106 outer, 107 delegate); 108 } else { 109 _logger.log(Level.FINEST, 110 "Creating MBeanServer with appserver interceptors in AppServerMBeanServerBuilder"); 111 return newAppServerMBeanServer(defaultDomain, delegate); 112 } 113 } 114 } 115 116 128 protected MBeanServer newAppServerMBeanServer(String defaultDomain, 129 MBeanServerDelegate delegate) { 130 try { 131 MBeanServer appserverMBS = new SunoneInterceptor(); 134 MBeanServer newAppserverMBS = addInterceptor(appserverMBS); 135 MBeanServer jmxMBS = 136 defaultBuilder.newMBeanServer(defaultDomain, 137 newAppserverMBS, 138 delegate); 139 ((SunoneInterceptor) appserverMBS).setJmxMBeanServer(jmxMBS); 140 _logger.log(Level.FINEST, 141 "Created MBeanServer in AppServerMBeanServerBuilder"); 142 return newAppserverMBS; 143 144 } catch (InitException e) { 145 _logger.log(Level.FINE, "InitException while creating MBeanServer", e); 146 throw new RuntimeException (e.getMessage(), e.getCause()); 147 } 148 } 149 150 154 protected MBeanServer addInterceptor(MBeanServer mbs) { 155 _logger.log(Level.FINEST, 157 "No additional interceptors added in" + 158 "addInterceptor() in AppServerMBeanServerBuilder"); 159 return mbs; 160 } 161 162 174 public MBeanServerDelegate newMBeanServerDelegate() { 175 return defaultBuilder.newMBeanServerDelegate(); 176 } 177 178 182 static void enableAppServerMBeanServer(boolean flag) { 183 createAppServerMBeanServer = flag; 184 } 185 186 190 static protected boolean createAppServerMBeanServer() { 191 return createAppServerMBeanServer; 192 } 193 194 197 static protected MBeanServerBuilder getDefaultBuilder() { 198 return defaultBuilder; 199 } 200 } | Popular Tags |