1 23 24 26 27 package com.sun.enterprise.management.config; 28 29 import com.sun.enterprise.management.support.LBDeregistrationUtil; 30 import javax.management.ObjectName ; 31 32 import java.util.Collection ; 33 import java.util.Map ; 34 import java.util.HashMap ; 35 import java.util.ArrayList ; 36 import java.io.IOException ; 37 38 import javax.management.JMException ; 39 import javax.management.MBeanServer ; 40 import javax.management.ObjectName ; 41 42 import com.sun.appserv.management.base.XTypes; 43 import com.sun.enterprise.management.config.AMXConfigImplBase; 44 import com.sun.enterprise.management.support.Delegate; 45 import com.sun.enterprise.management.support.ObjectNames; 46 47 import static com.sun.appserv.management.base.XTypes.LOAD_BALANCER; 48 import static com.sun.appserv.management.base.XTypes.LOAD_BALANCER_MONITOR; 49 import static com.sun.appserv.management.base.AMX.J2EE_TYPE_KEY; 50 import static com.sun.appserv.management.base.AMX.NAME_KEY; 51 import static com.sun.appserv.management.base.AMX.JMX_DOMAIN; 52 53 import com.sun.appserv.management.base.Util; 54 import com.sun.appserv.management.base.AMXDebug; 55 import com.sun.appserv.management.monitor.LoadBalancerMonitor; 56 import com.sun.appserv.management.monitor.LoadBalancerClusterMonitor; 57 import com.sun.appserv.management.monitor.LoadBalancerServerMonitor; 58 import com.sun.appserv.management.monitor.LoadBalancerApplicationMonitor; 59 import com.sun.appserv.management.monitor.LoadBalancerContextRootMonitor; 60 import com.sun.appserv.management.config.DeployedItemRefConfig; 61 import com.sun.appserv.management.config.ClusterRefConfig; 62 import com.sun.appserv.management.config.ClusterConfig; 63 import com.sun.appserv.management.config.ServerRefConfig; 64 import com.sun.appserv.management.config.ServerConfig; 65 import com.sun.appserv.management.config.LoadBalancerConfig; 66 import com.sun.appserv.management.config.LBConfig; 67 import com.sun.appserv.management.client.ProxyFactory; 68 71 public final class ServerRefConfigImpl extends AMXConfigImplBase 72 implements ConfigFactoryCallback 73 { 74 ServerRefDeregistrationHelper mHelper = null; 76 77 public ServerRefConfigImpl(final Delegate delegate) 78 { 79 super(delegate); 80 } 81 82 83 public ObjectName getHealthCheckerConfigObjectName() 84 { 85 return(getContaineeObjectName(XTypes.HEALTH_CHECKER_CONFIG)); 86 } 87 88 private HealthCheckerConfigFactory getHealthCheckerConfigFactory() { 89 return new HealthCheckerConfigFactory(this); 90 } 91 92 public ObjectName 93 createHealthCheckerConfig( 94 String url, 95 String intervalInSeconds, 96 String timeoutInSeconds) 97 { 98 return getHealthCheckerConfigFactory().create( 99 url,intervalInSeconds, timeoutInSeconds); 100 } 101 102 public void removeHealthCheckerConfig(final String name) 103 { 104 final ObjectName item = getHealthCheckerConfigObjectName(); 105 getHealthCheckerConfigFactory().remove(item); 106 } 107 108 protected void unregisterMisc() { 109 try { 110 mHelper = new ServerRefDeregistrationHelper( 111 getName(), getMBeanServer()); 112 } catch (Exception ex) { 113 logWarning("ServerRefConfig unregisterMisc failed. " + 114 "ServerRefDeregistrationHelper creation failed"); 115 } 116 } 117 118 public void postDeregister() { 119 super.postDeregister(); 120 try { 121 if (getContainer() instanceof LBConfig) { 122 String lbConfigName = ((LBConfig)getContainer()).getName(); 125 Map <String ,LoadBalancerConfig> relevantLoadBalancerConfigMap = 126 mHelper.fetchLoadBalancerConfigs((LBConfig)getContainer()); 127 mHelper.unregisterMonitors(relevantLoadBalancerConfigMap); 128 } else if (getContainer() instanceof ClusterConfig) { 129 String clusterName = ((ClusterConfig)getContainer()).getName(); 130 Map <String ,LoadBalancerConfig> relevantLoadBalancerConfigMap = 131 mHelper.fetchLoadBalancerConfigs((ClusterConfig)getContainer()); 132 mHelper.unregisterMonitors(clusterName, relevantLoadBalancerConfigMap); 133 } 134 mHelper = null; 135 } catch (Exception ex) { 136 logWarning("ServerRefConfig postDeregistration failed. " + 137 "Load Balancer Monitoring MBeans might be lying around"); 138 } 139 } 140 141 private class ServerRefDeregistrationHelper { 142 143 final static String J2EE_TYPE = "j2eeType"; 144 final ObjectNames objectNames = ObjectNames.getInstance(JMX_DOMAIN); 145 String serverName = null; 146 MBeanServer mbs = null; 147 148 public ServerRefDeregistrationHelper(String serverName, MBeanServer mbs) { 149 this.mbs = mbs; 150 this.serverName = serverName; 151 } 152 153 void unregisterMonitors(Map <String ,LoadBalancerConfig> 154 relevantLoadBalancerConfigMap) throws JMException { 155 156 unregisterMonitors(serverName, relevantLoadBalancerConfigMap); 157 } 158 159 void unregisterMonitors(String clusterName, 160 Map <String ,LoadBalancerConfig> relevantLoadBalancerConfigMap) 161 throws JMException { 162 163 for (String loadBalancerName : relevantLoadBalancerConfigMap.keySet()) { 164 LoadBalancerMonitor loadBalancerMonitor = 165 LBDeregistrationUtil.getInstance(mbs). 166 fetchLBMonitoringRoot(loadBalancerName); 167 168 Map <String ,LoadBalancerClusterMonitor> loadBalancerClusterMonitorMap = 169 loadBalancerMonitor.getLoadBalancerClusterMonitorMap(); 170 171 LoadBalancerClusterMonitor loadBalancerClusterMonitor = 172 loadBalancerClusterMonitorMap.get(clusterName); 173 174 Map <String ,LoadBalancerServerMonitor> loadBalancerServerMonitorMap = 177 loadBalancerClusterMonitor.getLoadBalancerServerMonitorMap(); 178 179 for (String serverName : loadBalancerServerMonitorMap.keySet()) { 180 LoadBalancerServerMonitor loadBalancerServerMonitor = 181 loadBalancerServerMonitorMap.get(serverName); 182 Map <String ,LoadBalancerApplicationMonitor> 183 loadBalancerApplicationMonitorMap = 184 loadBalancerServerMonitor 185 .getLoadBalancerApplicationMonitorMap(); 186 187 for (String appName : loadBalancerApplicationMonitorMap.keySet()) { 188 LoadBalancerApplicationMonitor loadBalancerApplicationMonitor = 189 loadBalancerApplicationMonitorMap.get(appName); 190 Map <String ,LoadBalancerContextRootMonitor> 191 lbcrmm = loadBalancerApplicationMonitor 192 .getLoadBalancerContextRootMonitorMap(); 193 for (String ctxRootName : lbcrmm.keySet()) { 194 LoadBalancerContextRootMonitor loadBalancerContextRootMonitor = 195 lbcrmm.get(ctxRootName); 196 ObjectName loadBalancerContextRootMonitorObjName = 197 Util.getObjectName(loadBalancerContextRootMonitor); 198 mbs.unregisterMBean(loadBalancerContextRootMonitorObjName); 199 } 200 201 ObjectName loadBalancerApplicationMonitorObjName = 202 Util.getObjectName(loadBalancerApplicationMonitor); 203 mbs.unregisterMBean( 204 loadBalancerApplicationMonitorObjName); 205 } 206 207 ObjectName loadBalancerServerMonitorObjName = 208 Util.getObjectName(loadBalancerServerMonitor); 209 mbs.unregisterMBean(loadBalancerServerMonitorObjName); 210 } 211 212 ObjectName loadBalancerClusterMonitorObjName = 213 Util.getObjectName(loadBalancerClusterMonitor); 214 mbs.unregisterMBean(loadBalancerClusterMonitorObjName); 215 } 216 } 217 218 Map <String ,LoadBalancerConfig> fetchLoadBalancerConfigs( 219 LBConfig lbConfig) { 220 Map <String , LBConfig> lbConfigMap = new HashMap <String , LBConfig>(); 221 lbConfigMap.put(lbConfig.getName(), lbConfig); 222 return fetchLoadBalancerConfigs(lbConfigMap); 223 } 224 225 Map <String ,LoadBalancerConfig> fetchLoadBalancerConfigs( 226 ClusterConfig clusterConfig) { 227 228 String clusterName = clusterConfig.getName(); 229 Map <String ,LBConfig> allLBConfigMap = 231 getDomainRoot().getDomainConfig().getLBConfigMap(); 232 233 Map <String , LBConfig> relevantLBConfigMap = new HashMap <String , LBConfig>(); 234 for (String lbConfigName : allLBConfigMap.keySet()) { 235 LBConfig lbConfig = allLBConfigMap.get(lbConfigName); 236 Map <String ,ClusterRefConfig> clusterRefConfigMap = 237 lbConfig.getClusterRefConfigMap(); 238 for (String clusterRef : clusterRefConfigMap.keySet()) { 239 if (clusterRef.equals(clusterName)) { 240 relevantLBConfigMap.put(lbConfigName, lbConfig); 241 break; 242 } 243 } 244 } 245 return fetchLoadBalancerConfigs(relevantLBConfigMap); 246 } 247 248 private Map <String ,LoadBalancerConfig> fetchLoadBalancerConfigs( 249 Map <String , LBConfig> lbConfigMap) { 250 251 Map <String ,LoadBalancerConfig> relevantLoadBalancerConfigMap = 252 new HashMap <String ,LoadBalancerConfig>(); 253 254 for (String lbConfigName : lbConfigMap.keySet()) { 255 Map <String ,LoadBalancerConfig> allLoadBalancerConfigMap = 257 getDomainRoot().getDomainConfig().getLoadBalancerConfigMap(); 258 259 260 for (String loadBalancerName : allLoadBalancerConfigMap.keySet()) { 261 LoadBalancerConfig loadBalancerConfig = 262 allLoadBalancerConfigMap.get(loadBalancerName); 263 if (loadBalancerConfig.getLbConfigName().equals(lbConfigName)) 264 relevantLoadBalancerConfigMap.put( 265 loadBalancerName, loadBalancerConfig); 266 } 267 } 268 return relevantLoadBalancerConfigMap; 269 } 270 271 } 272 } | Popular Tags |