KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jmx > browser > model > connector > JBoss30RMIConnectionService


1 /*
2
3  * EJTools, the Enterprise Java Tools
4
5  *
6
7  * Distributable under LGPL license.
8
9  * See terms of license at www.gnu.org.
10
11  */

12
13 package org.ejtools.jmx.browser.model.connector;
14
15
16
17 import java.lang.reflect.Constructor JavaDoc;
18
19 import java.lang.reflect.Method JavaDoc;
20
21 import java.util.Hashtable JavaDoc;
22
23
24
25 import javax.naming.Context JavaDoc;
26
27 import javax.naming.InitialContext JavaDoc;
28
29 import javax.rmi.PortableRemoteObject JavaDoc;
30
31
32
33 import org.ejtools.jmx.MBeanServerProxy;
34
35 import org.ejtools.jmx.browser.model.service.ConnectionMetaData;
36
37
38
39
40
41 /**
42
43  * @author letiembl
44
45  * @created 4 septembre 2002
46
47  * @version $Revision: 1.6 $
48
49  */

50
51 public class JBoss30RMIConnectionService extends AbstractConnectionService
52
53 {
54
55    /** Description of the Field */
56
57    protected Object JavaDoc connector = null;
58
59
60
61
62
63    /**Constructor for the JBoss30RMIConnectionService object */
64
65    public JBoss30RMIConnectionService()
66
67    {
68
69    }
70
71
72
73
74
75    /** */
76
77    public void disconnect()
78
79    {
80
81       super.disconnect();
82
83       try
84
85       {
86
87          // Search for the stop method of the RMIConnector
88

89          Method JavaDoc m = this.connector.getClass().getMethod("stop", new Class JavaDoc[0]);
90
91          m.invoke(this.connector, new Object JavaDoc[0]);
92
93       }
94
95       catch (Exception JavaDoc e)
96
97       {
98
99          // Do nothing
100

101       }
102
103       this.setConnected(false);
104
105    }
106
107
108
109
110
111
112
113    /**
114
115     * @exception Exception Description of the Exception
116
117     */

118
119    protected void createMBeanServer()
120
121       throws Exception JavaDoc
122
123    {
124
125       System.setProperty("jmx.serial.form", "1.1");
126
127
128
129       Hashtable JavaDoc props = new Hashtable JavaDoc();
130
131       props.put(Context.INITIAL_CONTEXT_FACTORY, this.profile.getProperty(ConnectionMetaData.FACTORY));
132
133       props.put(Context.URL_PKG_PREFIXES, this.profile.getProperty(ConnectionMetaData.PACKAGES));
134
135       props.put(Context.PROVIDER_URL, this.profile.getProperty(ConnectionMetaData.URL));
136
137       props.put(Context.SECURITY_PRINCIPAL, this.profile.getProperty(ConnectionMetaData.PRINCIPAL));
138
139       props.put(Context.SECURITY_CREDENTIALS, this.profile.getProperty(ConnectionMetaData.CREDENTIALS));
140
141
142
143       InitialContext JavaDoc context = new InitialContext JavaDoc(props);
144
145       Object JavaDoc ref = context.lookup(this.profile.getProperty(ConnectionMetaData.CONTEXT));
146
147
148
149       Class JavaDoc clazzAdaptor = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.jmx.adaptor.rmi.RMIAdaptor");
150
151       Object JavaDoc adaptor = PortableRemoteObject.narrow(ref, clazzAdaptor);
152
153       Class JavaDoc clazzConnector = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.jmx.connector.rmi.RMIConnectorImpl");
154
155       Constructor JavaDoc constructor = clazzConnector.getConstructor(new Class JavaDoc[]{clazzAdaptor});
156
157       this.connector = constructor.newInstance(new Object JavaDoc[]{adaptor});
158
159
160
161       this.setMBeanServer(MBeanServerProxy.createMBeanProxy(this.connector));
162
163    }
164
165 }
166
167
Popular Tags