KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webjmx > adapter > RMIAdapter


1 /*
2  * Copyright (C) WebJMX.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the WebJMX License version 2.0.
6  * See the terms of the WebJMX License in the documentation provided with this software.
7  */

8 /*
9  * SocketAdapter.java
10  *
11  * Created on December 20, 2001, 5:54 PM
12  */

13
14 package org.webjmx.adapter;
15
16 import java.io.*;
17 import java.util.*;
18 import javax.management.*;
19
20 import mx4j.connector.*;
21 import mx4j.connector.rmi.jrmp.*;
22
23 /** This adapter is a wrapper for the MX4J RemoteMBeanServer class. The jndiName parameter
24  * is required, and optional argument pairs can follow. The argument pairs will override
25  * the hashtable entried from the jndi.properties file.
26  *
27  * parameter list: <jndi name>[:param name 1:param value 1][:param name 2:param value 2]
28  *
29  * @author john aronson
30  */

31 public class RMIAdapter
32     implements JMXServiceAdapter, MBeanServer
33 {
34     protected String JavaDoc jndiName;
35     protected Hashtable environment = new Hashtable();
36     protected RemoteMBeanServer server;
37     
38
39     public void initialize(List params)
40         throws Exception JavaDoc
41     {
42         if(params.size() < 1)
43             throw new Exception JavaDoc("missing host name");
44
45         jndiName = (String JavaDoc)params.get(0);
46
47         javax.naming.Context JavaDoc ctx = new javax.naming.InitialContext JavaDoc();
48         environment.putAll(ctx.getEnvironment());
49         environment.put("java.naming.factory.initial", "com.sun.jndi.rmi.registry.RegistryContextFactory");
50         
51         for(int i = 1; i < params.size(); i += 2)
52         {
53             String JavaDoc name = (String JavaDoc)params.get(i);
54             String JavaDoc value = (String JavaDoc)params.get(i+1);
55             environment.put(name, value);
56         }
57         
58         if(Boolean.getBoolean(org.webjmx.tags.JMXTaglibConstants.DEBUG_PROP))
59         {
60             System.out.println("JRMPConnector environment ...");
61             Enumeration e = environment.keys();
62             while(e.hasMoreElements())
63             {
64                 String JavaDoc s = (String JavaDoc)e.nextElement();
65                 System.out.println(s +" : " +environment.get(s));
66             }
67             System.out.println("end JRMPConnector environment.");
68             System.out.println("InitialContext bindings ...");
69             javax.naming.NamingEnumeration JavaDoc ne = ctx.listBindings("");
70             while(ne.hasMore())
71             {
72                 javax.naming.Binding JavaDoc b = (javax.naming.Binding JavaDoc)ne.next();
73                 System.out.println(b.getName() + " : " +b.getObject());
74             }
75             System.out.println("end InitialContext bindings");
76         }
77     }
78     
79     public void connect() throws Exception JavaDoc
80     {
81         JRMPConnector connector = new JRMPConnector();
82     connector.connect(jndiName, environment);
83         server = connector.getRemoteMBeanServer();
84     }
85     
86     public Object JavaDoc instantiate(String JavaDoc str, ObjectName objectName)
87         throws ReflectionException, MBeanException, InstanceNotFoundException
88     {
89         throw new MBeanException(null, "not supported for this service");
90     }
91     
92     public boolean isInstanceOf(ObjectName objectName, String JavaDoc str)
93         throws InstanceNotFoundException
94     {
95         return server.isInstanceOf(objectName, str);
96     }
97     
98     public ObjectInstance registerMBean(Object JavaDoc obj, ObjectName objectName)
99         throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException
100     {
101         return server.registerMBean(obj, objectName);
102     }
103     
104     public String JavaDoc getDefaultDomain()
105     {
106         return server.getDefaultDomain();
107     }
108     
109     public MBeanInfo getMBeanInfo(ObjectName objectName)
110         throws InstanceNotFoundException, IntrospectionException, ReflectionException
111     {
112         return server.getMBeanInfo(objectName);
113     }
114     
115     public ObjectInstance getObjectInstance(ObjectName objectName)
116         throws InstanceNotFoundException
117     {
118         return server.getObjectInstance(objectName);
119     }
120     
121     public Object JavaDoc instantiate(String JavaDoc str)
122         throws ReflectionException, MBeanException
123     {
124         throw new MBeanException(null, "not supported for this service");
125     }
126     
127     public boolean isRegistered(ObjectName objectName)
128     {
129         return server.isRegistered(objectName);
130     }
131     
132     public void addNotificationListener(ObjectName objectName, NotificationListener notificationListener,
133         NotificationFilter notificationFilter, Object JavaDoc obj)
134             throws InstanceNotFoundException
135     {
136         server.addNotificationListener(objectName, notificationListener, notificationFilter, obj);
137     }
138     
139     public void addNotificationListener(ObjectName objectName, ObjectName objectName1,
140         NotificationFilter notificationFilter, Object JavaDoc obj)
141             throws InstanceNotFoundException
142     {
143         throw new InstanceNotFoundException("not supported for this service");
144     }
145     
146     public ObjectInstance createMBean(String JavaDoc str, ObjectName objectName, ObjectName objectName2)
147         throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException
148     {
149         return server.createMBean(str, objectName, objectName2);
150     }
151     
152     public ObjectInstance createMBean(String JavaDoc str, ObjectName objectName)
153         throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException
154     {
155         return server.createMBean(str, objectName);
156     }
157     
158     public Object JavaDoc getAttribute(ObjectName objectName, String JavaDoc str)
159         throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException
160     {
161         return server.getAttribute(objectName, str);
162     }
163     
164     public ObjectInstance createMBean(String JavaDoc str, ObjectName objectName, Object JavaDoc[] obj, String JavaDoc[] str3)
165         throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException
166     {
167         return server.createMBean(str, objectName, obj, str3);
168     }
169     
170     public ObjectInstance createMBean(String JavaDoc str, ObjectName objectName, ObjectName objectName2, Object JavaDoc[] obj, String JavaDoc[] str4)
171         throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException
172     {
173         return server.createMBean(str, objectName, objectName2, obj, str4);
174     }
175     
176     public void setAttribute(ObjectName objectName, Attribute attribute)
177         throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException
178     {
179         server.setAttribute(objectName, attribute);
180     }
181     
182     public Object JavaDoc instantiate(String JavaDoc str, ObjectName objectName, Object JavaDoc[] obj, String JavaDoc[] str3)
183         throws ReflectionException, MBeanException, InstanceNotFoundException
184     {
185         throw new MBeanException(null, "not supported by this service");
186     }
187     
188     public Object JavaDoc instantiate(String JavaDoc str, Object JavaDoc[] obj, String JavaDoc[] str2)
189         throws ReflectionException, MBeanException
190     {
191         throw new MBeanException(null, "not supported by this service");
192     }
193     
194     public ObjectInputStream deserialize(String JavaDoc str, ObjectName objectName, byte[] values)
195         throws InstanceNotFoundException, OperationsException, ReflectionException
196     {
197         throw new OperationsException("not supported by this service");
198     }
199     
200     public ObjectInputStream deserialize(String JavaDoc str, byte[] values)
201         throws OperationsException, ReflectionException
202     {
203         throw new OperationsException("not supported by this service");
204     }
205     
206     public Set queryMBeans(ObjectName objectName, QueryExp queryExp)
207     {
208         return server.queryMBeans(objectName, queryExp);
209     }
210     
211     public AttributeList setAttributes(ObjectName objectName, AttributeList attributeList)
212         throws InstanceNotFoundException, ReflectionException
213     {
214         return server.setAttributes(objectName, attributeList);
215     }
216     
217     public Integer JavaDoc getMBeanCount()
218     {
219         return server.getMBeanCount();
220     }
221     
222     public Object JavaDoc invoke(ObjectName objectName, String JavaDoc str, Object JavaDoc[] obj, String JavaDoc[] str3)
223         throws InstanceNotFoundException, MBeanException, ReflectionException
224     {
225         return server.invoke(objectName, str, obj, str3);
226     }
227     
228     public ObjectInputStream deserialize(ObjectName objectName, byte[] values)
229         throws InstanceNotFoundException, OperationsException
230     {
231         throw new OperationsException("not supported by this service");
232     }
233     
234     public AttributeList getAttributes(ObjectName objectName, String JavaDoc[] str)
235         throws InstanceNotFoundException, ReflectionException
236     {
237         return server.getAttributes(objectName, str);
238     }
239     
240     public Set queryNames(ObjectName objectName, QueryExp queryExp)
241     {
242         return server.queryNames(objectName, queryExp);
243     }
244     
245     public void unregisterMBean(ObjectName objectName)
246         throws InstanceNotFoundException, MBeanRegistrationException
247     {
248         server.unregisterMBean(objectName);
249     }
250     
251     public void removeNotificationListener(ObjectName objectName, ObjectName objectName1)
252         throws InstanceNotFoundException, ListenerNotFoundException
253     {
254         throw new ListenerNotFoundException("not supported by this service");
255     }
256     
257     public void removeNotificationListener(ObjectName objectName, NotificationListener notificationListener)
258         throws InstanceNotFoundException, ListenerNotFoundException
259     {
260         server.removeNotificationListener(objectName, notificationListener, null, null);
261     }
262 }
263
Popular Tags