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 WebContainerChangeHandler implements ChangeHandler { 62 63 private final ChangeHandler successor; 64 private MonitoringRegistrationHelper registryImpl; 65 private final ValueListMap listeners; 66 67 private static final Logger logger = Logger.getLogger(AdminConstants.kLoggerName); 68 69 WebContainerChangeHandler(ChangeHandler successor, ValueListMap listeners) { 70 this.successor = successor; 71 this.listeners = listeners; 72 } 73 74 public void handleChange(MonitoredObjectType t, MonitoringLevel from, MonitoringLevel to) { 75 if (isWebContainerType(t)) { 76 handleChange(from, to, t); 77 } 78 else { 79 successor.handleChange(t, from, to); 80 } 81 } 82 83 private boolean isWebContainerType(MonitoredObjectType t) { 84 return ( t == MonitoredObjectType.SERVLET || 85 t == MonitoredObjectType.WEBMODULE); 86 } 87 88 private void handleChange(MonitoringLevel from, MonitoringLevel to, 89 MonitoredObjectType t) { 90 if (off2Low(from, to) || off2High(from, to)) { 91 notifyListeners(from, to, t); 92 registerMBeans(); 93 } 94 if (low2Off(from, to) || high2Off(from, to)) { 95 unregisterMBeans(); 96 notifyListeners(from, to, t); 97 } 98 if (low2High(from, to) || high2Low(from, to)) { 99 } 101 } 102 103 private void notifyListeners(MonitoringLevel from, MonitoringLevel to, MonitoredObjectType t) { 104 logger.finer("DynamicReconfigurator: Notifying the listeners for web container --- from = " + from.toString() + " to = " + to.toString()); 105 final Map l = (Map )listeners.get(t); if (l == null) 107 return; final Iterator it = l.keySet().iterator(); 109 while (it.hasNext()) { 110 final MonitoringLevelListener ml = (MonitoringLevelListener)it.next(); 111 ml.changeLevel(from, to, t); 112 } 113 } 114 115 private void registerMBeans() { 116 final MonitoringRegistrationHelper registryImpl = 117 (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance(); 118 120 final Iterator iter = registryImpl.getWebContainerNodes().iterator(); 122 while (iter.hasNext()) { 123 final StatsHolder c = (StatsHolder) iter.next(); 124 c.registerMBean(); 125 logger.finer("DynamicReconfigurator: Now Registering MBean for --- " + c.getName()); 126 } 127 } 128 129 private void unregisterMBeans() { 130 final MonitoringRegistrationHelper registryImpl = 131 (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance(); 132 134 final Iterator iter = registryImpl.getWebContainerNodes().iterator(); 135 while (iter.hasNext()) { 136 final StatsHolder c = (StatsHolder) iter.next(); 137 c.unregisterMBean(); 138 logger.finer("DynamicReconfigurator: Now UnRegistering MBean for --- " + c.getName()); 139 } 140 } 141 142 private boolean off2Low(MonitoringLevel from, MonitoringLevel to) { 143 return ( from == MonitoringLevel.OFF && to == MonitoringLevel.LOW ); 144 } 145 private boolean off2High(MonitoringLevel from, MonitoringLevel to) { 146 return ( from == MonitoringLevel.OFF && to == MonitoringLevel.HIGH ); 147 } 148 private boolean low2Off(MonitoringLevel from, MonitoringLevel to) { 149 return ( from == MonitoringLevel.LOW && to == MonitoringLevel.OFF); 150 } 151 private boolean high2Off(MonitoringLevel from, MonitoringLevel to) { 152 return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.OFF ); 153 } 154 private boolean low2High(MonitoringLevel from, MonitoringLevel to) { 155 return ( from == MonitoringLevel.LOW && to == MonitoringLevel.HIGH); 156 } 157 private boolean high2Low(MonitoringLevel from, MonitoringLevel to) { 158 return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.LOW ); 159 } 160 } 161 | Popular Tags |