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.common.ObjectNames; 37 import com.sun.enterprise.admin.common.EntityStatus; 38 import com.sun.enterprise.admin.common.constant.ConfigAttributeName; 39 import com.sun.enterprise.admin.common.exception.J2EEWebModuleException; 40 import com.sun.enterprise.admin.common.exception.MBeanConfigException; 41 42 import com.sun.enterprise.instance.InstanceEnvironment; 44 import com.sun.enterprise.admin.event.AdminEvent; 45 import com.sun.enterprise.admin.event.AdminEventCache; 46 import com.sun.enterprise.admin.event.AdminEventResult; 47 import com.sun.enterprise.admin.event.ModuleDeployEvent; 48 import com.sun.enterprise.admin.event.BaseDeployEvent; 49 import com.sun.enterprise.admin.event.AdminEventMulticaster; 50 import com.sun.enterprise.admin.server.core.channel.RMIClient; 51 import com.sun.enterprise.admin.server.core.channel.AdminChannel; 52 import com.sun.enterprise.admin.common.Status; 53 import com.sun.enterprise.admin.common.MBeanServerFactory; 54 import javax.management.MBeanServer ; 55 import javax.management.ObjectName ; 56 import com.sun.enterprise.server.ApplicationServer; 57 import com.sun.enterprise.server.ServerContext; 58 import com.sun.enterprise.management.StateManageable; 59 60 61 73 74 public class ManagedStandaloneJ2EEWebModule extends ConfigMBeanBase implements ConfigAttributeName.StandaloneWebModule 75 { 76 82 private int state = StateManageable.RUNNING_STATE; 83 84 private static final String [][] MAPLIST = 85 { 86 {kName , ATTRIBUTE + ServerTags.NAME}, 87 {kContextRoot , ATTRIBUTE + ServerTags.CONTEXT_ROOT}, 88 {kLocation , ATTRIBUTE + ServerTags.LOCATION}, 89 {kVirtualServers , ATTRIBUTE + ServerTags.VIRTUAL_SERVERS}, 90 {kDescription , ATTRIBUTE + PSEUDO_ATTR_DESCRIPTION}, 92 }; 93 94 private static final String [] ATTRIBUTES = 95 { 96 kName + ", String, R" , 97 kContextRoot + ", String, RW" , 98 kLocation + ", String, RW" , 99 kVirtualServers + ", String, RW" , 100 kDescription + ", String, RW" , 102 }; 103 104 private static final String [] OPERATIONS = 105 { 106 "getStatus(), INFO", 107 "enable(), ACTION", 108 "disable(), ACTION", 109 "start(), ACTION", 110 "stop(), ACTION", 111 "getState(), INFO" 112 }; 113 114 117 public ManagedStandaloneJ2EEWebModule() throws MBeanConfigException 118 { 119 this.setDescriptions(MAPLIST, ATTRIBUTES, OPERATIONS); 120 } 121 122 public ManagedStandaloneJ2EEWebModule(String instanceName, String moduleName) 123 throws MBeanConfigException 124 { 125 this(); initialize(ObjectNames.kStandaloneWebModule, new String []{instanceName, moduleName}); 127 } 128 129 133 public EntityStatus getStatus() throws J2EEWebModuleException 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 J2EEWebModuleException(e.getMessage()); 154 } 155 return status; 156 } 157 158 163 public void disable() throws J2EEWebModuleException 164 { 165 return; 177 } 178 179 180 185 public void stop() throws J2EEWebModuleException { 186 state = StateManageable.STOPPING_STATE; 187 try { 188 String moduleName = (String )this.getAttribute(kName); 189 multicastAdminEvent(moduleName, BaseDeployEvent.DISABLE); 190 state = StateManageable.STOPPED_STATE; 191 } catch (Exception e) { 192 sLogger.throwing(getClass().getName(), "stop", e); 193 state = StateManageable.FAILED_STATE; 194 throw new J2EEWebModuleException(e.getMessage()); 195 } 196 } 197 198 201 public Integer getState() throws J2EEWebModuleException { 202 203 return (new Integer (state)); 204 205 214 215 232 } 233 234 235 240 public void enable() throws J2EEWebModuleException 241 { 242 return; 254 } 255 256 261 public void start() throws J2EEWebModuleException { 262 state = StateManageable.STARTING_STATE; 263 try { 264 String moduleName = (String )this.getAttribute(kName); 265 multicastAdminEvent(moduleName, BaseDeployEvent.ENABLE); 266 state = StateManageable.RUNNING_STATE; 267 } catch (Exception e) { 268 sLogger.throwing(getClass().getName(), "start", e); 269 state = StateManageable.FAILED_STATE; 270 throw new J2EEWebModuleException(e.getMessage()); 271 } 272 } 273 274 public String [] getServlets() throws J2EEWebModuleException 275 { 276 try 277 { 278 String location = (String )this.getAttribute(kLocation); 279 return ModulesXMLHelper.getServletsForWebModule(location, null); 280 } 281 catch (Exception e) 282 { 283 sLogger.throwing(getClass().getName(), "getServlets", e); 284 throw new J2EEWebModuleException(e.getMessage()); 285 } 286 } 287 288 289 293 294 298 private void multicastAdminEvent(String entityName, String actionCode) 299 throws J2EEWebModuleException { 300 String instanceName = super.getServerInstanceName(); 301 InstanceEnvironment instEnv = new InstanceEnvironment(instanceName); 302 310 AdminEvent event = new ModuleDeployEvent(instanceName, entityName, "web", actionCode); 311 RMIClient serverInstancePinger = AdminChannel.getRMIClient(instanceName); 313 if (serverInstancePinger.getInstanceStatusCode() != Status.kInstanceRunningCode) { 314 return; 315 } 316 AdminEventResult multicastResult = AdminEventMulticaster.multicastEvent(event); 317 if (!AdminEventResult.SUCCESS.equals(multicastResult.getResultCode())) { 318 AdminEventCache cache = AdminEventCache.getInstance(instanceName); 319 cache.setRestartNeeded(true); 320 } 321 } 322 } 323 | Popular Tags |