KickJava   Java API By Example, From Geeks To Geeks.

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


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
24 /*
25  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
26  * Use is subject to license terms.
27  */

28  
29 /*
30  * $Header: /cvs/glassfish/admin/mbeanapi-impl/src/java/com/sun/enterprise/management/support/LoadBalancerClusterRefRegistrationListener.java,v 1.5 2006/03/09 20:30:47 llc Exp $
31  * $Revision: 1.5 $
32  * $Date: 2006/03/09 20:30:47 $
33  */

34
35 package com.sun.enterprise.management.support;
36
37 import java.util.Map JavaDoc;
38 import java.util.HashMap JavaDoc;
39 import java.util.List JavaDoc;
40 import java.util.ArrayList JavaDoc;
41 import java.io.IOException JavaDoc;
42
43 import javax.management.MBeanServer JavaDoc;
44 import javax.management.ObjectName JavaDoc;
45 import javax.management.JMException JavaDoc;
46 import javax.management.InstanceNotFoundException JavaDoc;
47
48 import com.sun.appserv.management.base.AMXDebug;
49 import com.sun.appserv.management.base.Container;
50 import com.sun.appserv.management.base.Util;
51 import com.sun.appserv.management.client.ProxyFactory;
52 import com.sun.enterprise.management.support.ObjectNames;
53
54 import com.sun.appserv.management.monitor.LoadBalancerMonitor;
55 import com.sun.appserv.management.monitor.LoadBalancerClusterMonitor;
56 import com.sun.appserv.management.monitor.LoadBalancerServerMonitor;
57 import com.sun.appserv.management.monitor.LoadBalancerApplicationMonitor;
58 import com.sun.appserv.management.monitor.LoadBalancerContextRootMonitor;
59
60 import static com.sun.appserv.management.base.XTypes.CLUSTER_REF_CONFIG;
61 import com.sun.appserv.management.config.DeployedItemRefConfig;
62 import com.sun.appserv.management.config.ClusterRefConfig;
63 import com.sun.appserv.management.config.ClusterConfig;
64 import com.sun.appserv.management.config.ServerConfig;
65 import com.sun.appserv.management.config.ClusteredServerConfig;
66 import com.sun.appserv.management.config.LBConfig;
67
68 /**
69  * A class that triggers forming LB monitoring tree whenever a new <cluster-ref>
70  * gets added to a <lb-config> element. The registration logic
71  * 1. locates <load-balancer> elements referring to the <lb-config> under which
72  * the present <cluster-ref> got added
73  * 2. fetches root container monitors, LoadBalancerMonitor, for each
74  * <load-balancer> found in step 1
75  * 3. registers a LoadBalancerClusterMonitor under each of this root
76  * LoadBalancerMonitor found in step 2
77  * 4. fetches the <server> elements (via <server-ref> elements) for this
78  * <cluster-ref> element
79  * 5. registers a LoadBalancerServerMonitor under each of this
80  * LoadBalancerClusterMonitor found in step 3
81  * 6. fetches the <application> elements (via <application-ref> elements) for
82  * each <server> element found in step 4.
83  * 7. registers a LoadBalancerApplicationMonitor under each of the
84  * LoadBalancerServerMonitor found in step 5
85  * 6. fetches the context roots for each <application> element found in step 6.
86  * 8. registers a LoadBalancerContextRootMonitor under each of the
87  * LoadBalancerApplicationMonitor found in step 7
88  *
89  * @see LoadBalancerServerRefRegistrationListener
90  * @see LoadBalancerApplicationRefRegistrationListener
91  * @see LoadBalancerRegistrationListener
92  */

93 public class LoadBalancerClusterRefRegistrationListener
94     extends LBBaseMBeanRegistrationListener {
95     
96     public LoadBalancerClusterRefRegistrationListener(MBeanServer JavaDoc mBeanServer)
97         throws InstanceNotFoundException JavaDoc, IOException JavaDoc {
98         super(mBeanServer);
99     }
100
101     protected void mbeanRegistered(final ObjectName JavaDoc objectName) {
102         try {
103             if (CLUSTER_REF_CONFIG.equals(Util.getJ2EEType(objectName))) {
104                 ClusterRefConfig clusterRefConfig =
105                     ProxyFactory.getInstance(getConn()).getProxy(objectName, ClusterRefConfig.class);
106                 String JavaDoc clusterName = clusterRefConfig.getRef();
107                 Container container = clusterRefConfig.getContainer();
108
109                 if (container instanceof LBConfig) {
110                     List JavaDoc<LoadBalancerMonitor> lbmList =
111                         fetchLBMonitoringRoots((LBConfig)container);
112                     
113                     for (LoadBalancerMonitor lbm : lbmList) {
114                         registerLoadBalancerClusterMonitorTree(lbm, clusterName);
115                     }
116                     
117                 }
118             }
119     } catch (Exception JavaDoc ex) {
120             logWarning(
121                 "LoadBalancerClusterRefRegistrationListener mbeanRegistered " +
122                     "failed. Exception = ", ex);
123     }
124     }
125 }
Popular Tags