1 23 24 package com.sun.enterprise.management.config; 25 26 import java.util.Collection ; 27 import java.util.Map ; 28 import java.util.HashMap ; 29 import java.util.ArrayList ; 30 import java.io.IOException ; 31 32 import javax.management.JMException ; 33 import javax.management.MBeanServer ; 34 import javax.management.ObjectName ; 35 36 import com.sun.appserv.management.base.XTypes; 37 import com.sun.enterprise.management.config.AMXConfigImplBase; 38 import com.sun.enterprise.management.support.Delegate; 39 import com.sun.enterprise.management.support.ObjectNames; 40 import com.sun.enterprise.management.support.LBDeregistrationUtil; 41 import com.sun.enterprise.management.support.AMXAttributeNameMapper; 42 43 import static com.sun.appserv.management.base.XTypes.LOAD_BALANCER; 44 import static com.sun.appserv.management.base.XTypes.LOAD_BALANCER_MONITOR; 45 import static com.sun.appserv.management.base.AMX.J2EE_TYPE_KEY; 46 import static com.sun.appserv.management.base.AMX.NAME_KEY; 47 import static com.sun.appserv.management.base.AMX.JMX_DOMAIN; 48 49 import com.sun.appserv.management.base.Util; 50 import com.sun.appserv.management.base.AMXDebug; 51 import com.sun.appserv.management.monitor.LoadBalancerMonitor; 52 import com.sun.appserv.management.monitor.LoadBalancerClusterMonitor; 53 import com.sun.appserv.management.monitor.LoadBalancerServerMonitor; 54 import com.sun.appserv.management.monitor.LoadBalancerApplicationMonitor; 55 import com.sun.appserv.management.monitor.LoadBalancerContextRootMonitor; 56 import com.sun.appserv.management.config.DeployedItemRefConfig; 57 import com.sun.appserv.management.config.ClusterRefConfig; 58 import com.sun.appserv.management.config.ClusterConfig; 59 import com.sun.appserv.management.config.ServerRefConfig; 60 import com.sun.appserv.management.config.ServerConfig; 61 import com.sun.appserv.management.config.LoadBalancerConfig; 62 import com.sun.appserv.management.config.LBConfig; 63 import com.sun.appserv.management.client.ProxyFactory; 64 65 68 public final class ClusterRefConfigImpl extends AMXConfigImplBase 69 implements ConfigFactoryCallback { 70 72 ClusterRefDeregistrationHelper mHelper = null; 73 74 public ClusterRefConfigImpl(final Delegate delegate) 75 { 76 super(delegate); 77 } 78 79 protected void unregisterMisc() { 80 try { 81 mHelper = new ClusterRefDeregistrationHelper( 82 getName(), getMBeanServer()); 83 } catch (Exception ex) { 84 logWarning("ClusterRefConfig unregisterMisc failed. " + 85 "ClusterRefDeregistrationHelper creation failed"); 86 } 87 } 88 89 public void postDeregister() { 90 super.postDeregister(); 91 try { 92 Map <String ,LoadBalancerConfig> relevantLoadBalancerConfigMap = 93 new HashMap <String ,LoadBalancerConfig>(); 94 95 if (getContainer() instanceof LBConfig) { 96 String lbConfigName = ((LBConfig)getContainer()).getName(); 97 relevantLoadBalancerConfigMap = 98 mHelper.fetchLoadBalancerConfigs((LBConfig)getContainer()); 99 mHelper.unregisterMonitors(relevantLoadBalancerConfigMap); 100 } 101 mHelper = null; 102 } catch (Exception ex) { 103 logWarning("ClusterRefConfig postDeregistration failed. " + 104 "Load Balancer Monitoring MBeans might be lying around"); 105 } 106 } 107 108 private class ClusterRefDeregistrationHelper { 109 110 final static String J2EE_TYPE = "j2eeType"; 111 final ObjectNames objectNames = ObjectNames.getInstance(JMX_DOMAIN); 112 String clusterName = null; 113 MBeanServer mbs = null; 114 115 public ClusterRefDeregistrationHelper(String clusterName, MBeanServer mbs) { 116 this.mbs = mbs; 117 this.clusterName = clusterName; 118 } 119 120 Map <String , LoadBalancerConfig> fetchLoadBalancerConfigs(LBConfig lbConfig) { 121 String lbConfigName = lbConfig.getName(); 122 Map <String ,LoadBalancerConfig> allLoadBalancerConfigMap = 123 getDomainRoot().getDomainConfig().getLoadBalancerConfigMap(); 124 Map <String ,LoadBalancerConfig> 125 relevantLoadBalancerConfigMap = new HashMap <String ,LoadBalancerConfig>(); 126 127 for (String loadBalancerName : allLoadBalancerConfigMap.keySet()) { 128 LoadBalancerConfig loadBalancerConfig = 129 allLoadBalancerConfigMap.get(loadBalancerName); 130 if (loadBalancerConfig.getLbConfigName().equals(lbConfigName)) 131 relevantLoadBalancerConfigMap.put( 132 loadBalancerName, loadBalancerConfig); 133 } 134 135 return relevantLoadBalancerConfigMap; 136 } 137 138 void unregisterMonitors( 139 Map <String ,LoadBalancerConfig> relevantLoadBalancerConfigMap) 140 throws JMException { 141 142 for (String loadBalancerName : relevantLoadBalancerConfigMap.keySet()) { 143 LoadBalancerMonitor loadBalancerMonitor = 144 LBDeregistrationUtil.getInstance(mbs) 145 .fetchLBMonitoringRoot(loadBalancerName); 146 147 Map <String ,LoadBalancerClusterMonitor> lbcmMap = 148 loadBalancerMonitor.getLoadBalancerClusterMonitorMap(); 149 150 LoadBalancerClusterMonitor lbcm = lbcmMap.get(clusterName); 151 152 Map <String ,LoadBalancerServerMonitor> lbsmMap = 155 lbcm.getLoadBalancerServerMonitorMap(); 156 157 for (LoadBalancerServerMonitor lbsm : lbsmMap.values()) { 158 159 Map <String ,LoadBalancerApplicationMonitor> 160 lbamMap = lbsm.getLoadBalancerApplicationMonitorMap(); 161 162 for (LoadBalancerApplicationMonitor lbam : lbamMap.values()) { 163 Map <String ,LoadBalancerContextRootMonitor> 164 lbcrmMap = lbam.getLoadBalancerContextRootMonitorMap(); 165 for (LoadBalancerContextRootMonitor lbcrm : lbcrmMap.values()) { 166 ObjectName lbcrmObjName = Util.getObjectName(lbcrm); 167 mbs.unregisterMBean(lbcrmObjName ); 168 } 169 170 ObjectName lbamObjName = Util.getObjectName(lbam); 171 mbs.unregisterMBean(lbamObjName); 172 } 173 174 ObjectName loadBalancerServerMonitorObjName = 175 Util.getObjectName(lbsm); 176 mbs.unregisterMBean(loadBalancerServerMonitorObjName); 177 } 178 179 ObjectName lbcmObjName = Util.getObjectName(lbcm); 180 mbs.unregisterMBean(lbcmObjName); 181 } 182 } 183 } 184 } 185 186 187 188 189 190 191 192 | Popular Tags |