1 23 24 27 28 package com.sun.enterprise.admin.mbeans; 29 30 import java.lang.IllegalArgumentException ; 31 32 import javax.management.AttributeList ; 34 import javax.management.Attribute ; 35 import javax.management.MBeanException ; 36 import javax.management.ReflectionException ; 37 import javax.management.AttributeNotFoundException ; 38 39 import com.sun.enterprise.admin.meta.MBeanRegistryFactory; 40 41 import com.sun.enterprise.admin.event.EventContext; 43 import com.sun.enterprise.admin.event.DynamicReconfigEvent; 44 45 import com.sun.enterprise.admin.config.BaseConfigMBean; 47 import com.sun.enterprise.config.serverbeans.ServerTags; 48 import com.sun.enterprise.admin.AdminContext; 49 50 import java.util.logging.Level ; 52 53 import com.sun.enterprise.admin.servermgmt.pe.PEInstancesManager; 54 import com.sun.enterprise.admin.servermgmt.RepositoryConfig; 55 import com.sun.enterprise.admin.servermgmt.RuntimeStatus; 56 import com.sun.enterprise.admin.servermgmt.InstanceException; 57 import com.sun.enterprise.util.SystemPropertyConstants; 58 import com.sun.enterprise.util.i18n.StringManager; 59 60 public class ConfigMBean extends BaseConfigMBean 61 { 62 63 69 public AttributeList setAttributes(AttributeList list) { 70 71 boolean bEnabled = false; 72 int reconfigIdx = -1; 73 if(list!=null) 74 for(int i=0; i<list.size(); i++) 75 { 76 Attribute attr = (Attribute )list.get(i); 77 if(ServerTags.DYNAMIC_RECONFIGURATION_ENABLED.equals(attr.getName())) 78 { 79 try { 80 bEnabled = validateDynamicReconfigEvent(attr.getValue()); 81 } catch(Exception e) { 82 reconfigIdx = i; 83 } 84 } 85 86 } 87 88 if (reconfigIdx != -1) { 89 list.remove(reconfigIdx); 90 } 91 list = super.setAttributes(list); 93 94 if (reconfigIdx != -1) { 95 return list; 96 } 97 98 if(list!=null) 100 for(int i=0; i<list.size(); i++) 101 { 102 Attribute attr = (Attribute )list.get(i); 103 if(ServerTags.DYNAMIC_RECONFIGURATION_ENABLED.equals(attr.getName())) 104 { 105 emitDynamicReconfigEvent(bEnabled); 106 } 107 108 } 109 return list; 110 } 111 112 125 public void setAttribute(Attribute attr) 126 throws AttributeNotFoundException , MBeanException , ReflectionException 127 { 128 boolean bEnabled = false; 129 if(ServerTags.DYNAMIC_RECONFIGURATION_ENABLED.equals(attr.getName())) 131 { 132 bEnabled = validateDynamicReconfigEvent(attr.getValue()); 133 } 134 super.setAttribute(attr); 136 if(ServerTags.DYNAMIC_RECONFIGURATION_ENABLED.equals(attr.getName())) 137 { 138 emitDynamicReconfigEvent(bEnabled); 139 } 140 } 141 142 private boolean validateDynamicReconfigEvent(Object value) throws IllegalArgumentException , MBeanException 143 { 144 boolean bEnabled = false; 145 if(value instanceof Boolean ) 146 bEnabled = ((Boolean )value).booleanValue(); 147 else 148 if("true".equalsIgnoreCase(value.toString()) || 149 "yes".equalsIgnoreCase(value.toString()) ) 150 bEnabled = true; 151 152 boolean restartRequired = false; 153 try { 154 restartRequired = getRuntimeStatus().isRestartNeeded(); 155 } catch(InstanceException ie) { 156 throw new MBeanException (ie); 157 } 158 159 if((bEnabled == true) && ( restartRequired == true)) { 160 String msg = _strMgr.getString( 161 "admin.mbeans.configMBean.serverRequiresRestart"); 162 Exception e = new Exception (msg); 163 throw new MBeanException (e,msg); 164 } 165 166 return bEnabled; 167 } 168 private void emitDynamicReconfigEvent(boolean bEnabled) 169 { 170 try 171 { 172 AdminContext adminContext = MBeanRegistryFactory.getAdminContext(); 173 String instanceName = adminContext.getServerName(); 174 int action = bEnabled?DynamicReconfigEvent.ACTION_ENABLED:DynamicReconfigEvent.ACTION_DISABLED; 175 DynamicReconfigEvent event = new DynamicReconfigEvent(instanceName, action); 176 String configName = (String )getAttribute(ServerTags.NAME); 177 event.setTargetDestination(configName); 178 EventContext.addEvent(event); 179 } 180 catch (Exception e) 181 { 182 e.printStackTrace(); 183 184 } 186 } 187 188 private RuntimeStatus getRuntimeStatus() throws InstanceException 189 { 190 String serverName = 191 System.getProperty(SystemPropertyConstants.SERVER_NAME); 192 PEInstancesManager manager = new PEInstancesManager(new RepositoryConfig()); 193 return RuntimeStatus.getRuntimeStatus(serverName, manager); 194 } 195 197 private static final StringManager _strMgr = 198 StringManager.getManager(ConfigMBean.class); 199 201 } 202 | Popular Tags |