1 23 24 38 39 package com.sun.enterprise.admin.monitor.registry.spi.reconfig; 40 41 import java.util.Iterator ; 42 import java.util.Map ; 43 import java.util.logging.Logger ; 44 import com.sun.enterprise.admin.monitor.registry.MonitoringLevel; 45 import com.sun.enterprise.admin.monitor.registry.MonitoredObjectType; 46 import com.sun.enterprise.admin.monitor.registry.StatsHolder; 47 import com.sun.enterprise.admin.monitor.registry.MonitoringLevelListener; 48 49 import com.sun.enterprise.admin.monitor.registry.spi.ValueListMap; 50 import com.sun.enterprise.admin.monitor.registry.spi.MonitoringRegistrationHelper; 51 import com.sun.enterprise.admin.common.constant.AdminConstants; 52 53 61 class EjbContainerChangeHandler implements ChangeHandler { 62 63 private final ChangeHandler successor; 64 private final ValueListMap listeners; 65 private static final Logger logger = Logger.getLogger(AdminConstants.kLoggerName); 66 67 EjbContainerChangeHandler(ChangeHandler successor, ValueListMap listeners) { 68 this.successor = successor; 69 this.listeners = listeners; 70 } 71 72 public void handleChange(MonitoredObjectType t, MonitoringLevel from, MonitoringLevel to) { 73 if (isEjbContainerType(t)) { 74 handleChange(from, to, t); 75 } 76 else { 77 successor.handleChange(t, from, to); 78 } 79 } 80 81 private boolean isEjbContainerType(MonitoredObjectType t) { 82 return (t == MonitoredObjectType.EJB || 83 t == MonitoredObjectType.BEAN_CACHE || 84 t == MonitoredObjectType.BEAN_METHOD || 85 t == MonitoredObjectType.BEAN_POOL || 86 t == MonitoredObjectType.ENTITY_BEAN || 87 t == MonitoredObjectType.STATEFUL_BEAN || 88 t == MonitoredObjectType.STATELESS_BEAN || 89 t == MonitoredObjectType.MESSAGE_DRIVEN_BEAN ); 90 } 91 92 private void handleChange(MonitoringLevel from, MonitoringLevel to, MonitoredObjectType t) { 93 if (off2Low(from, to) || off2High(from, to)) { 94 boolean includeMethods = false; 95 notifyListeners(from, to, t); 96 if(to == MonitoringLevel.HIGH) 98 includeMethods = true; 99 registerMBeans(includeMethods); 100 } 101 if (low2Off(from, to) || high2Off(from, to)) { 102 boolean includeMethods = false; 103 if(from == MonitoringLevel.HIGH) 105 includeMethods = true; 106 unregisterMBeans(includeMethods); 107 notifyListeners(from, to, t); 108 } 109 if (low2High(from, to)) { 110 notifyListeners(from, to, t); 112 registerMethodMBeans(); 113 } 114 if (high2Low(from, to)) { 115 unregisterMethodMBeans(); 117 notifyListeners(from, to, t); 118 } 119 120 } 121 122 private void notifyListeners(MonitoringLevel from, MonitoringLevel to, MonitoredObjectType t) { 123 logger.finer("DynamicReconfigurator: Now notifying the listeners for ejb stats --- from = " + from.toString() + " to = " + to.toString()); 124 final Map l = (Map )listeners.get(t); if (l == null) 126 return; final Iterator it = l.keySet().iterator(); 128 while (it.hasNext()) { 129 final MonitoringLevelListener ml = (MonitoringLevelListener)it.next(); 130 ml.changeLevel(from, to, t); 131 } 132 } 133 134 135 private void registerMBeans(boolean includeMethods) { 136 final MonitoringRegistrationHelper registryImpl = 137 (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance(); 138 140 final Iterator iter = registryImpl.getEjbContainerNodes(includeMethods).iterator(); 142 while (iter.hasNext()) { 143 final StatsHolder c = (StatsHolder) iter.next(); 144 c.registerMBean(); 145 logger.finer("DynamicReconfigurator: Now Registering MBean for --- " + c.getName()); 146 } 147 } 148 149 private void unregisterMBeans(boolean includeMethods) { 150 final MonitoringRegistrationHelper registryImpl = 151 (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance(); 152 154 final Iterator iter = registryImpl.getEjbContainerNodes(includeMethods).iterator(); 155 while (iter.hasNext()) { 156 final StatsHolder c = (StatsHolder) iter.next(); 157 c.unregisterMBean(); 158 logger.finer("DynamicReconfigurator: Now UnRegistering MBean for --- " + c.getName()); 159 } 160 } 161 162 163 private void registerMethodMBeans() { 164 final MonitoringRegistrationHelper registryImpl = 165 (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance(); 166 167 final Iterator iter = registryImpl.getEjbMethodNodes().iterator(); 168 while (iter.hasNext()) { 169 final StatsHolder c = (StatsHolder) iter.next(); 170 c.registerMBean(); 171 logger.finer("DynamicReconfigurator: Now Registering MBean for --- " + c.getName()); 172 } 173 } 174 175 176 private void unregisterMethodMBeans() { 177 final MonitoringRegistrationHelper registryImpl = 178 (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance(); 179 180 final Iterator iter = registryImpl.getEjbMethodNodes().iterator(); 181 while (iter.hasNext()) { 182 final StatsHolder c = (StatsHolder) iter.next(); 183 c.unregisterMBean(); 184 logger.finer("DynamicReconfigurator: Now UnRegistering MBean for --- " + c.getName()); 185 } 186 } 187 188 private boolean off2Low(MonitoringLevel from, MonitoringLevel to) { 189 return ( from == MonitoringLevel.OFF && to == MonitoringLevel.LOW ); 190 } 191 private boolean off2High(MonitoringLevel from, MonitoringLevel to) { 192 return ( from == MonitoringLevel.OFF && to == MonitoringLevel.HIGH ); 193 } 194 private boolean low2Off(MonitoringLevel from, MonitoringLevel to) { 195 return ( from == MonitoringLevel.LOW && to == MonitoringLevel.OFF); 196 } 197 private boolean high2Off(MonitoringLevel from, MonitoringLevel to) { 198 return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.OFF ); 199 } 200 private boolean low2High(MonitoringLevel from, MonitoringLevel to) { 201 return ( from == MonitoringLevel.LOW && to == MonitoringLevel.HIGH); 202 } 203 private boolean high2Low(MonitoringLevel from, MonitoringLevel to) { 204 return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.LOW ); 205 } 206 } 207 | Popular Tags |