KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.Serializable JavaDoc;
12 import javax.management.MBeanServer JavaDoc;
13 import javax.management.ObjectName JavaDoc;
14 import org.jboss.remoting.ConnectionFailedException;
15 import org.jboss.remoting.ident.Identity;
16 import org.jboss.remoting.loading.ClassUtil;
17
18 /**
19  * MBeanLocator is used to uniquely indentify and locate a specific MBean on the JMX remoting
20  * network.
21  *
22  * @author <a HREF="mailto:jhaynie@vocalocity.net">Jeff Haynie</a>
23  * @version $Revision: 30392 $
24  */

25 public class MBeanLocator implements Serializable JavaDoc
26 {
27    static final long serialVersionUID = -95280512054710509L;
28
29    private final Identity identity;
30    private final ObjectName JavaDoc objectName;
31    private final MBeanServerLocator locator;
32
33    public MBeanLocator(MBeanServerLocator sl, ObjectName JavaDoc obj)
34    {
35       this.identity = sl.getIdentity();
36       this.locator = sl;
37       this.objectName = obj;
38    }
39
40    public boolean equals(Object JavaDoc o)
41    {
42       if(this == o)
43       {
44          return true;
45       }
46       if(!(o instanceof MBeanLocator))
47       {
48          return false;
49       }
50
51       final MBeanLocator mBeanLocator = (MBeanLocator) o;
52
53       if(identity != null ? !identity.equals(mBeanLocator.identity) : mBeanLocator.identity != null)
54       {
55          return false;
56       }
57       if(locator != null ? !locator.equals(mBeanLocator.locator) : mBeanLocator.locator != null)
58       {
59          return false;
60       }
61       if(objectName != null ? !objectName.equals(mBeanLocator.objectName) : mBeanLocator.objectName != null)
62       {
63          return false;
64       }
65
66       return true;
67    }
68
69    public int hashCode()
70    {
71       int result;
72       result = (identity != null ? identity.hashCode() : 0);
73       result = 29 * result + (objectName != null ? objectName.hashCode() : 0);
74       result = 29 * result + (locator != null ? locator.hashCode() : 0);
75       return result;
76    }
77
78    /**
79     * return the server locator for this mbean
80     *
81     * @return
82     */

83    public MBeanServerLocator getServerLocator()
84    {
85       return this.locator;
86    }
87
88    /**
89     * return the identity of the mbean server
90     *
91     * @return
92     */

93    public final Identity getIdentity()
94    {
95       return this.identity;
96    }
97
98    /**
99     * return the ObjectName that identifies the MBean
100     *
101     * @return
102     */

103    public final ObjectName JavaDoc getObjectName()
104    {
105       return objectName;
106    }
107
108    /**
109     * stringify
110     *
111     * @return
112     */

113    public String JavaDoc toString()
114    {
115       return "MBeanLocator [server:" + locator + ",mbean:" + objectName + "]";
116    }
117
118    /**
119     * returns true if the MBeanLocator is the same JVM as this locator
120     *
121     * @param locator
122     * @return
123     */

124    public boolean isSameJVM(MBeanLocator locator)
125    {
126       return locator != null && locator.locator.equals(this.locator);
127    }
128
129
130    /**
131     * narrow this locator to an interface class that the MBean locator implements
132     *
133     * @param interfaceCl
134     * @return
135     */

136    public Object JavaDoc narrow(Class JavaDoc interfaceCl)
137    {
138       Class JavaDoc cl[] = ClassUtil.getInterfacesFor(interfaceCl);
139       return narrow(cl);
140    }
141
142    /**
143     * return a dynamic proxy to the remote mbean server where this locator lives ...
144     *
145     * @return
146     * @throws ConnectionFailedException
147     */

148    public MBeanServer JavaDoc getMBeanServer()
149          throws ConnectionFailedException
150    {
151       return locator.getMBeanServer();
152    }
153
154    /**
155     * narrow the locator to a specific Class interface that the MBean locator implements
156     *
157     * @param interfaces
158     * @return
159     */

160    public Object JavaDoc narrow(Class JavaDoc interfaces[])
161    {
162       return MoveableMBean.create(this, interfaces);
163    }
164 }
165
Popular Tags