KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.webjmx.adapter;
10
11 import java.io.*;
12 import java.util.*;
13 import javax.management.*;
14
15 import com.sun.jdmk.comm.*;
16
17 /** This adapter is a wrapper for the RemoteMBeanServer class from the open source "Remoting" package.
18  *
19  * parameter list: [host name]:[port]:[service name]
20  *
21  * @author john aronson
22  */

23 public class RemotingAdapter implements JMXServiceAdapter, MBeanServer
24 {
25     protected RmiConnectorAddress address;
26     protected RemoteMBeanServer server;
27     
28
29     public void initialize(List params)
30         throws Exception JavaDoc
31     {
32     address = new RmiConnectorAddress();
33         if(params.size() > 0 && params.get(0) != null)
34         {
35             address.setHost(params.get(0).toString());
36         }
37         if(params.size() > 1 && params.get(1) != null)
38         {
39             try { address.setPort(Integer.parseInt(params.get(1).toString())); }
40             catch(Exception JavaDoc ex) { System.out.println("failed to parse string into port number: " +params.get(1)); }
41         }
42         if(params.size() > 2 && params.get(2) != null)
43         {
44             address.setName(params.get(2).toString());
45         }
46         
47         if(Boolean.getBoolean(org.webjmx.tags.JMXTaglibConstants.DEBUG_PROP))
48         {
49             System.out.println("Connecting to remote MBeanServer via RMI Connector Address ["
50                 +address.getHost() +", " +address.getPort() +", " +address.getName() +"]");
51         }
52     }
53     
54     public void connect() throws Exception JavaDoc
55     {
56         server = new RmiConnectorClient();
57         
58         server.connect(address);
59     }
60     
61     public Object JavaDoc instantiate(String JavaDoc str, ObjectName objectName)
62         throws ReflectionException, MBeanException, InstanceNotFoundException
63     {
64         throw new MBeanException(null, "not supported for this service");
65     }
66     
67     public boolean isInstanceOf(ObjectName objectName, String JavaDoc str)
68         throws InstanceNotFoundException
69     {
70         return server.isInstanceOf(objectName, str);
71     }
72     
73     public ObjectInstance registerMBean(Object JavaDoc obj, ObjectName objectName)
74         throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException
75     {
76         throw new MBeanRegistrationException(null, "not supported for this service");
77     }
78     
79     public String JavaDoc getDefaultDomain()
80     {
81         return server.getDefaultDomain();
82     }
83     
84     public MBeanInfo getMBeanInfo(ObjectName objectName)
85         throws InstanceNotFoundException, IntrospectionException, ReflectionException
86     {
87         return server.getMBeanInfo(objectName);
88     }
89     
90     public ObjectInstance getObjectInstance(ObjectName objectName)
91         throws InstanceNotFoundException
92     {
93         return server.getObjectInstance(objectName);
94     }
95     
96     public Object JavaDoc instantiate(String JavaDoc str)
97         throws ReflectionException, MBeanException
98     {
99         throw new MBeanException(null, "not supported for this service");
100     }
101     
102     public boolean isRegistered(ObjectName objectName)
103     {
104         return server.isRegistered(objectName);
105     }
106     
107     public void addNotificationListener(ObjectName objectName, NotificationListener notificationListener,
108         NotificationFilter notificationFilter, Object JavaDoc obj)
109             throws InstanceNotFoundException
110     {
111         server.addNotificationListener(objectName, notificationListener, notificationFilter, obj);
112     }
113     
114     public void addNotificationListener(ObjectName objectName, ObjectName objectName1,
115         NotificationFilter notificationFilter, Object JavaDoc obj)
116             throws InstanceNotFoundException
117     {
118         throw new InstanceNotFoundException("not supported for this service");
119     }
120     
121     public ObjectInstance createMBean(String JavaDoc str, ObjectName objectName, ObjectName objectName2)
122         throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException
123     {
124         return server.createMBean(str, objectName, objectName2);
125     }
126     
127     public ObjectInstance createMBean(String JavaDoc str, ObjectName objectName)
128         throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException
129     {
130         return server.createMBean(str, objectName);
131     }
132     
133     public Object JavaDoc getAttribute(ObjectName objectName, String JavaDoc str)
134         throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException
135     {
136         return server.getAttribute(objectName, str);
137     }
138     
139     public ObjectInstance createMBean(String JavaDoc str, ObjectName objectName, Object JavaDoc[] obj, String JavaDoc[] str3)
140         throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException
141     {
142         return server.createMBean(str, objectName, obj, str3);
143     }
144     
145     public ObjectInstance createMBean(String JavaDoc str, ObjectName objectName, ObjectName objectName2, Object JavaDoc[] obj, String JavaDoc[] str4)
146         throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException
147     {
148         return server.createMBean(str, objectName, objectName2, obj, str4);
149     }
150     
151     public void setAttribute(ObjectName objectName, Attribute attribute)
152         throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException
153     {
154         server.setAttribute(objectName, attribute);
155     }
156     
157     public Object JavaDoc instantiate(String JavaDoc str, ObjectName objectName, Object JavaDoc[] obj, String JavaDoc[] str3)
158         throws ReflectionException, MBeanException, InstanceNotFoundException
159     {
160         throw new MBeanException(null, "not supported by this service");
161     }
162     
163     public Object JavaDoc instantiate(String JavaDoc str, Object JavaDoc[] obj, String JavaDoc[] str2)
164         throws ReflectionException, MBeanException
165     {
166         throw new MBeanException(null, "not supported by this service");
167     }
168     
169     public ObjectInputStream deserialize(String JavaDoc str, ObjectName objectName, byte[] values)
170         throws InstanceNotFoundException, OperationsException, ReflectionException
171     {
172         throw new OperationsException("not supported by this service");
173     }
174     
175     public ObjectInputStream deserialize(String JavaDoc str, byte[] values)
176         throws OperationsException, ReflectionException
177     {
178         throw new OperationsException("not supported by this service");
179     }
180     
181     public Set queryMBeans(ObjectName objectName, QueryExp queryExp)
182     {
183         return server.queryMBeans(objectName, queryExp);
184     }
185     
186     public AttributeList setAttributes(ObjectName objectName, AttributeList attributeList)
187         throws InstanceNotFoundException, ReflectionException
188     {
189         return server.setAttributes(objectName, attributeList);
190     }
191     
192     public Integer JavaDoc getMBeanCount()
193     {
194         return server.getMBeanCount();
195     }
196     
197     public Object JavaDoc invoke(ObjectName objectName, String JavaDoc str, Object JavaDoc[] obj, String JavaDoc[] str3)
198         throws InstanceNotFoundException, MBeanException, ReflectionException
199     {
200         return server.invoke(objectName, str, obj, str3);
201     }
202     
203     public ObjectInputStream deserialize(ObjectName objectName, byte[] values)
204         throws InstanceNotFoundException, OperationsException
205     {
206         throw new OperationsException("not supported by this service");
207     }
208     
209     public AttributeList getAttributes(ObjectName objectName, String JavaDoc[] str)
210         throws InstanceNotFoundException, ReflectionException
211     {
212         return server.getAttributes(objectName, str);
213     }
214     
215     public Set queryNames(ObjectName objectName, QueryExp queryExp)
216     {
217         return server.queryNames(objectName, queryExp);
218     }
219     
220     public void unregisterMBean(ObjectName objectName)
221         throws InstanceNotFoundException, MBeanRegistrationException
222     {
223         server.unregisterMBean(objectName);
224     }
225     
226     public void removeNotificationListener(ObjectName objectName, ObjectName objectName1)
227         throws InstanceNotFoundException, ListenerNotFoundException
228     {
229         throw new ListenerNotFoundException("not supported by this service");
230     }
231     
232     public void removeNotificationListener(ObjectName objectName, NotificationListener notificationListener)
233         throws InstanceNotFoundException, ListenerNotFoundException
234     {
235         server.removeNotificationListener(objectName, notificationListener);
236     }
237 }
238
Popular Tags