1 23 24 package com.sun.enterprise.admin.server.core.mbean.config; 25 26 import com.sun.enterprise.config.ConfigException; 28 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 29 import com.sun.enterprise.config.serverbeans.ServerTags; 30 32 import javax.management.Attribute ; 34 35 import com.sun.enterprise.admin.AdminContext; 37 import com.sun.enterprise.admin.common.ObjectNames; 38 import com.sun.enterprise.admin.common.exception.J2EEEjbJarModuleException; 39 import com.sun.enterprise.admin.common.EntityStatus; 40 import com.sun.enterprise.admin.common.constant.ConfigAttributeName; 41 import com.sun.enterprise.admin.common.exception.MBeanConfigException; 42 43 import com.sun.enterprise.instance.InstanceEnvironment; 45 import com.sun.enterprise.admin.event.AdminEvent; 46 import com.sun.enterprise.admin.event.AdminEventCache; 47 import com.sun.enterprise.admin.event.AdminEventResult; 48 import com.sun.enterprise.admin.event.ModuleDeployEvent; 49 import com.sun.enterprise.admin.event.BaseDeployEvent; 50 import com.sun.enterprise.admin.event.AdminEventMulticaster; 51 import com.sun.enterprise.admin.server.core.channel.RMIClient; 52 import com.sun.enterprise.admin.server.core.channel.AdminChannel; 53 import com.sun.enterprise.admin.common.Status; 54 import com.sun.enterprise.admin.common.MBeanServerFactory; 55 import javax.management.MBeanServer ; 56 import javax.management.ObjectName ; 57 import com.sun.enterprise.server.ApplicationServer; 58 import com.sun.enterprise.server.ServerContext; 59 60 61 73 74 public class ManagedStandaloneJ2EEEjbJarModule extends ConfigMBeanBase implements ConfigAttributeName.StandaloneEjbJarModule 75 { 76 private static final String [][] MAPLIST = 77 { 78 {kName , ATTRIBUTE + ServerTags.NAME}, 79 {kLocation , ATTRIBUTE + ServerTags.LOCATION}, 80 {kDescription , ATTRIBUTE + PSEUDO_ATTR_DESCRIPTION}, 82 }; 83 84 private static final String [] ATTRIBUTES = 85 { 86 kName + ", String, R" , 87 kLocation + ", String, RW" , 88 kDescription + ", String, RW" , 90 }; 91 92 private static final String [] OPERATIONS = 93 { 94 "getStatus(), INFO", 95 "enable(), ACTION", 96 "disable(), ACTION", 97 "start(), ACTION", 98 "stop(), ACTION", 99 "getState(), INFO", 100 "getEnterpriseBeans(), INFO", 101 "getSessionEJBs(), INFO", 102 "getEntityEJBs(), INFO" 103 }; 104 105 106 109 public ManagedStandaloneJ2EEEjbJarModule() throws MBeanConfigException 110 { 111 this.setDescriptions(MAPLIST, ATTRIBUTES, OPERATIONS); 112 } 113 114 public ManagedStandaloneJ2EEEjbJarModule(String instanceName, String moduleName) 115 throws MBeanConfigException 116 { 117 this(instanceName, moduleName, null); 118 } 119 120 public ManagedStandaloneJ2EEEjbJarModule(String instanceName, 121 String moduleName, AdminContext adminContext) 122 throws MBeanConfigException 123 { 124 this(); setAdminContext(adminContext); 126 initialize(ObjectNames.kStandaloneEjbModule, new String []{instanceName, moduleName}); 127 } 128 129 133 public EntityStatus getStatus() throws J2EEEjbJarModuleException 134 { 135 EntityStatus status = null; 136 try 137 { 138 boolean isModuleEnabled = true; status = new EntityStatus(); 141 if (isModuleEnabled) 142 { 143 status.setEnabled(); 144 } 145 else 146 { 147 status.setDisabled(); 148 } 149 } 150 catch (Exception e) 151 { 152 sLogger.throwing(getClass().getName(), "getStatus", e); 153 throw new J2EEEjbJarModuleException(e.getMessage()); 154 } 155 return status; 156 } 157 158 163 public void disable() throws J2EEEjbJarModuleException 164 { 165 return; 177 } 178 179 180 185 public void stop() throws J2EEEjbJarModuleException { 186 try { 187 String moduleName = (String )this.getAttribute(kName); 188 multicastAdminEvent(moduleName, BaseDeployEvent.DISABLE); 189 } catch (Exception e) { 190 sLogger.throwing(getClass().getName(), "stop", e); 191 throw new J2EEEjbJarModuleException(e.getMessage()); 192 } 193 } 194 195 198 public Integer getState() throws J2EEEjbJarModuleException { 199 try { 200 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 201 ServerContext serverContext = ApplicationServer.getServerContext(); 202 ObjectName objName = new ObjectName ( 203 serverContext.getDefaultDomainName() + ":" + 204 "j2eeType=EJBModule," + 205 "name=" + ((String )this.getAttribute(kName)) + "," + 206 "J2EEApplication=" + "null" + "," + 207 "J2EEServer=" + serverContext.getInstanceName()); 208 Integer intObj = (Integer ) mbs.getAttribute(objName, "state"); 209 return intObj; 210 } catch (Exception e) { 211 sLogger.throwing(getClass().getName(), "stop", e); 212 throw new J2EEEjbJarModuleException(e.getMessage()); 213 } 214 } 215 216 221 public void enable() throws J2EEEjbJarModuleException 222 { 223 return; 235 } 236 237 242 public void start() throws J2EEEjbJarModuleException { 243 try { 244 String moduleName = (String )this.getAttribute(kName); 245 multicastAdminEvent(moduleName, BaseDeployEvent.ENABLE); 246 } catch (Exception e) { 247 sLogger.throwing(getClass().getName(), "start", e); 248 throw new J2EEEjbJarModuleException(e.getMessage()); 249 } 250 } 251 252 public String [] getEnterpriseBeans() throws J2EEEjbJarModuleException 253 { 254 return getBeansByType(ModulesXMLHelper.EJB_TYPE_ALL); 255 } 256 257 public String [] getSessionEJBs() throws J2EEEjbJarModuleException 258 { 259 return getBeansByType(ModulesXMLHelper.EJB_TYPE_SESSION); 260 } 261 262 public String [] getEntityEJBs() throws J2EEEjbJarModuleException 263 { 264 return getBeansByType(ModulesXMLHelper.EJB_TYPE_ENTITY); 265 } 266 267 private String [] getBeansByType(int ejbType) throws J2EEEjbJarModuleException 268 { 269 try 270 { 271 String location = (String )this.getAttribute(kLocation); 272 return ModulesXMLHelper.getEnterpriseBeansForEjbModule(location, null, ejbType); 273 } 274 catch (Exception e) 275 { 276 sLogger.throwing(getClass().getName(), "getBeansByType", e); 277 throw new J2EEEjbJarModuleException(e.getMessage()); 278 } 279 } 280 281 285 private void multicastAdminEvent(String entityName, String actionCode) 286 throws J2EEEjbJarModuleException { 287 String instanceName = super.getServerInstanceName(); 288 InstanceEnvironment instEnv = new InstanceEnvironment(instanceName); 289 try { 290 instEnv.applyServerXmlChanges(false); 291 } catch (Exception e) { 292 sLogger.throwing(getClass().getName(), "getBeansByType", e); 293 throw new J2EEEjbJarModuleException(e.getMessage()); 294 } 295 AdminEvent event = new ModuleDeployEvent(instanceName, entityName, "ejb", actionCode); 296 RMIClient serverInstancePinger = AdminChannel.getRMIClient(instanceName); 298 if (serverInstancePinger.getInstanceStatusCode() != Status.kInstanceRunningCode) { 299 return; 300 } 301 AdminEventResult multicastResult = AdminEventMulticaster.multicastEvent(event); 302 if (!AdminEventResult.SUCCESS.equals(multicastResult.getResultCode())) { 303 AdminEventCache cache = AdminEventCache.getInstance(instanceName); 304 cache.setRestartNeeded(true); 305 } 306 } 307 } 308 | Popular Tags |