KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > remoting > MBeanServerRegistry


1 /***************************************
2  * *
3  * JBoss: The OpenSource J2EE WebOS *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  ***************************************/

9 package org.jboss.mx.remoting;
10
11 import java.util.Collections JavaDoc;
12 import java.util.HashMap JavaDoc;
13 import java.util.Map JavaDoc;
14 import javax.management.MBeanServer JavaDoc;
15 import org.jboss.logging.Logger;
16 import org.jboss.remoting.InvokerLocator;
17
18 /**
19  * MBeanServerRegistry is a registry for remote MBeanServer proxies that are registered in the local
20  * JVM.
21  *
22  * @author <a HREF="mailto:jhaynie@vocalocity.net">Jeff Haynie</a>
23  * @version $Revision: 30251 $
24  */

25 public class MBeanServerRegistry
26 {
27    private static final Logger log = Logger.getLogger(MBeanServerRegistry.class.getName());
28
29    private static final Map JavaDoc serversById = Collections.synchronizedMap(new HashMap JavaDoc());
30    private static final Map JavaDoc serversByLocator = Collections.synchronizedMap(new HashMap JavaDoc());
31
32    /**
33     * return true if the remote MbeanServer is registered for the given MBeanServer ID
34     *
35     * @param id
36     * @return
37     */

38    public static final boolean isMBeanServerRegistered(String JavaDoc id)
39    {
40       return getMBeanServerFor(id) != null;
41    }
42
43    /**
44     * return the MBeanServer proxy for a given MBeanServer id, or null if none registered
45     *
46     * @param id
47     * @return
48     */

49    public static final MBeanServer JavaDoc getMBeanServerFor(String JavaDoc id)
50    {
51       return (MBeanServer JavaDoc) serversById.get(id);
52    }
53
54    /**
55     * returns true if the remote MBeanServer proxy is registered for the given locator
56     *
57     * @param locator
58     * @return
59     */

60    public static final boolean isMBeanServerRegistered(InvokerLocator locator)
61    {
62       return getMBeanServerFor(locator) != null;
63    }
64
65    /**
66     * return the MBeanServer proxy for a given InvokerLocator, or null if none registered
67     *
68     * @param locator
69     * @return
70     */

71    public static final MBeanServer JavaDoc getMBeanServerFor(InvokerLocator locator)
72    {
73       return (MBeanServer JavaDoc) serversByLocator.get(locator);
74    }
75
76    static synchronized void register(MBeanServer JavaDoc server, MBeanServerClientInvokerProxy proxy)
77    {
78       String JavaDoc serverid = proxy.getServerId();
79       serversById.put(serverid, server);
80       serversByLocator.put(proxy.getLocator(), server);
81       if(log.isTraceEnabled())
82       {
83          log.trace("register called with proxy: " + proxy + " and serverid: " + serverid);
84       }
85    }
86
87    static synchronized void unregister(MBeanServerClientInvokerProxy proxy)
88    {
89       String JavaDoc serverid = proxy.getServerId();
90       serversById.remove(serverid);
91       serversByLocator.remove(proxy.getLocator());
92       if(log.isTraceEnabled())
93       {
94          log.trace("unregister called with proxy: " + proxy + " and serverid: " + serverid);
95       }
96    }
97 }
98
Popular Tags