1 23 24 28 29 34 35 package com.sun.enterprise.management.support; 36 37 import com.sun.appserv.management.util.jmx.NotificationListenerBase; 38 import com.sun.enterprise.management.ext.lb.LoadBalancerImpl; 39 40 import java.util.Map ; 41 import java.util.HashMap ; 42 import java.io.IOException ; 43 import javax.management.AttributeChangeNotification ; 44 45 import javax.management.InstanceNotFoundException ; 46 import javax.management.JMException ; 47 import javax.management.MBeanServer ; 48 import javax.management.Notification ; 49 import javax.management.NotificationListener ; 50 import javax.management.ObjectName ; 51 52 import com.sun.appserv.management.client.ProxyFactory; 53 import com.sun.appserv.management.base.AMXDebug; 54 import com.sun.appserv.management.config.DomainConfig; 55 import com.sun.appserv.management.config.LBConfig; 56 import com.sun.appserv.management.config.LoadBalancerConfig; 57 import com.sun.appserv.management.ext.lb.LoadBalancer; 58 import com.sun.appserv.management.DomainRoot; 59 import com.sun.appserv.management.base.AMXRootLogger; 60 import com.sun.enterprise.management.support.LBDeregistrationUtil; 61 import static com.sun.appserv.management.base.AMX.JMX_DOMAIN; 62 63 77 public class LBBootstrapUtil extends NotificationListenerBase { 78 79 final static String MONITORING_ENABLED = "MonitoringEnabled"; 80 static boolean isInitialized = false; 81 LoadBalancerRegistrationListener lbrl = null; 82 final private ObjectNames objectNames = ObjectNames.getInstance(JMX_DOMAIN); 83 84 public LBBootstrapUtil(ObjectName domainRoot, MBeanServer mBeanServer) 85 throws InstanceNotFoundException , IOException { 86 super(mBeanServer, domainRoot, null); 87 } 88 89 public void handleNotification( 90 final Notification notifIn, final Object handback) { 91 try { 92 String type = notifIn.getType(); 93 if ( (type == null) || 94 (type.equals(DomainRoot.AMX_READY_NOTIFICATION_TYPE) == false) ) 95 return ; 96 97 if (isInitialized) return; 100 101 106 lbrl = new LoadBalancerRegistrationListener((MBeanServer )getConn()); 107 initRestOfLBMBeanRegistrationListeners(); 108 109 DomainConfig domainConfig = ProxyFactory.getInstance(getConn()) 110 .getDomainRoot().getDomainConfig(); 111 112 Map <String , LoadBalancerConfig> loadBalancerConfigMap = 114 domainConfig.getLoadBalancerConfigMap(); 115 Map <String , LBConfig> lbConfigMap = domainConfig.getLBConfigMap(); 117 118 String lbConfigName = null; 119 LBConfig lbConfig = null; 120 String loadBalancerName = null; 121 boolean isMonitoringEnabled = false; 122 123 for (LoadBalancerConfig loadBalancerConfig : loadBalancerConfigMap.values()) { 124 loadBalancerName = loadBalancerConfig.getName(); 125 lbConfigName = loadBalancerConfig.getLbConfigName(); 126 lbConfig = lbConfigMap.get(lbConfigName); 127 128 LoadBalancer loadBalancer = 129 lbrl.registerLoadBalancer(loadBalancerConfig.getName()); 130 131 isMonitoringEnabled = lbConfig.getMonitoringEnabled(); 132 if (isMonitoringEnabled) 133 lbrl.enableMonitoring(loadBalancerConfig.getName(), lbConfig); 134 135 lbrl.addLBConfigListener(loadBalancerName, lbConfig); 137 } 138 isInitialized = true; 139 } catch (Exception ex) { 140 AMXRootLogger.getInstance().warning( 141 "LBBootstrapUtil:handleNotification" + " : " + ex.getMessage()); 142 } 143 } 144 145 private void initRestOfLBMBeanRegistrationListeners() { 146 147 MBeanServer mbeanServer = (MBeanServer )getConn(); 148 try { 149 new LoadBalancerClusterRefRegistrationListener(mbeanServer); 150 new LoadBalancerServerRefRegistrationListener(mbeanServer); 151 new LoadBalancerApplicationRefRegistrationListener(mbeanServer); 152 } catch(Exception e) { 153 throw new RuntimeException (e); 154 } 155 } 156 157 } | Popular Tags |