1 23 24 38 39 package com.sun.enterprise.admin.monitor.registry.spi.reconfig; 40 41 import java.util.Iterator ; 42 import java.util.logging.Logger ; 43 import com.sun.enterprise.admin.monitor.registry.MonitoringLevel; 44 import com.sun.enterprise.admin.monitor.registry.MonitoredObjectType; 45 import com.sun.enterprise.admin.monitor.registry.StatsHolder; 46 47 import com.sun.enterprise.admin.monitor.registry.spi.ValueListMap; 48 import com.sun.enterprise.admin.monitor.registry.spi.MonitoringRegistrationHelper; 49 import com.sun.enterprise.admin.common.constant.AdminConstants; 50 51 59 class ThreadPoolChangeHandler implements ChangeHandler { 60 61 private final ChangeHandler successor; 62 private final ValueListMap listeners; 63 64 private static final Logger logger = Logger.getLogger(AdminConstants.kLoggerName); 65 66 ThreadPoolChangeHandler(ChangeHandler successor, ValueListMap listeners) { 67 this.successor = successor; 68 this.listeners = listeners; 69 } 70 71 public void handleChange(MonitoredObjectType t, MonitoringLevel from, MonitoringLevel to) { 72 if (isThreadPoolType(t)) { 73 handleChange(from, to); 74 } 75 else { 76 successor.handleChange(t, from, to); 77 } 78 } 79 80 private boolean isThreadPoolType(MonitoredObjectType t) { 81 return ( t == MonitoredObjectType.THREAD_POOL ); 82 } 83 84 private void handleChange(MonitoringLevel from, MonitoringLevel to) { 85 if (off2Low(from, to) || off2High(from, to)) { 86 notifyListeners(from, to); 87 registerMBeans(); 88 } 89 if (low2Off(from, to) || high2Off(from, to)) { 90 unregisterMBeans(); 91 notifyListeners(from, to); 92 } 93 if (low2High(from, to) || high2Low(from, to)) { 94 } 96 } 97 98 private void notifyListeners(MonitoringLevel from, MonitoringLevel to) { 99 logger.finer("DynamicReconfigurator: Now notifying the listeners for Thread Pool stats --- from = " + from.toString() + " to = " + to.toString()); 100 } 101 102 private void registerMBeans() { 103 final MonitoringRegistrationHelper registryImpl = 104 (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance(); 105 107 final Iterator iter = registryImpl.getThreadPoolNodes().iterator(); 109 while (iter.hasNext()) { 110 final StatsHolder c = (StatsHolder) iter.next(); 111 c.registerMBean(); 112 logger.finer("DynamicReconfigurator: Now Registering MBean for --- " + c.getName()); 113 } 114 } 115 116 private void unregisterMBeans() { 117 final MonitoringRegistrationHelper registryImpl = 118 (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance(); 119 121 final Iterator iter = registryImpl.getThreadPoolNodes().iterator(); 122 while (iter.hasNext()) { 123 final StatsHolder c = (StatsHolder) iter.next(); 124 c.unregisterMBean(); 125 logger.finer("DynamicReconfigurator: Now UnRegistering MBean for --- " + c.getName()); 126 } 127 } 128 129 private boolean off2Low(MonitoringLevel from, MonitoringLevel to) { 130 return ( from == MonitoringLevel.OFF && to == MonitoringLevel.LOW ); 131 } 132 private boolean off2High(MonitoringLevel from, MonitoringLevel to) { 133 return ( from == MonitoringLevel.OFF && to == MonitoringLevel.HIGH ); 134 } 135 private boolean low2Off(MonitoringLevel from, MonitoringLevel to) { 136 return ( from == MonitoringLevel.LOW && to == MonitoringLevel.OFF); 137 } 138 private boolean high2Off(MonitoringLevel from, MonitoringLevel to) { 139 return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.OFF ); 140 } 141 private boolean low2High(MonitoringLevel from, MonitoringLevel to) { 142 return ( from == MonitoringLevel.LOW && to == MonitoringLevel.HIGH); 143 } 144 private boolean high2Low(MonitoringLevel from, MonitoringLevel to) { 145 return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.LOW ); 146 } 147 } 148 | Popular Tags |