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.MonitoringLevelListener; 46 import com.sun.enterprise.admin.monitor.registry.MonitoredObjectType; 47 import com.sun.enterprise.admin.monitor.registry.StatsHolder; 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 HttpServiceChangeHandler implements ChangeHandler { 62 63 private final ChangeHandler successor; 64 private final ValueListMap listeners; 65 66 private static final Logger logger = Logger.getLogger(AdminConstants.kLoggerName); 67 HttpServiceChangeHandler(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 (isHttpServiceType(t)) { 74 handleChange(from, to, t); 75 } 76 else { 77 successor.handleChange(t, from, to); 78 } 79 } 80 81 private boolean isHttpServiceType(MonitoredObjectType t) { 82 return ( t == MonitoredObjectType.HTTP_LISTENER || 83 t == MonitoredObjectType.VIRTUAL_SERVER || 84 t == MonitoredObjectType.HTTP_SERVICE ); 85 } 86 87 private void handleChange(MonitoringLevel from, MonitoringLevel to, MonitoredObjectType t) { 88 final Map lsnrs = (Map ) listeners.get(t); 89 if (off2Low(from, to) || off2High(from, to)) { 90 if(lsnrs != null) 91 notifyListeners(from, to, t); 92 registerMBeans(); 93 } 94 if (low2Off(from, to) || high2Off(from, to)) { 95 if(lsnrs != null) 96 notifyListeners(from, to, t); 97 else 98 unregisterMBeans(); 99 } 100 if (low2High(from, to) || high2Low(from, to)) { 101 } 103 } 104 105 private void notifyListeners(MonitoringLevel from, MonitoringLevel to, MonitoredObjectType t) { 106 logger.finer("DynamicReconfigurator: Now notifying the listeners for http service --- from = " + from.toString() + " to = " + to.toString()); 107 final Map l = (Map )listeners.get(t); if (l == null) 109 return; final Iterator it = l.keySet().iterator(); 111 while (it.hasNext()) { 112 final MonitoringLevelListener ml = (MonitoringLevelListener)it.next(); 113 ml.changeLevel(from, to, t); 114 } 115 } 116 117 private void registerMBeans() { 118 final MonitoringRegistrationHelper registryImpl = 119 (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance(); 120 122 final Iterator iter = registryImpl.getHttpServiceNodes().iterator(); 124 while (iter.hasNext()) { 125 final StatsHolder c = (StatsHolder) iter.next(); 126 c.registerMBean(); 127 logger.finer("DynamicReconfigurator: Now Registering MBean for --- " + c.getName()); 128 } 129 } 130 131 private void unregisterMBeans() { 132 final MonitoringRegistrationHelper registryImpl = 133 (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance(); 134 136 final Iterator iter = registryImpl.getHttpServiceNodes().iterator(); 137 while (iter.hasNext()) { 138 final StatsHolder c = (StatsHolder) iter.next(); 139 c.unregisterMBean(); 140 logger.finer("DynamicReconfigurator: Now UnRegistering MBean for --- " + c.getName()); 141 } 142 } 143 144 private boolean off2Low(MonitoringLevel from, MonitoringLevel to) { 145 return ( from == MonitoringLevel.OFF && to == MonitoringLevel.LOW ); 146 } 147 private boolean off2High(MonitoringLevel from, MonitoringLevel to) { 148 return ( from == MonitoringLevel.OFF && to == MonitoringLevel.HIGH ); 149 } 150 private boolean low2Off(MonitoringLevel from, MonitoringLevel to) { 151 return ( from == MonitoringLevel.LOW && to == MonitoringLevel.OFF); 152 } 153 private boolean high2Off(MonitoringLevel from, MonitoringLevel to) { 154 return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.OFF ); 155 } 156 private boolean low2High(MonitoringLevel from, MonitoringLevel to) { 157 return ( from == MonitoringLevel.LOW && to == MonitoringLevel.HIGH); 158 } 159 private boolean high2Low(MonitoringLevel from, MonitoringLevel to) { 160 return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.LOW ); 161 } 162 } 163 | Popular Tags |