KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > config > ClusterRefConfigImpl


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 package com.sun.enterprise.management.config;
25
26 import java.util.Collection JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.io.IOException JavaDoc;
31
32 import javax.management.JMException JavaDoc;
33 import javax.management.MBeanServer JavaDoc;
34 import javax.management.ObjectName JavaDoc;
35
36 import com.sun.appserv.management.base.XTypes;
37 import com.sun.enterprise.management.config.AMXConfigImplBase;
38 import com.sun.enterprise.management.support.Delegate;
39 import com.sun.enterprise.management.support.ObjectNames;
40 import com.sun.enterprise.management.support.LBDeregistrationUtil;
41 import com.sun.enterprise.management.support.AMXAttributeNameMapper;
42
43 import static com.sun.appserv.management.base.XTypes.LOAD_BALANCER;
44 import static com.sun.appserv.management.base.XTypes.LOAD_BALANCER_MONITOR;
45 import static com.sun.appserv.management.base.AMX.J2EE_TYPE_KEY;
46 import static com.sun.appserv.management.base.AMX.NAME_KEY;
47 import static com.sun.appserv.management.base.AMX.JMX_DOMAIN;
48
49 import com.sun.appserv.management.base.Util;
50 import com.sun.appserv.management.base.AMXDebug;
51 import com.sun.appserv.management.monitor.LoadBalancerMonitor;
52 import com.sun.appserv.management.monitor.LoadBalancerClusterMonitor;
53 import com.sun.appserv.management.monitor.LoadBalancerServerMonitor;
54 import com.sun.appserv.management.monitor.LoadBalancerApplicationMonitor;
55 import com.sun.appserv.management.monitor.LoadBalancerContextRootMonitor;
56 import com.sun.appserv.management.config.DeployedItemRefConfig;
57 import com.sun.appserv.management.config.ClusterRefConfig;
58 import com.sun.appserv.management.config.ClusterConfig;
59 import com.sun.appserv.management.config.ServerRefConfig;
60 import com.sun.appserv.management.config.ServerConfig;
61 import com.sun.appserv.management.config.LoadBalancerConfig;
62 import com.sun.appserv.management.config.LBConfig;
63 import com.sun.appserv.management.client.ProxyFactory;
64
65 /**
66     Configuration for the <cluster-ref> element.
67 */

