KickJava   Java API By Example, From Geeks To Geeks.

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


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.Hashtable JavaDoc;
26 import java.util.Map JavaDoc;
27 import javax.management.JMException JavaDoc;
28 import javax.management.MBeanServer JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30 import javax.management.Notification JavaDoc;
31 import javax.management.NotificationListener JavaDoc;
32 import javax.management.AttributeChangeNotification JavaDoc;
33
34 import static com.sun.appserv.management.base.AMX.J2EE_TYPE_KEY;
35 import static com.sun.appserv.management.base.AMX.NAME_KEY;
36 import static com.sun.appserv.management.base.AMX.JMX_DOMAIN;
37 import static com.sun.appserv.management.base.XTypes.LOAD_BALANCER;
38 import static com.sun.appserv.management.base.XTypes.LOAD_BALANCER_CONFIG;
39 import static com.sun.appserv.management.base.XTypes.LOAD_BALANCER_MONITOR;
40 import static com.sun.appserv.management.base.XTypes.LB_CONFIG;
41
42 import com.sun.enterprise.management.support.AMXServerLogger;
43 import com.sun.enterprise.management.support.AMXMBeanRootLogger;
44
45 import com.sun.appserv.management.config.LoadBalancerConfig;
46 import com.sun.appserv.management.config.LBConfig;
47 import com.sun.appserv.management.client.ProxyFactory;
48 import com.sun.appserv.management.monitor.LoadBalancerMonitor;
49 import com.sun.appserv.management.base.Util;
50
51 /**
52  * Utilities to help the DeregisterationHelpers that are
53  * invoked in postDeRegister() methods of the config MBeans
54  */

55 public final class LBDeregistrationUtil {
56
57     private MBeanServer JavaDoc mbs = null;
58     private Map JavaDoc<String JavaDoc, NotificationListener JavaDoc> mLBConfigListenersMap = null;
59     private static LBDeregistrationUtil mUtil = null;
60             
61     private LBDeregistrationUtil(MBeanServer JavaDoc mbs) {
62         mLBConfigListenersMap = new Hashtable JavaDoc<String JavaDoc, NotificationListener JavaDoc>();
63         this.mbs=mbs;
64     }
65     
66     public static LBDeregistrationUtil getInstance(MBeanServer JavaDoc mbs) {
67         if (mUtil == null) mUtil = new LBDeregistrationUtil(mbs);
68         return mUtil;
69     }
70     
71     public LoadBalancerMonitor fetchLBMonitoringRoot(
72         String JavaDoc loadBalancerName) throws JMException JavaDoc {
73
74         ObjectName JavaDoc loadBalancerMonitorObjName =
75             new ObjectName JavaDoc(JMX_DOMAIN + ":" + J2EE_TYPE_KEY + "=" +
76                 LOAD_BALANCER_MONITOR + "," + NAME_KEY + "=" + loadBalancerName);
77         LoadBalancerMonitor loadBalancerMonitor =
78             ProxyFactory.getInstance(mbs).getProxy(loadBalancerMonitorObjName, LoadBalancerMonitor.class);
79
80         return loadBalancerMonitor;
81     }
82     
83     public void addLBConfigListener(String JavaDoc loadBalancerName,
84         NotificationListener JavaDoc nl, LBConfig lbConfig) {
85         lbConfig.addNotificationListener(nl, null, null);
86         mLBConfigListenersMap.put(loadBalancerName, nl);
87     }
88
89     public void removeLBConfigListener(String JavaDoc loadBalancerName, LBConfig lbConfig)
90         throws JMException JavaDoc {
91         lbConfig.removeNotificationListener(
92             (NotificationListener JavaDoc)mLBConfigListenersMap.get(loadBalancerName));
93         mLBConfigListenersMap.remove(loadBalancerName);
94     }
95 }
Popular Tags