1 19 24 25 package org.netbeans.modules.j2ee.sun.ide.j2ee.mbmapping; 26 27 import javax.management.Attribute ; 28 import javax.management.MBeanInfo ; 29 import javax.management.ObjectName ; 30 import javax.management.AttributeList ; 31 import javax.management.MBeanAttributeInfo ; 32 import javax.management.MBeanServerConnection ; 33 import javax.management.MBeanException ; 34 import javax.management.ReflectionException ; 35 import javax.management.InstanceNotFoundException ; 36 import javax.management.AttributeNotFoundException ; 37 import javax.management.InvalidAttributeValueException ; 38 39 import java.rmi.RemoteException ; 40 41 42 43 44 46 50 public class JvmOptions extends ModuleMBean implements Constants{ 51 52 private ObjectName configObjName = null; 53 private boolean isServerEightOne = true; 54 55 public JvmOptions(MBeanServerConnection in_conn) { 56 super(in_conn); 57 this.configObjName = createConfigObjectName(); 58 this.runtimeObjName = configObjName; 59 } 60 61 public JvmOptions(ObjectName objName, MBeanServerConnection in_conn) { 62 super(objName, in_conn); 63 this.configObjName = createConfigObjectName(); 64 } 65 66 public JvmOptions(ObjectName objName, MBeanServerConnection in_conn, boolean in_isServerEightOne) { 67 super(objName, in_conn); 68 this.configObjName = createConfigObjectName(); 69 this.isServerEightOne = in_isServerEightOne; 70 } 71 72 private ObjectName createConfigObjectName(){ 73 ObjectName configName = null; 74 try{ 75 configName = new ObjectName (this.MAP_JVMOptions); 76 }catch(Exception ex){ 77 return null; 78 } 79 return configName; 80 } 81 82 public ObjectName getConfigObjectName(){ 83 return configObjName; 84 } 85 public AttributeList getAttributes(String [] attributes){ 86 AttributeList attList = null; 87 try{ 88 String addrValue = getAddressValue(); 89 Attribute jpdaAttr = null; 90 if(isSharedMemory()){ 91 if(isWindows()) 93 jpdaAttr = new Attribute (SHARED_MEM, (Object )addrValue); 94 else{ 95 Attribute newAttr = new Attribute (DEBUG_OPTIONS, DEF_DEUG_OPTIONS_SOCKET); 97 this.setAttribute(newAttr); 98 Integer value = new Integer (11000); 99 jpdaAttr = new Attribute (JPDA_PORT, value); 100 } 101 }else{ 102 Integer value = new Integer (addrValue); 103 jpdaAttr = new Attribute (JPDA_PORT, (Object )value); 104 } 105 attList = this.conn.getAttributes(this.configObjName, attributes); 106 attList.add(jpdaAttr); 107 }catch(Exception ex){ 108 return attList; 109 } 111 return attList; 112 } 113 114 public MBeanInfo getMBeanInfo() { 115 MBeanInfo updatedInfo = null; 116 try{ 117 MBeanInfo newInfo = this.conn.getMBeanInfo(this.configObjName); 118 119 MBeanAttributeInfo [] newAttrInfo = newInfo.getAttributes(); 121 int size = newAttrInfo.length + 1; 122 MBeanAttributeInfo [] updatedAttrInfo = new MBeanAttributeInfo [size]; 123 for ( int i=0; i<newAttrInfo.length; i++ ) { 125 updatedAttrInfo[i] = newAttrInfo[i]; 126 } 127 128 if(isSharedMemory() && isWindows()) 130 updatedAttrInfo[size-1] = new MBeanAttributeInfo (SHARED_MEM, "java.lang.String", "Shared Memory", true, true, false); else 132 updatedAttrInfo[size-1] = new MBeanAttributeInfo (JPDA_PORT, "int", "JPDA port number", true, true, false); 134 updatedInfo = new MBeanInfo (newInfo.getClassName(), newInfo.getDescription(), updatedAttrInfo, newInfo.getConstructors(), 135 newInfo.getOperations(), newInfo.getNotifications()); 136 137 }catch(Exception ex){ 138 return updatedInfo; 140 } 141 return updatedInfo; 142 } 143 144 public void setAttribute(Attribute attribute) throws RemoteException , InstanceNotFoundException , AttributeNotFoundException , 145 InvalidAttributeValueException , MBeanException , ReflectionException , java.io.IOException { 146 if(attribute.getName().equals(this.JPDA_PORT)){ 147 if(attribute.getValue() != null){ 148 setAddressValue(attribute.getValue().toString()); 149 } 150 }else if(attribute.getName().equals(this.SHARED_MEM)){ 151 if(attribute.getValue() != null){ 152 setAddressValue(attribute.getValue().toString()); 153 } 154 }else if(attribute.getName().equals(this.DEBUG_OPTIONS)){ 155 if((attribute.getValue() != null) && (attribute.getValue().toString().indexOf(ISMEM) == -1)){ 157 this.conn.setAttribute(this.configObjName, attribute); 158 }else{ 159 if(isWindows()){ 160 this.conn.setAttribute(this.configObjName, attribute); 161 } 162 } 165 }else{ 166 this.conn.setAttribute(this.configObjName, attribute); 167 } 168 } 169 170 private String getDebugOptions(){ 171 Object debugOptionsAttr = getConfigAttributeValue(DEBUG_OPTIONS); 172 String debugOptionsVal = null; 173 if(debugOptionsAttr != null){ 174 debugOptionsVal = debugOptionsAttr.toString().trim(); 175 } 176 return debugOptionsVal; 177 } 178 179 public String getAddressValue(){ 180 String debugOptionsVal = getDebugOptions(); 181 if(debugOptionsVal != null){ 182 debugOptionsVal = debugOptionsVal.substring(debugOptionsVal.indexOf(DEBUG_OPTIONS_ADDRESS)+DEBUG_OPTIONS_ADDRESS.length(), debugOptionsVal.length()); 183 int hasMore = debugOptionsVal.indexOf(","); if(hasMore != -1){ 185 debugOptionsVal = debugOptionsVal.substring(0, hasMore); 186 } 187 } 188 return debugOptionsVal; 189 } 190 191 public void setAddressValue(String portNumber){ 192 try{ 193 String debugOptionsVal = getDebugOptions(); 194 String debugOptionsStart = debugOptionsVal.substring(0, debugOptionsVal.indexOf(DEBUG_OPTIONS_ADDRESS) + DEBUG_OPTIONS_ADDRESS.length()); 195 debugOptionsStart = debugOptionsStart + portNumber; 196 String inMiddle = debugOptionsVal.substring(debugOptionsVal.indexOf(DEBUG_OPTIONS_ADDRESS) + DEBUG_OPTIONS_ADDRESS.length(), debugOptionsVal.length()); 197 int hasMore = inMiddle.indexOf(","); if(hasMore != -1){ 199 String debugOptionsEnd = inMiddle.substring(hasMore, inMiddle.length()); 200 debugOptionsStart = debugOptionsStart + debugOptionsEnd; 201 } 202 Attribute newAttr = new Attribute (DEBUG_OPTIONS, debugOptionsStart); 203 this.setAttribute(newAttr); 204 }catch(Exception ex){ 205 } 207 } 208 209 public String getClassPath(){ 210 String serverClassPath = getConfigAttributeValue("server_classpath"); return serverClassPath; 212 } 213 214 public void setClassPath(String classpath){ 215 try{ 216 Attribute classPathAttr = new Attribute ("server_classpath", classpath); this.setAttribute(classPathAttr); 218 }catch(Exception ex){ 219 } 221 } 222 223 public String getConfigAttributeValue(String attributeName){ 224 return super.getAttribute(this.configObjName, attributeName); 225 } 226 227 public boolean isSharedMemory(){ 229 boolean isShared = false; 230 String debugOpt = getDebugOptions(); 231 if((debugOpt.indexOf(ISMEM) == -1) && (debugOpt.indexOf(ISSOCKET) == -1)){ 232 try{ 233 Attribute attr = null; 234 if(this.isServerEightOne) 235 attr = new Attribute (DEBUG_OPTIONS, DEF_DEUG_OPTIONS_81); 236 else 237 attr = new Attribute (DEBUG_OPTIONS, DEF_DEUG_OPTIONS); 238 setAttribute(attr); 239 }catch(Exception ex){ 240 } 242 }else if(debugOpt.indexOf(ISSOCKET) != -1){ 243 String addrValue = getAddressValue(); 244 Integer value = null; 245 try{ 246 value = new Integer (addrValue); 247 }catch(Exception ex){ 248 if(this.isServerEightOne){ 249 value = new Integer (9009); 250 setAddressValue("9009"); }else{ 252 value = new Integer (1044); 253 setAddressValue("1044"); } 255 } 256 }else if (debugOpt.indexOf(ISMEM) != -1){ 257 return true; 258 } 259 return isShared; 260 } 261 262 public boolean isWindows(){ 264 Object javaHome = getConfigAttributeValue(JAVA_HOME); 265 if (javaHome==null){ return false; 267 } 268 try{ 269 String local_osName = System.getProperty("os.name"); if(local_osName.toLowerCase().indexOf("windows") != -1) return true; 274 else 275 return false; 276 282 } 283 catch (IndexOutOfBoundsException ee){ 284 return false; 285 } 286 } 287 288 295 public void setDefaultTransportForDebug(String addressVal) { 296 Attribute newAttr = null; 297 if(isWindows()){ 298 String value = DEF_DEUG_OPTIONS_SHMEM; 299 if(addressVal != null) 300 value = value + addressVal; 301 else 302 value = value + "defaultAddress"; newAttr = new Attribute (DEBUG_OPTIONS, value); 304 }else{ 305 if((getAddressValue().equals("1044")) || (getAddressValue().equals("9009"))) { newAttr = new Attribute (DEBUG_OPTIONS, DEF_DEUG_OPTIONS_SOCKET); 307 } 308 } 309 try{ 310 if(newAttr != null){ 311 this.setAttribute(newAttr); 312 } 313 }catch(Exception ex){} 314 } 315 316 } 317 | Popular Tags |