68 public final class ClusterRefConfigImpl extends AMXConfigImplBase
69     implements ConfigFactoryCallback {
70     //implements ClusterRefConfig
71

72     ClusterRefDeregistrationHelper mHelper = null;
73     
74     public ClusterRefConfigImpl(final Delegate delegate)
75     {
76         super(delegate);
77     }
78
79     protected void unregisterMisc() {
80         try {
81             mHelper = new ClusterRefDeregistrationHelper(
82                             getName(), getMBeanServer());
83         } catch (Exception JavaDoc ex) {
84             logWarning("ClusterRefConfig unregisterMisc failed. " +
85                     "ClusterRefDeregistrationHelper creation failed");
86         }
87     }
88
89     public void postDeregister() {
90         super.postDeregister();
91         try {
92             Map JavaDoc<String JavaDoc,LoadBalancerConfig> relevantLoadBalancerConfigMap =
93                 new HashMap JavaDoc<String JavaDoc,LoadBalancerConfig>();
94
95             if (getContainer() instanceof LBConfig) {
96                 String JavaDoc lbConfigName = ((LBConfig)getContainer()).getName();
97                 relevantLoadBalancerConfigMap =
98                     mHelper.fetchLoadBalancerConfigs((LBConfig)getContainer());
99                 mHelper.unregisterMonitors(relevantLoadBalancerConfigMap);
100             }
101             mHelper = null;
102         } catch (Exception JavaDoc ex) {
103             logWarning("ClusterRefConfig postDeregistration failed. " +
104                     "Load Balancer Monitoring MBeans might be lying around");
105         }
106     }
107
108     private class ClusterRefDeregistrationHelper {
109
110         final static String JavaDoc J2EE_TYPE = "j2eeType";
111         final ObjectNames objectNames = ObjectNames.getInstance(JMX_DOMAIN);
112         String JavaDoc clusterName = null;
113         MBeanServer JavaDoc mbs = null;
114
115         public ClusterRefDeregistrationHelper(String JavaDoc clusterName, MBeanServer JavaDoc mbs) {
116             this.mbs = mbs;
117             this.clusterName = clusterName;
118         }
119
120         Map JavaDoc<String JavaDoc, LoadBalancerConfig> fetchLoadBalancerConfigs(LBConfig lbConfig) {
121             String JavaDoc lbConfigName = lbConfig.getName();
122             Map JavaDoc<String JavaDoc,LoadBalancerConfig> allLoadBalancerConfigMap =
123                  getDomainRoot().getDomainConfig().getLoadBalancerConfigMap();
124             Map JavaDoc<String JavaDoc,LoadBalancerConfig>
125                  relevantLoadBalancerConfigMap = new HashMap JavaDoc<String JavaDoc,LoadBalancerConfig>();
126
127             for (String JavaDoc loadBalancerName : allLoadBalancerConfigMap.keySet()) {
128                 LoadBalancerConfig loadBalancerConfig =
129                     allLoadBalancerConfigMap.get(loadBalancerName);
130                 if (loadBalancerConfig.getLbConfigName().equals(lbConfigName))
131                     relevantLoadBalancerConfigMap.put(
132                         loadBalancerName, loadBalancerConfig);
133             }
134             
135             return relevantLoadBalancerConfigMap;
136         }
137
138         void unregisterMonitors(
139             Map JavaDoc<String JavaDoc,LoadBalancerConfig> relevantLoadBalancerConfigMap)
140             throws JMException JavaDoc {
141
142             for (String JavaDoc loadBalancerName : relevantLoadBalancerConfigMap.keySet()) {
143                LoadBalancerMonitor loadBalancerMonitor =
144                     LBDeregistrationUtil.getInstance(mbs)
145                         .fetchLBMonitoringRoot(loadBalancerName);
146
147                Map JavaDoc<String JavaDoc,LoadBalancerClusterMonitor> lbcmMap =
148                    loadBalancerMonitor.getLoadBalancerClusterMonitorMap();
149
150                LoadBalancerClusterMonitor lbcm = lbcmMap.get(clusterName);
151
152                //loadBalancerServerMonitorMap will have only one element for every
153
//standalone server as it is is wrapped up in a default cluster
154
Map JavaDoc<String JavaDoc,LoadBalancerServerMonitor> lbsmMap =
155                     lbcm.getLoadBalancerServerMonitorMap();
156
157                for (LoadBalancerServerMonitor lbsm : lbsmMap.values()) {
158
159                    Map JavaDoc<String JavaDoc,LoadBalancerApplicationMonitor>
160                        lbamMap = lbsm.getLoadBalancerApplicationMonitorMap();
161
162                    for (LoadBalancerApplicationMonitor lbam : lbamMap.values()) {
163                         Map JavaDoc<String JavaDoc,LoadBalancerContextRootMonitor>
164                             lbcrmMap = lbam.getLoadBalancerContextRootMonitorMap();
165                        for (LoadBalancerContextRootMonitor lbcrm : lbcrmMap.values()) {
166                             ObjectName JavaDoc lbcrmObjName = Util.getObjectName(lbcrm);
167                             mbs.unregisterMBean(lbcrmObjName );
168                         }
169
170                         ObjectName JavaDoc lbamObjName = Util.getObjectName(lbam);
171                         mbs.unregisterMBean(lbamObjName);
172                     }
173
174                     ObjectName JavaDoc loadBalancerServerMonitorObjName =
175                         Util.getObjectName(lbsm);
176                         mbs.unregisterMBean(loadBalancerServerMonitorObjName);
177                 }
178
179                 ObjectName JavaDoc lbcmObjName = Util.getObjectName(lbcm);
180                 mbs.unregisterMBean(lbcmObjName);
181             }
182         }
183     }
184 }
185
186
187
188
189
190
191
192
Popular Tags