1 23 package com.sun.enterprise.admin.server.core.jmx.storage; 24 25 import javax.management.ObjectName ; 27 import com.sun.enterprise.admin.AdminContext; 29 import com.sun.enterprise.admin.common.ObjectNames; 30 import com.sun.enterprise.admin.common.ObjectNameHelper; 31 import com.sun.enterprise.admin.common.exception.MBeanConfigException; 32 import com.sun.enterprise.admin.util.HostAndPort; 33 import com.sun.enterprise.admin.common.constant.AdminConstants; 35 import com.sun.enterprise.admin.server.core.mbean.config.GenericConfigurator; 36 import com.sun.enterprise.admin.server.core.mbean.config.ServerController; 37 import com.sun.enterprise.admin.server.core.mbean.config.ManagedAdminServerInstance; 38 import com.sun.enterprise.admin.server.core.mbean.config.ManagedServerInstance; 39 import com.sun.enterprise.admin.server.core.mbean.config.naming.ConfigMBeanNamingInfo; 40 41 import com.sun.enterprise.config.serverbeans.*; 43 import com.sun.enterprise.config.ConfigFactory; 44 import com.sun.enterprise.config.ConfigContext; 45 import com.sun.enterprise.config.ConfigException; 46 import com.sun.enterprise.config.ConfigBeansFactory; 47 import com.sun.enterprise.instance.ServerManager; 48 49 import com.sun.enterprise.admin.meta.MBeanRegistryEntry; 50 import com.sun.enterprise.server.ApplicationServer; 52 import com.sun.enterprise.instance.InstanceEnvironment; 53 54 import java.util.logging.Level ; 55 import java.util.logging.Logger ; 56 57 import com.sun.enterprise.util.i18n.StringManager; 59 60 61 66 67 public class MBeanManufacturer 68 { 69 private ObjectName mObjectName = null; 70 private Object mConfigBean = null; 71 private AdminContext mAdminContext; 72 73 private static final Logger _logger = Logger.getLogger(AdminConstants.kLoggerName); 74 75 private static StringManager localStrings = 77 StringManager.getManager( MBeanManufacturer.class ); 78 79 80 public MBeanManufacturer (ObjectName oName, Object configBean) 81 { 82 if (oName == null || configBean == null) 83 { 84 String msg = localStrings.getString( "admin.server.core.jmx.storage.null_object_name_or_config_bean" ); 85 throw new IllegalArgumentException ( msg ); 86 } 87 mObjectName = oName; 88 mConfigBean = configBean; 89 } 90 91 public void setAdminContext(AdminContext ctx) { 92 mAdminContext = ctx; 93 } 94 95 103 public Object createMBeanInstance() 104 { 105 Object mbeanInstance = null; 106 String instanceName = ApplicationServer.getServerContext().getInstanceName(); 107 108 if(mConfigBean instanceof MBeanRegistryEntry) 110 { 111 ConfigContext configContext; 112 try 113 { 114 if (mAdminContext != null) { 115 configContext = mAdminContext.getAdminConfigContext(); 116 } else { 117 InstanceEnvironment instanceEnvironment = new InstanceEnvironment(instanceName); 118 120 String fileUrl = instanceEnvironment.getBackupConfigFilePath(); 121 configContext = ConfigFactory.createConfigContext(fileUrl); 122 } 123 return ((MBeanRegistryEntry)mConfigBean).instantiateMBean(mObjectName,null, configContext); 124 } 125 catch(Exception e) 126 { 127 return null; 128 } 129 } 130 String type = ObjectNameHelper.getType(mObjectName); 131 Level logLevel = Level.SEVERE; 133 134 try 135 { 136 if (type.equals(ObjectNames.kController)) 137 { 138 mbeanInstance = new ServerController(mAdminContext); 139 } 140 else if (type.equals(ObjectNames.kGenericConfigurator)) 141 { 142 mbeanInstance = new GenericConfigurator(); 143 } 144 else if (type.equals(ObjectNames.kServerInstance)) 145 { 146 mbeanInstance = createServerInstanceMBean(instanceName); 147 157 } 158 else 159 { 160 logLevel = Level.FINE; 161 mbeanInstance = createGenericConfigMBean(mObjectName); 162 } 163 } 164 catch(Exception e) 165 { 166 _logger.log(logLevel, "mbean.config.admin.create_mbean_instance_failed", e ); 167 } 168 169 return ( mbeanInstance ); 170 } 171 172 private ManagedServerInstance createServerInstanceMBean(String instanceName) throws Exception 173 { 174 Server server = (Server)mConfigBean; 175 ConfigContext ctx = server.getConfigContext(); 177 Config config = (Config) ConfigBeansFactory.getConfigBeanByXPath(ctx, ServerXPathHelper.XPATH_CONFIG); 178 HttpService https = config.getHttpService(); 179 180 HttpListener[] hlArray = https.getHttpListener(); 181 HttpListener ls = hlArray[0]; 184 for(int i = 0;i<hlArray.length;i++) { 186 if(hlArray[i].isEnabled()) { 187 ls = hlArray[i]; 188 break; 189 } 190 } 191 String port = new PropertyResolver(ctx, instanceName). 192 resolve(ls.getPort()); 193 int intPort = Integer.parseInt (port); 194 HostAndPort hp = new HostAndPort("localhost", intPort); 195 return new ManagedServerInstance(instanceName, hp, false, mAdminContext); 196 } 197 198 private ManagedAdminServerInstance createAdminServerInstance() 199 throws Exception 200 { 201 return new ManagedAdminServerInstance(); 202 } 203 204 private Object createGenericConfigMBean(ObjectName objectName) throws MBeanConfigException 205 { 206 ConfigMBeanNamingInfo mbeanInfo = new ConfigMBeanNamingInfo(objectName); 207 mbeanInfo.setAdminContext(mAdminContext); 208 return mbeanInfo.constructConfigMBean(); 209 } 210 211 } 212 | Popular Tags |