1 23 package com.sun.enterprise.management.support; 24 25 26 import java.util.Map ; 27 import java.util.List ; 28 import java.util.ArrayList ; 29 import java.util.Collection ; 30 import java.io.IOException ; 31 32 import javax.management.MBeanServer ; 33 import javax.management.ObjectName ; 34 import javax.management.JMException ; 35 import javax.management.InstanceNotFoundException ; 36 37 import com.sun.appserv.management.base.AMXDebug; 38 import com.sun.appserv.management.base.Container; 39 import com.sun.appserv.management.base.Util; 40 import com.sun.appserv.management.client.ProxyFactory; 41 import com.sun.enterprise.management.support.ObjectNames; 42 43 import com.sun.appserv.management.monitor.LoadBalancerMonitor; 44 import com.sun.appserv.management.monitor.LoadBalancerClusterMonitor; 45 import com.sun.appserv.management.monitor.LoadBalancerServerMonitor; 46 import com.sun.appserv.management.monitor.LoadBalancerApplicationMonitor; 47 import com.sun.appserv.management.monitor.LoadBalancerContextRootMonitor; 48 49 import static com.sun.appserv.management.base.XTypes.DEPLOYED_ITEM_REF_CONFIG; 50 import com.sun.appserv.management.config.DeployedItemRefConfig; 51 import com.sun.appserv.management.config.ClusterConfig; 52 import com.sun.appserv.management.config.ServerConfig; 53 import com.sun.appserv.management.config.LBConfig; 54 55 88 89 public class LoadBalancerApplicationRefRegistrationListener 90 extends LBBaseMBeanRegistrationListener { 91 92 public LoadBalancerApplicationRefRegistrationListener(MBeanServer mBeanServer) 93 throws InstanceNotFoundException , IOException { 94 super(mBeanServer); 95 } 96 97 protected void mbeanRegistered(final ObjectName objectName) { 98 try { 99 if (DEPLOYED_ITEM_REF_CONFIG.equals(Util.getJ2EEType(objectName))) { 100 DeployedItemRefConfig appRefConfig = 101 ProxyFactory.getInstance(getConn()).getProxy(objectName, DeployedItemRefConfig.class); 102 String appName = appRefConfig.getRef(); 103 Container parent = appRefConfig.getContainer(); 104 105 if (parent instanceof ServerConfig) { 106 Collection <LBConfig> affectedLBConfigArr = 107 fetchLBConfigs(((ServerConfig)parent).getName(), false); 108 for (LBConfig lbConfig : affectedLBConfigArr) { 109 List <LoadBalancerMonitor> monitoringRoots = 110 fetchLBMonitoringRoots(lbConfig); 111 List <LoadBalancerServerMonitor> serverMonitors = 112 fetchLoadBalancerServerMonitors(monitoringRoots, 113 ((ServerConfig)parent).getName(), false); 114 for (LoadBalancerServerMonitor lbsm : serverMonitors) 115 registerLoadBalancerApplicationMonitorTree(lbsm, appName); 116 } 117 } 119 else if (parent instanceof ClusterConfig) { 120 Collection <LBConfig> affectedLBConfigArr = 121 fetchLBConfigs(((ClusterConfig)parent).getName(), true); 122 for (LBConfig lbConfig : affectedLBConfigArr) { 123 List <LoadBalancerMonitor> monitoringRoots = 124 fetchLBMonitoringRoots(lbConfig); 125 List <LoadBalancerServerMonitor> serverMonitors = 126 fetchLoadBalancerServerMonitors(monitoringRoots, 127 ((ClusterConfig)parent).getName(), true); 128 for (LoadBalancerServerMonitor lbsm : serverMonitors) 129 registerLoadBalancerApplicationMonitorTree(lbsm, appName); 130 } 131 } 133 } 134 } catch (Exception ex) { 135 logWarning( 136 "LoadBalancerApplicationRefRegistrationListener" + 137 " mbeanRegistered failed. Exception = ", ex); 138 } 139 } 140 141 private List <LoadBalancerServerMonitor> fetchLoadBalancerServerMonitors( 142 List <LoadBalancerMonitor> monitoringRoots, String targetName, boolean isCluster) { 143 144 List <LoadBalancerServerMonitor> serverMonitors = new ArrayList <LoadBalancerServerMonitor>(); 145 146 if (isCluster) { 147 List <LoadBalancerClusterMonitor> clusterMonitors = 148 fetchLoadBalancerClusterMonitors(monitoringRoots, targetName); 149 150 for (LoadBalancerClusterMonitor lbcm : clusterMonitors) { 151 Map <String , LoadBalancerServerMonitor> lbsmMap = 152 lbcm.getLoadBalancerServerMonitorMap(); 153 serverMonitors.addAll(lbsmMap.values()); 154 } 155 } else { 156 161 for (LoadBalancerMonitor lbm : monitoringRoots) { 162 Map <String , LoadBalancerClusterMonitor> lbcmMap = 163 lbm.getLoadBalancerClusterMonitorMap(); 164 for (LoadBalancerClusterMonitor lbcm : lbcmMap.values()) { 165 Map <String , LoadBalancerServerMonitor> lbsmMap = 166 lbcm.getLoadBalancerServerMonitorMap(); 167 for (LoadBalancerServerMonitor lbsm : lbsmMap.values()) 168 if (lbsm.getName().equals(targetName)) 169 serverMonitors.add(lbsm); 170 } 171 } 172 } 173 return serverMonitors; 174 } 175 } | Popular Tags |