1 23 24 27 28 package com.sun.enterprise.management.config; 29 30 import com.sun.enterprise.management.support.LBDeregistrationUtil; 31 import com.sun.enterprise.management.support.ObjectNames; 32 import java.util.Map ; 33 34 import com.sun.appserv.management.base.XTypes; 35 import com.sun.appserv.management.base.Util; 36 import com.sun.enterprise.management.support.Delegate; 37 import com.sun.appserv.management.config.LoadBalancerConfig; 38 import com.sun.appserv.management.config.LBConfig; 39 import com.sun.appserv.management.ext.lb.LoadBalancer; 40 import javax.management.InstanceNotFoundException ; 41 import javax.management.JMException ; 42 import javax.management.MBeanServer ; 43 import javax.management.ObjectName ; 44 import com.sun.appserv.management.monitor.LoadBalancerMonitor; 45 import com.sun.appserv.management.monitor.LoadBalancerClusterMonitor; 46 import com.sun.appserv.management.monitor.LoadBalancerServerMonitor; 47 import com.sun.appserv.management.monitor.LoadBalancerApplicationMonitor; 48 import com.sun.appserv.management.monitor.LoadBalancerContextRootMonitor; 49 import com.sun.appserv.management.config.DeployedItemRefConfig; 50 import com.sun.appserv.management.config.ClusterRefConfig; 51 import com.sun.appserv.management.config.ClusterConfig; 52 import com.sun.appserv.management.config.ServerRefConfig; 53 import com.sun.appserv.management.config.ServerConfig; 54 import com.sun.appserv.management.config.StandaloneServerConfig; 55 import com.sun.appserv.management.config.LoadBalancerConfig; 56 import com.sun.appserv.management.config.LBConfig; 57 import com.sun.appserv.management.ext.lb.LoadBalancer; 58 import com.sun.appserv.management.monitor.MonitoringRoot; 59 import com.sun.appserv.management.DomainRoot; 60 import com.sun.appserv.management.client.ProxyFactory; 61 62 65 public final class LoadBalancerConfigImpl extends AMXConfigImplBase { 66 67 LoadBalancerDeregistrationHelper mHelper = null; 68 String lbConfigName = null; 69 70 public LoadBalancerConfigImpl(final Delegate delegate) { 71 super(delegate); 72 } 73 74 protected void unregisterMisc() { 75 try { 76 LoadBalancerConfig lbc = ProxyFactory.getInstance(getMBeanServer()) 77 .getDomainRoot().getDomainConfig().getLoadBalancerConfigMap() 78 .get(getName()); 79 LBConfig lbConfig = getDomainRoot().getDomainConfig() 80 .getLBConfigMap().get(lbConfigName); 81 mHelper = new LoadBalancerDeregistrationHelper( 82 getName(), lbConfig, getMBeanServer()); 83 } catch (Exception ex) { 84 logWarning("LoadBalancerConfig unregisterMisc failed. " + 85 "LoadBalancerDeregistrationHelper creation failed"); 86 } 87 } 88 89 public void postRegisterHook(Boolean registrationSucceeded) { 90 super.postRegisterHook(registrationSucceeded); 91 if (registrationSucceeded) { 92 LoadBalancerConfig lbc = ProxyFactory.getInstance(getMBeanServer()) 93 .getDomainRoot().getDomainConfig().getLoadBalancerConfigMap() 94 .get(getName()); 95 lbConfigName = lbc.getLbConfigName(); 96 } 97 } 98 99 public void postDeregister() { 100 super.postDeregister(); 101 try { 102 mHelper.unregisterMonitors(); 103 mHelper.unregisterRuntimeMBean(); 104 mHelper.removeLBConfigListener(); 105 mHelper = null; 106 } catch (Exception ex) { 107 logWarning("LoadBalancerConfig postDeregistration failed. " + 108 "Load Balancer Monitoring MBeans might be lying around"); 109 } 110 } 111 112 private class LoadBalancerDeregistrationHelper { 113 114 final static String J2EE_TYPE = "j2eeType"; 115 final ObjectNames objectNames = ObjectNames.getInstance(JMX_DOMAIN); 116 MBeanServer mbs = null; 117 String loadBalancerName = null; 118 LBConfig lbConfig = null; 119 120 public LoadBalancerDeregistrationHelper( 121 String loadBalancerName, LBConfig lbConfig, MBeanServer mbs) { 122 123 this.mbs = mbs; 124 this.loadBalancerName = loadBalancerName; 125 this.lbConfig = lbConfig; 126 } 127 128 void removeLBConfigListener() throws JMException { 129 LBDeregistrationUtil.getInstance(mbs) 130 .removeLBConfigListener(loadBalancerName, lbConfig); 131 } 132 133 void unregisterRuntimeMBean() throws JMException { 134 LoadBalancer loadBalancer = ProxyFactory.getInstance(mbs) 135 .getDomainRoot().getLoadBalancerMap().get(loadBalancerName); 136 137 ObjectName lbObjName = Util.getObjectName(loadBalancer); 138 mbs.unregisterMBean(lbObjName); 139 } 140 141 void unregisterMonitors() throws JMException { 142 143 if (!lbConfig.getMonitoringEnabled()) return; 144 145 LoadBalancerMonitor lbm = LBDeregistrationUtil.getInstance(mbs) 146 .fetchLBMonitoringRoot(loadBalancerName); 147 148 Map <String ,LoadBalancerClusterMonitor> lbcmMap = 149 lbm.getLoadBalancerClusterMonitorMap(); 150 151 for (LoadBalancerClusterMonitor lbcm : lbcmMap.values()) { 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 ObjectName lbmObjName = Util.getObjectName(lbm); 184 mbs.unregisterMBean(lbmObjName); 185 } 186 } 187 } | Popular Tags |