1 23 24 package com.sun.enterprise.admin.monitor.registry.spi.reconfig; 25 26 import java.util.Iterator ; 27 import java.util.Map ; 28 import java.util.logging.Logger ; 29 import com.sun.enterprise.admin.monitor.registry.MonitoringLevel; 30 import com.sun.enterprise.admin.monitor.registry.MonitoredObjectType; 31 import com.sun.enterprise.admin.monitor.registry.StatsHolder; 32 import com.sun.enterprise.admin.monitor.registry.MonitoringLevelListener; 33 34 import com.sun.enterprise.admin.monitor.registry.spi.ValueListMap; 35 import com.sun.enterprise.admin.monitor.registry.spi.MonitoringRegistrationHelper; 36 import com.sun.enterprise.admin.common.constant.AdminConstants; 37 38 44 class JVMChangeHandler implements ChangeHandler { 45 46 private final ChangeHandler successor; 47 private final ValueListMap listeners; 48 private static final Logger logger = Logger.getLogger(AdminConstants.kLoggerName); 49 50 JVMChangeHandler(ChangeHandler successor, ValueListMap listeners) { 51 this.successor = successor; 52 this.listeners = listeners; 53 } 54 55 public void handleChange(MonitoredObjectType t, MonitoringLevel from, MonitoringLevel to) { 56 if (isJvmType(t)) { 57 handleChange(from, to, t); 58 } 59 else { 60 successor.handleChange(t, from, to); 61 } 62 } 63 64 private boolean isJvmType(MonitoredObjectType t) { 65 return (t == MonitoredObjectType.JVM); 66 } 67 68 private void handleChange(MonitoringLevel from, MonitoringLevel to, MonitoredObjectType t) { 69 if (off2Low(from, to) || off2High(from, to)) { 70 boolean threadInfo = false; 71 notifyListeners(from, to, t); 72 if(to == MonitoringLevel.HIGH) 74 threadInfo = true; 75 registerMBeans(threadInfo); 76 } 77 if (low2Off(from, to) || high2Off(from, to)) { 78 boolean threadInfo = false; 79 if(from == MonitoringLevel.HIGH) 81 threadInfo = true; 82 unregisterMBeans(threadInfo); 83 notifyListeners(from, to, t); 84 } 85 if (low2High(from, to)) { 86 notifyListeners(from, to, t); 88 registerThreadInfoMBeans(); 89 } 90 if (high2Low(from, to)) { 91 unregisterThreadInfoMBeans(); 93 notifyListeners(from, to, t); 94 } 95 96 } 97 98 private void notifyListeners(MonitoringLevel from, MonitoringLevel to, MonitoredObjectType t) { 99 logger.finer("DynamicReconfigurator: Now notifying the listeners for jvm stats --- from = " + from.toString() + " to = " + to.toString()); 100 final Map l = (Map )listeners.get(t); if (l == null) 102 return; final Iterator it = l.keySet().iterator(); 104 while (it.hasNext()) { 105 final MonitoringLevelListener ml = (MonitoringLevelListener)it.next(); 106 ml.changeLevel(from, to, t); 107 } 108 } 109 110 111 private void registerMBeans(boolean threadInfo) { 112 final MonitoringRegistrationHelper registryImpl = 113 (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance(); 114 115 final Iterator iter = registryImpl.getJvmNodes(threadInfo).iterator(); 116 while (iter.hasNext()) { 117 final StatsHolder c = (StatsHolder) iter.next(); 118 c.registerMBean(); 119 logger.finer("DynamicReconfigurator: Now Registering MBean for --- " + c.getName()); 120 } 121 } 122 123 private void unregisterMBeans(boolean threadInfo) { 124 final MonitoringRegistrationHelper registryImpl = 125 (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance(); 126 127 final Iterator iter = registryImpl.getJvmNodes(threadInfo).iterator(); 128 while (iter.hasNext()) { 129 final StatsHolder c = (StatsHolder) iter.next(); 130 c.unregisterMBean(); 131 logger.finer("DynamicReconfigurator: Now UnRegistering MBean for --- " + c.getName()); 132 } 133 } 134 135 136 private void registerThreadInfoMBeans() { 137 final MonitoringRegistrationHelper registryImpl = 138 (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance(); 139 140 final Iterator iter = registryImpl.getJvmThreadInfoNodes().iterator(); 141 while (iter.hasNext()) { 142 final StatsHolder c = (StatsHolder) iter.next(); 143 c.registerMBean(); 144 logger.finer("DynamicReconfigurator: Now Registering MBean for --- " + c.getName()); 145 } 146 } 147 148 149 private void unregisterThreadInfoMBeans() { 150 final MonitoringRegistrationHelper registryImpl = 151 (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance(); 152 153 final Iterator iter = registryImpl.getJvmThreadInfoNodes().iterator(); 154 while (iter.hasNext()) { 155 final StatsHolder c = (StatsHolder) iter.next(); 156 c.unregisterMBean(); 157 logger.finer("DynamicReconfigurator: Now UnRegistering MBean for --- " + c.getName()); 158 } 159 } 160 161 private boolean off2Low(MonitoringLevel from, MonitoringLevel to) { 162 return ( from == MonitoringLevel.OFF && to == MonitoringLevel.LOW ); 163 } 164 private boolean off2High(MonitoringLevel from, MonitoringLevel to) { 165 return ( from == MonitoringLevel.OFF && to == MonitoringLevel.HIGH ); 166 } 167 private boolean low2Off(MonitoringLevel from, MonitoringLevel to) { 168 return ( from == MonitoringLevel.LOW && to == MonitoringLevel.OFF); 169 } 170 private boolean high2Off(MonitoringLevel from, MonitoringLevel to) { 171 return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.OFF ); 172 } 173 private boolean low2High(MonitoringLevel from, MonitoringLevel to) { 174 return ( from == MonitoringLevel.LOW && to == MonitoringLevel.HIGH); 175 } 176 private boolean high2Low(MonitoringLevel from, MonitoringLevel to) { 177 return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.LOW ); 178 } 179 } 180 | Popular Tags |