1 23 24 26 27 package com.sun.enterprise.management.config; 28 29 import com.sun.enterprise.management.support.LBDeregistrationUtil; 30 import com.sun.enterprise.management.support.ObjectNames; 31 import javax.management.ObjectName ; 32 33 import com.sun.enterprise.management.config.AMXConfigImplBase; 34 import com.sun.enterprise.management.support.Delegate; 35 36 import com.sun.enterprise.management.support.AMXAttributeNameMapper; 37 38 import java.util.Collection ; 39 import java.util.Map ; 40 import java.util.HashMap ; 41 import java.util.ArrayList ; 42 import java.io.IOException ; 43 44 import javax.management.InstanceNotFoundException ; 45 import javax.management.JMException ; 46 import javax.management.MBeanServer ; 47 import javax.management.ObjectName ; 48 49 import static com.sun.appserv.management.base.XTypes.LOAD_BALANCER; 50 import static com.sun.appserv.management.base.XTypes.LOAD_BALANCER_MONITOR; 51 import static com.sun.appserv.management.base.AMX.J2EE_TYPE_KEY; 52 import static com.sun.appserv.management.base.AMX.NAME_KEY; 53 import static com.sun.appserv.management.base.AMX.JMX_DOMAIN; 54 55 import com.sun.appserv.management.base.Util; 56 import com.sun.appserv.management.base.AMXDebug; 57 import com.sun.appserv.management.monitor.LoadBalancerMonitor; 58 import com.sun.appserv.management.monitor.LoadBalancerClusterMonitor; 59 import com.sun.appserv.management.monitor.LoadBalancerServerMonitor; 60 import com.sun.appserv.management.monitor.LoadBalancerApplicationMonitor; 61 import com.sun.appserv.management.monitor.LoadBalancerContextRootMonitor; 62 import com.sun.appserv.management.config.DeployedItemRefConfig; 63 import com.sun.appserv.management.config.ClusterRefConfig; 64 import com.sun.appserv.management.config.ClusterConfig; 65 import com.sun.appserv.management.config.ServerRefConfig; 66 import com.sun.appserv.management.config.ServerConfig; 67 import com.sun.appserv.management.config.LoadBalancerConfig; 68 import com.sun.appserv.management.config.LBConfig; 69 import com.sun.appserv.management.client.ProxyFactory; 70 74 public final class DeployedItemRefConfigImpl extends AMXConfigImplBase 75 { 76 DeployedItemRefDeRegistrationHelper mHelper = null; 77 78 public 79 DeployedItemRefConfigImpl( final Delegate delegate ) 80 { 81 super( delegate ); 82 } 83 84 93 94 protected void unregisterMisc() { 95 try { 96 mHelper = new DeployedItemRefDeRegistrationHelper( 97 getName(), getMBeanServer()); 98 } catch (Exception ex) { 99 logWarning("DeployedItemRefConfig unregisterMisc failed. " + 100 "DeployedItemRefDeregistrationHelper creation failed"); 101 } 102 } 103 104 public void postDeregister() { 105 super.postDeregister(); 106 try { 107 108 Map <String ,LoadBalancerConfig> relevantLoadBalancerConfigMap = 109 new HashMap <String ,LoadBalancerConfig>(); 110 if (getContainer() instanceof ServerConfig) { 111 relevantLoadBalancerConfigMap = 112 mHelper.fetchLoadBalancerConfigs((ServerConfig)getContainer()); 113 mHelper.unregisterMonitors(relevantLoadBalancerConfigMap); 114 } else if (getContainer() instanceof ClusterConfig) { 115 relevantLoadBalancerConfigMap = 116 mHelper.fetchLoadBalancerConfigs((ClusterConfig)getContainer()); 117 mHelper.unregisterMonitors(relevantLoadBalancerConfigMap); 118 } 119 mHelper = null; 120 } catch (Exception ex) { 121 logWarning("DeployedItemRef postDeregistration failed. " + 122 "Load Balancer Monitoring MBeans might be lying around " + 123 "if this application is being load balanced " ); 124 } 125 } 126 127 private class DeployedItemRefDeRegistrationHelper { 128 129 final static String J2EE_TYPE = "j2eeType"; 130 final ObjectNames objectNames = ObjectNames.getInstance(JMX_DOMAIN); 131 String appName = null; 132 MBeanServer mbs = null; 133 134 public DeployedItemRefDeRegistrationHelper(String appName, MBeanServer mbs) { 135 this.mbs = mbs; 136 this.appName = appName; 137 } 138 139 void unregisterMonitors( 140 Map <String ,LoadBalancerConfig> relevantLoadBalancerConfigMap) 141 throws JMException { 142 143 for (String loadBalancerName : relevantLoadBalancerConfigMap.keySet()) { 144 LoadBalancerConfig loadBalancerConfig = 145 relevantLoadBalancerConfigMap.get(loadBalancerName); 146 LoadBalancerMonitor loadBalancerMonitor = 147 LBDeregistrationUtil.getInstance(mbs) 148 .fetchLBMonitoringRoot(loadBalancerName); 149 Collection <LoadBalancerApplicationMonitor> lbamList = 150 fetchLoadBalancerApplicationMonitors(appName, loadBalancerMonitor); 151 for (LoadBalancerApplicationMonitor lbam : lbamList) { 152 Map <String ,LoadBalancerContextRootMonitor> 153 lbcrmm = lbam.getLoadBalancerContextRootMonitorMap(); 154 for (String ctxRootName : lbcrmm.keySet()) { 155 LoadBalancerContextRootMonitor loadBalancerContextRootMonitor = 156 lbcrmm.get(ctxRootName); 157 ObjectName loadBalancerContextRootMonitorObjName = 158 Util.getObjectName(loadBalancerContextRootMonitor); 159 mbs.unregisterMBean(loadBalancerContextRootMonitorObjName); 160 } 161 ObjectName lbamObjName = Util.getObjectName(lbam); 162 mbs.unregisterMBean(lbamObjName); 163 } 164 } 165 } 166 167 Map <String ,LoadBalancerConfig> fetchLoadBalancerConfigs( 168 ClusterConfig clusterConfig) { 169 170 String clusterName = clusterConfig.getName(); 171 Map <String ,LBConfig> allLBConfigMap = 173 getDomainRoot().getDomainConfig().getLBConfigMap(); 174 175 Map <String , LBConfig> relevantLBConfigMap = new HashMap <String , LBConfig>(); 176 for (String lbConfigName : allLBConfigMap.keySet()) { 177 LBConfig lbConfig = allLBConfigMap.get(lbConfigName); 178 Map <String ,ClusterRefConfig> clusterRefConfigMap = 179 lbConfig.getClusterRefConfigMap(); 180 for (String clusterRef : clusterRefConfigMap.keySet()) { 181 if (clusterRef.equals(clusterName)) { 182 relevantLBConfigMap.put(lbConfigName, lbConfig); 183 break; 184 } 185 } 186 } 187 return fetchLoadBalancerConfigs(relevantLBConfigMap); 188 } 189 190 Map <String ,LoadBalancerConfig> fetchLoadBalancerConfigs( 191 ServerConfig serverConfig) { 192 193 Map <String , LBConfig> relevantLBConfigMap = new HashMap <String , LBConfig>(); 194 195 String serverName = serverConfig.getName(); 196 197 Map <String ,LBConfig> allLBConfigMap = 199 getDomainRoot().getDomainConfig().getLBConfigMap(); 200 Map <String ,ClusterConfig> allClusterConfigMap = 202 getDomainRoot().getDomainConfig().getClusterConfigMap(); 203 204 for (String lbConfigName : allLBConfigMap.keySet()) { 205 LBConfig lbConfig = allLBConfigMap.get(lbConfigName); 206 207 Map <String ,ClusterConfig> 208 relevantClusterConfigMap = new HashMap <String ,ClusterConfig>(); 209 210 Map <String ,ClusterRefConfig> clusterRefConfigMap = 211 lbConfig.getClusterRefConfigMap(); 212 for (String clusterName : clusterRefConfigMap.keySet()) 213 relevantClusterConfigMap.put( 214 clusterName, allClusterConfigMap.get(clusterName)); 215 216 for (ClusterConfig clusterConfig : 217 relevantClusterConfigMap.values()) { 218 Map <String ,ServerRefConfig> serverRefConfigMap = 219 clusterConfig.getServerRefConfigMap(); 220 for (String serverRef : serverRefConfigMap.keySet()) { 221 if (serverRef.equals(serverName)) { 222 relevantLBConfigMap.put(lbConfigName, lbConfig); 223 break; 224 } 225 } 226 } 227 228 Map <String ,ServerRefConfig> serverRefConfigMap = 229 lbConfig.getServerRefConfigMap(); 230 for (String serverRef : serverRefConfigMap.keySet()) { 231 if (serverRef.equals(serverName)) { 232 relevantLBConfigMap.put(lbConfigName, lbConfig); 233 break; 234 } 235 } 236 } 237 238 return fetchLoadBalancerConfigs(relevantLBConfigMap); 239 } 240 241 private Collection <LoadBalancerApplicationMonitor> 242 fetchLoadBalancerApplicationMonitors( 243 String ipAppName, LoadBalancerMonitor loadBalancerMonitor) { 244 245 Collection <LoadBalancerApplicationMonitor> result = new ArrayList <LoadBalancerApplicationMonitor>(); 246 Map <String ,LoadBalancerClusterMonitor> lbcmMap = 247 loadBalancerMonitor.getLoadBalancerClusterMonitorMap(); 248 for (String clusterName : lbcmMap.keySet()) { 249 LoadBalancerClusterMonitor lbcm = lbcmMap.get(clusterName); 250 Map <String ,LoadBalancerServerMonitor> lbsmMap = 251 lbcm.getLoadBalancerServerMonitorMap(); 252 for (String serverName : lbsmMap.keySet()) { 253 LoadBalancerServerMonitor lbsm = lbsmMap.get(serverName); 254 Map <String , LoadBalancerApplicationMonitor> lbamMap = 255 lbsm.getLoadBalancerApplicationMonitorMap(); 256 if (lbamMap.get(ipAppName) != null) 257 result.add(lbamMap.get(ipAppName)); 258 } 259 } 260 return result; 261 } 262 263 private Map <String ,LoadBalancerConfig> fetchLoadBalancerConfigs( 264 LBConfig lbConfig) { 265 Map <String , LBConfig> lbConfigMap = new HashMap <String , LBConfig>(); 266 lbConfigMap.put(lbConfig.getName(), lbConfig); 267 return fetchLoadBalancerConfigs(lbConfigMap); 268 } 269 270 private Map <String ,LoadBalancerConfig> fetchLoadBalancerConfigs( 271 Map <String , LBConfig> lbConfigMap) { 272 273 Map <String ,LoadBalancerConfig> relevantLoadBalancerConfigMap = 274 new HashMap <String ,LoadBalancerConfig>(); 275 276 for (String lbConfigName : lbConfigMap.keySet()) { 277 Map <String ,LoadBalancerConfig> allLoadBalancerConfigMap = 279 getDomainRoot().getDomainConfig().getLoadBalancerConfigMap(); 280 281 282 for (String loadBalancerName : allLoadBalancerConfigMap.keySet()) { 283 LoadBalancerConfig loadBalancerConfig = 284 allLoadBalancerConfigMap.get(loadBalancerName); 285 if (loadBalancerConfig.getLbConfigName().equals(lbConfigName)) 286 relevantLoadBalancerConfigMap.put( 287 loadBalancerName, loadBalancerConfig); 288 } 289 } 290 return relevantLoadBalancerConfigMap; 291 } 292 } 293 } | Popular Tags |