1 23 package com.sun.enterprise.management.util; 24 25 import com.sun.enterprise.admin.server.core.mbean.config.*; 26 import com.sun.enterprise.management.model.*; 27 import com.sun.enterprise.ManagementObjectManager; 28 import javax.management.*; 29 30 31 39 public class StartStopCallback { 40 private static boolean debug = false; 41 42 47 public void startModule(J2EEDeployedObjectMdl modObject) 48 throws MBeanException { 49 50 if (debug) { 51 return; 52 } 53 54 String moduleID = modObject.getname(); 55 String j2eeType = modObject.getj2eeType(); 56 String serverName = modObject.getJ2EEServer(); 57 58 if ((!j2eeType.equals(ManagementObjectManager.J2EE_TYPE_APPLICATION)) && 60 (!standAlone(modObject))) { 61 throw new MBeanException( 62 new Exception ( 63 "cannot start individual module, start the application itself")); 64 } 65 66 if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_EJB_MODULE)) { 67 startEJBModule(moduleID, serverName); 68 } else if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_WEB_MODULE)) { 69 startWEBModule(moduleID, serverName); 70 } else if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_RAR_MODULE)) { 71 startRARModule(moduleID, serverName); 72 } else if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_ACC_MODULE)) { 73 return; 74 } else if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_APPLICATION)) { 75 startApplication(moduleID, serverName); 76 } 77 } 78 79 84 public void stopModule(J2EEDeployedObjectMdl modObject) 85 throws MBeanException { 86 87 if (debug) { 88 return; 89 } 90 91 String moduleID = modObject.getname(); 92 String j2eeType = modObject.getj2eeType(); 93 String serverName = modObject.getJ2EEServer(); 94 95 if ((!j2eeType.equals(ManagementObjectManager.J2EE_TYPE_APPLICATION)) && 97 (!standAlone(modObject))) { 98 throw new MBeanException( 99 new Exception ( 100 "cannot stop individual module, stop the application itself")); 101 } 102 103 if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_EJB_MODULE)) { 104 stopEJBModule(moduleID, serverName); 105 } else if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_WEB_MODULE)) { 106 stopWEBModule(moduleID, serverName); 107 } else if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_RAR_MODULE)) { 108 stopRARModule(moduleID, serverName); 109 } else if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_ACC_MODULE)) { 110 return; 111 } else if (j2eeType.equals(ManagementObjectManager.J2EE_TYPE_APPLICATION)) { 112 stopApplication(moduleID, serverName); 113 } 114 } 115 116 117 private void startEJBModule(String moduleID, String serverName) 118 throws MBeanException { 119 try { 120 ManagedStandaloneJ2EEEjbJarModule msejbModule = new ManagedStandaloneJ2EEEjbJarModule(serverName, 121 moduleID); 122 msejbModule.start(); 123 } catch (Exception e) { 124 throw new MBeanException(e); 125 } 126 } 127 128 129 private void stopEJBModule(String moduleID, String serverName) 130 throws MBeanException { 131 132 try { 133 ManagedStandaloneJ2EEEjbJarModule msejbModule = new ManagedStandaloneJ2EEEjbJarModule(serverName, 134 moduleID); 135 msejbModule.stop(); 136 } catch (Exception e) { 137 throw new MBeanException(e); 138 } 139 } 140 141 142 private void startWEBModule(String moduleID, String serverName) 143 throws MBeanException { 144 145 try { 146 ManagedStandaloneJ2EEWebModule mswebModule = new ManagedStandaloneJ2EEWebModule(serverName, 147 moduleID); 148 mswebModule.start(); 149 } catch (Exception e) { 150 throw new MBeanException(e); 151 } 152 } 153 154 155 private void stopWEBModule(String moduleID, String serverName) 156 throws MBeanException { 157 158 try { 159 ManagedStandaloneJ2EEWebModule mswebModule = new ManagedStandaloneJ2EEWebModule(serverName, 160 moduleID); 161 mswebModule.stop(); 162 } catch (Exception e) { 163 throw new MBeanException(e); 164 } 165 } 166 167 168 private void startRARModule(String moduleID, String serverName) 169 throws MBeanException { 170 171 try { 172 ManagedStandaloneConnectorModule mscModule = new ManagedStandaloneConnectorModule(serverName, 173 moduleID); 174 mscModule.start(); 175 } catch (Exception e) { 176 throw new MBeanException(e); 177 } 178 } 179 180 181 private void stopRARModule(String moduleID, String serverName) 182 throws MBeanException { 183 184 try { 185 ManagedStandaloneConnectorModule mscModule = new ManagedStandaloneConnectorModule(serverName, 186 moduleID); 187 mscModule.stop(); 188 } catch (Exception e) { 189 throw new MBeanException(e); 190 } 191 } 192 193 194 private void startApplication(String appID, String serverName) 195 throws MBeanException { 196 197 try { 198 ManagedJ2EEApplication mApp = new ManagedJ2EEApplication(serverName, 199 appID); 200 mApp.start(); 201 } catch (Exception e) { 202 throw new MBeanException(e); 203 } 204 } 205 206 207 private void stopApplication(String appID, String serverName) 208 throws MBeanException { 209 210 try { 211 ManagedJ2EEApplication mApp = new ManagedJ2EEApplication(serverName, 212 appID); 213 mApp.stop(); 214 } catch (Exception e) { 215 throw new MBeanException(e); 216 } 217 } 218 219 220 private boolean standAlone(J2EEDeployedObjectMdl modObject) 221 throws MBeanException { 222 223 try { 224 ObjectName objName = new ObjectName(modObject.getobjectName()); 225 String appName = objName.getKeyProperty("J2EEApplication"); 226 227 if ((appName == null) || (appName.length() < 1) || 228 (appName.equals("null")) || (appName.equals("NULL")) || 229 (appName.equals(""))) { 230 return true; 231 } 232 } catch (Exception e) { 233 throw new MBeanException(e); 234 } 235 236 return false; 237 } 238 } 239 | Popular Tags |