1 23 24 package com.sun.enterprise.admin.server.core.mbean.config; 25 26 import javax.management.Attribute ; 28 29 import com.sun.enterprise.config.ConfigException; 31 import com.sun.enterprise.config.serverbeans.ServerXPathHelper; 32 import com.sun.enterprise.config.serverbeans.ServerTags; 33 import com.sun.enterprise.config.serverbeans.EjbModule; 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.MBeanConfigException; 40 import com.sun.enterprise.admin.common.exception.J2EEConnectorModuleException; 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 59 60 72 73 public class ManagedStandaloneConnectorModule extends ConfigMBeanBase 74 implements ConfigAttributeName.StandaloneConnectorModule 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 }; 101 102 105 public ManagedStandaloneConnectorModule() throws MBeanConfigException 106 { 107 this.setDescriptions(MAPLIST, ATTRIBUTES, OPERATIONS); 108 } 109 110 public ManagedStandaloneConnectorModule(String instanceName, String moduleName) 111 throws MBeanConfigException 112 { 113 this(); initialize(ObjectNames.kConnectorModule, new String []{instanceName, moduleName}); 115 } 116 120 public EntityStatus getStatus() throws J2EEConnectorModuleException 121 { 122 EntityStatus status = null; 123 try 124 { 125 boolean isModuleEnabled = true; status = new EntityStatus(); 129 if (isModuleEnabled) 130 { 131 status.setEnabled(); 132 } 133 else 134 { 135 status.setDisabled(); 136 } 137 } 138 catch (Exception e) 139 { 140 sLogger.throwing(getClass().getName(), "getStatus", e); 141 throw new J2EEConnectorModuleException(e.getMessage()); 142 } 143 return status; 144 } 145 146 151 public void disable() throws J2EEConnectorModuleException 152 { 153 return; 165 } 166 167 168 173 public void stop() throws J2EEConnectorModuleException { 174 try { 175 String moduleName = (String )this.getAttribute(kName); 176 multicastAdminEvent(moduleName, BaseDeployEvent.DISABLE); 177 } catch (Exception e) { 178 sLogger.throwing(getClass().getName(), "stop", e); 179 throw new J2EEConnectorModuleException(e.getMessage()); 180 } 181 } 182 183 186 public Integer getState() throws J2EEConnectorModuleException { 187 try { 188 String moduleName = (String )this.getAttribute(kName); 189 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 190 ServerContext serverContext = ApplicationServer.getServerContext(); 191 ObjectName objName = new ObjectName ( 192 serverContext.getDefaultDomainName() + ":" + 193 "j2eeType=ResourceAdapterModule," + 194 "name=" + ((String )this.getAttribute(kName)) + "," + 195 "J2EEApplication=" + "null" + "," + 196 "J2EEServer=" + serverContext.getInstanceName()); 197 Integer intObj = (Integer ) mbs.getAttribute(objName, "state"); 198 return intObj; 199 } catch (Exception e) { 200 sLogger.throwing(getClass().getName(), "getState", e); 201 throw new J2EEConnectorModuleException(e.getMessage()); 202 } 203 } 204 205 206 207 212 public void enable() throws J2EEConnectorModuleException 213 { 214 return; 226 } 227 228 233 public void start() throws J2EEConnectorModuleException { 234 try { 235 String moduleName = (String )this.getAttribute(kName); 236 multicastAdminEvent(moduleName, BaseDeployEvent.ENABLE); 237 } catch (Exception e) { 238 sLogger.throwing(getClass().getName(), "start", e); 239 throw new J2EEConnectorModuleException(e.getMessage()); 240 } 241 } 242 243 247 private void multicastAdminEvent(String entityName, String actionCode) 248 throws J2EEConnectorModuleException { 249 String instanceName = super.getServerInstanceName(); 250 InstanceEnvironment instEnv = new InstanceEnvironment(instanceName); 251 259 AdminEvent event = new ModuleDeployEvent(instanceName, entityName, 260 ModuleDeployEvent.TYPE_CONNECTOR, actionCode); 261 RMIClient serverInstancePinger = AdminChannel.getRMIClient(instanceName); 263 if (serverInstancePinger.getInstanceStatusCode() != Status.kInstanceRunningCode) { 264 return; 265 } 266 AdminEventResult multicastResult = AdminEventMulticaster.multicastEvent(event); 267 if (!AdminEventResult.SUCCESS.equals(multicastResult.getResultCode())) { 268 AdminEventCache cache = AdminEventCache.getInstance(instanceName); 269 cache.setRestartNeeded(true); 270 } 271 } 272 } 273 | Popular Tags |