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 ConnectionPoolChangeHandler 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 ConnectionPoolChangeHandler(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 (isConnectionPoolType(t)) { 74 handleChange(from, to, t); 75 } 76 else { 77 successor.handleChange(t, from, to); 78 } 79 } 80 private boolean isConnectionPoolType(MonitoredObjectType t) { 83 return ( t == MonitoredObjectType.CONNECTOR_CONN_POOL || 84 t == MonitoredObjectType.JDBC_CONN_POOL || 85 t == MonitoredObjectType.CONNECTOR_SERVICE || 86 t == MonitoredObjectType.JMS_SERVICE); 87 } 88 89 private void handleChange(MonitoringLevel from, MonitoringLevel to, MonitoredObjectType t) { 90 if (off2Low(from, to) || off2High(from, to)) { 91 notifyListeners(from, to, t); 92 registerMBeans(t); 93 } 94 if (low2Off(from, to) || high2Off(from, to)) { 95 unregisterMBeans(t); 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: Now notifying the listeners for connection-pool stats --- from = " + from.toString() + " to = " + to.toString()); 105 assert ( t == MonitoredObjectType.JDBC_CONN_POOL || 106 t == MonitoredObjectType.CONNECTOR_CONN_POOL || 107 t == MonitoredObjectType.CONNECTOR_SERVICE || 108 t == MonitoredObjectType.JMS_SERVICE); 109 110 final Map l = (Map )listeners.get(t); if (l == null) 112 return; final Iterator it = l.keySet().iterator(); 114 while (it.hasNext()) { 115 final MonitoringLevelListener ml = (MonitoringLevelListener)it.next(); 116 ml.changeLevel(from, to, t); 117 } 118 } 119 120 private void registerMBeans(MonitoredObjectType t) { 121 final MonitoringRegistrationHelper registryImpl = 122 (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance(); 123 Iterator iter = null; 125 if(t == MonitoredObjectType.JDBC_CONN_POOL) 126 iter = registryImpl.getConnectionPoolNodes(t).iterator(); 127 else 128 iter = registryImpl.getConnectorRelatedNodes().iterator(); 129 while (iter.hasNext()) { 130 final StatsHolder c = (StatsHolder) iter.next(); 131 c.registerMBean(); 132 logger.finer("DynamicReconfigurator: Now Registering MBean for --- " + c.getName()); 133 } 134 } 135 136 private void unregisterMBeans(MonitoredObjectType t) { 137 final MonitoringRegistrationHelper registryImpl = 138 (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance(); 139 141 Iterator iter = null; 143 if(t == MonitoredObjectType.JDBC_CONN_POOL) 144 iter = registryImpl.getConnectionPoolNodes(t).iterator(); 145 else 146 iter = registryImpl.getConnectorRelatedNodes().iterator(); 147 while (iter.hasNext()) { 148 final StatsHolder c = (StatsHolder) iter.next(); 149 c.unregisterMBean(); 150 logger.finer("DynamicReconfigurator: Now UnRegistering MBean for --- " + c.getName()); 151 } 152 } 153 private boolean off2Low(MonitoringLevel from, MonitoringLevel to) { 154 return ( from == MonitoringLevel.OFF && to == MonitoringLevel.LOW ); 155 } 156 private boolean off2High(MonitoringLevel from, MonitoringLevel to) { 157 return ( from == MonitoringLevel.OFF && to == MonitoringLevel.HIGH ); 158 } 159 private boolean low2Off(MonitoringLevel from, MonitoringLevel to) { 160 return ( from == MonitoringLevel.LOW && to == MonitoringLevel.OFF); 161 } 162 private boolean high2Off(MonitoringLevel from, MonitoringLevel to) { 163 return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.OFF ); 164 } 165 private boolean low2High(MonitoringLevel from, MonitoringLevel to) { 166 return ( from == MonitoringLevel.LOW && to == MonitoringLevel.HIGH); 167 } 168 private boolean high2Low(MonitoringLevel from, MonitoringLevel to) { 169 return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.LOW ); 170 } 171 } 172 | Popular Tags |