KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > support > LoadBalancerServerRefRegistrationListener


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.management.support;
24
25 import java.util.Map JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Collection JavaDoc;
30 import java.io.IOException JavaDoc;
31
32 import javax.management.MBeanServer JavaDoc;
33 import javax.management.ObjectName JavaDoc;
34 import javax.management.JMException JavaDoc;
35 import javax.management.InstanceNotFoundException JavaDoc;
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.SERVER_REF_CONFIG;
50 import com.sun.appserv.management.config.DeployedItemRefConfig;
51 import com.sun.appserv.management.config.ServerRefConfig;
52 import com.sun.appserv.management.config.ClusterConfig;
53 import com.sun.appserv.management.config.ServerConfig;
54 import com.sun.appserv.management.config.ClusteredServerConfig;
55 import com.sun.appserv.management.config.StandaloneServerConfig;
56 import com.sun.appserv.management.config.LBConfig;
57 /**
58  * A class that triggers forming LB monitoring tree whenever a new <server-ref>
59  * gets added to a <lb-config> or <cluster> elements. The registration logic
60  * Determines parent object <lb-config> or <cluster>.
61  *
62  * If <lb-config> i.e. the server-ref is for a standalone server
63  * 1. get ALL standalone <server> elements
64  * 2. locate the referring <load-balancer> elements and fetch corresponding
65  * root LoadBalancerMonitors
66  * 3. create LoadBalancerClusterMonitor and its child LoadBalancerServerMonitor
67  * and create the rest of the monitoring tree under this LoadBalancerServerMonitor
68  * as governed by the structure of the <server> element
69  *
70  * If <cluster> i.e. the server-ref is for a clustered server
71  * 1. fetch <lb-configs elements that have reference to this <cluster>
72  * 2. fetch root LoadBalancerMonitors for the <lb-config> elements found in
73  * step 1. (this happens via <load-balancer> elements
74  * 3. fetch ONLY those LoadBalancerClusterMonitors that have the same name as the
75  * name of the cluster of the clustered server
76  * 4. create child LoadBalancerServerMonitors under the LoadBalancerClusterMonitors
77  * found in step 3 and create the rest of the monitoring tree under this
78  * LoadBalancerServerMonitor as governed by the structure of the <server> element
79  *
80  * @see LoadBalancerClusterRefRegistrationListener
81  * @see LoadBalancerApplicationRefRegistrationListener
82  * @see LoadBalancerRegistrationListener
83  */

84 public class LoadBalancerServerRefRegistrationListener
85     extends LBBaseMBeanRegistrationListener {
86     
87     public LoadBalancerServerRefRegistrationListener(MBeanServer JavaDoc mBeanServer)
88         throws InstanceNotFoundException JavaDoc, IOException JavaDoc {
89         super(mBeanServer);
90     }
91
92     protected void mbeanRegistered(final ObjectName JavaDoc objectName) {
93         try {
94             if (SERVER_REF_CONFIG.equals(Util.getJ2EEType(objectName))) {
95                 
96                 ServerRefConfig serverRefConfig =
97                     ProxyFactory.getInstance(getConn()).getProxy(objectName, ServerRefConfig.class);
98                 String JavaDoc serverName = serverRefConfig.getRef();
99                 Container container = serverRefConfig.getContainer();
100                 
101                 Map JavaDoc<String JavaDoc, ServerConfig> serverConfigMap = new HashMap JavaDoc<String JavaDoc, ServerConfig>();
102
103                 if (container instanceof LBConfig) {
104                     //get ALL standalone <server> elements
105
Map JavaDoc<String JavaDoc,StandaloneServerConfig> sserverConfigMap =
106                         getDomainConfig().getStandaloneServerConfigMap();
107                     
108                     //doing the following to enable reuse of the
109
//registerLoadBalancerServerMonitorTree base class method
110
for (String JavaDoc key : sserverConfigMap.keySet()) {
111                         serverConfigMap.put(
112                             key, (ServerConfig)sserverConfigMap.get(key));
113                     }
114                     
115                     List JavaDoc<LoadBalancerMonitor> loadBalancerMonitorList =
116                         fetchLBMonitoringRoots((LBConfig)container);
117                     
118                     for (LoadBalancerMonitor lbm : loadBalancerMonitorList) {
119                         LoadBalancerClusterMonitor lbcm =
120                             registerLoadBalancerClusterMonitor(
121                                 lbm, serverName);
122                         registerLoadBalancerServerMonitorTree(
123                             lbcm, serverConfigMap, serverName);
124                     } //end for (LoadBalancerMonitor : loadBalancerMonitorList)
125
} //end if (container instanceof LBConfig)
126

127                 else if (container instanceof ClusterConfig) {
128                     //get ALL clustered <server> elements
129
Map JavaDoc<String JavaDoc,ClusteredServerConfig> cserverConfigMap =
130                         getDomainConfig().getClusteredServerConfigMap();
131                     
132                     //doing the following to enable reuse of the
133
//registerLoadBalancerServerMonitorTree base class method
134
for (String JavaDoc key : cserverConfigMap.keySet()) {
135                         serverConfigMap.put(
136                             key, (ServerConfig)cserverConfigMap.get(key));
137                     }
138
139                     Collection JavaDoc<LBConfig> affectedLBConfigArr =
140                         fetchLBConfigs(((ClusterConfig)container).getName(), true);
141                     
142                     for (LBConfig lbConfig : affectedLBConfigArr) {
143                         List JavaDoc<LoadBalancerMonitor> monitoringRoots =
144                             fetchLBMonitoringRoots(lbConfig);
145                         List JavaDoc<LoadBalancerClusterMonitor> clusterMonitors =
146                             fetchLoadBalancerClusterMonitors(monitoringRoots,
147                                 ((ClusterConfig)container).getName());
148                         
149                         for (LoadBalancerClusterMonitor lbcm : clusterMonitors) {
150                             registerLoadBalancerServerMonitorTree(
151                                 lbcm, serverConfigMap, serverName);
152                         }
153                     }
154                 }
155             }
156     } catch (Exception JavaDoc ex) {
157             logWarning(
158                 "LoadBalancerServerRefRegistrationListener" +
159                 " mbeanRegistered failed. Exception = ", ex);
160     }
161     }
162 }
163
Popular Tags