001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.jmx.remote;
031:
032: import com.caucho.hessian.client.HessianProxyFactory;
033: import com.caucho.hessian.jmx.JMXSerializerFactory;
034: import com.caucho.util.L10N;
035: import com.caucho.util.Log;
036: import com.caucho.vfs.IOExceptionWrapper;
037:
038: import javax.management.*;
039: import java.io.IOException;
040: import java.util.Set;
041: import java.util.logging.Logger;
042:
043: /**
044: * Static convenience methods.
045: */
046: public class HessianMBeanServerConnection implements
047: MBeanServerConnection {
048: private static final L10N L = new L10N(
049: HessianMBeanServerConnection.class);
050: private static final Logger log = Log
051: .open(HessianMBeanServerConnection.class);
052:
053: private String _url;
054: private RemoteJMX _jmxProxy;
055:
056: /**
057: * Creates the MBeanClient.
058: */
059: public HessianMBeanServerConnection() {
060: }
061:
062: /**
063: * Creates the MBeanClient.
064: */
065: public HessianMBeanServerConnection(String url) {
066: _url = url;
067: }
068:
069: /**
070: * Sets the proxy
071: */
072: public void setProxy(RemoteJMX proxy) {
073: _jmxProxy = proxy;
074: }
075:
076: /**
077: * Returns the mbean info
078: */
079: public MBeanInfo getMBeanInfo(ObjectName objectName)
080: throws InstanceNotFoundException, IntrospectionException,
081: ReflectionException, IOException {
082: try {
083: return getProxy().getMBeanInfo(
084: objectName.getCanonicalName());
085: } catch (JMException ex) {
086: if (ex instanceof InstanceNotFoundException)
087: throw (InstanceNotFoundException) ex;
088:
089: if (ex instanceof IntrospectionException)
090: throw (IntrospectionException) ex;
091:
092: if (ex instanceof ReflectionException)
093: throw (ReflectionException) ex;
094:
095: throw new RuntimeException(ex);
096: }
097: }
098:
099: public boolean isInstanceOf(ObjectName name, String className)
100: throws InstanceNotFoundException, IOException {
101:
102: // XXX: unimplemented
103: if (true)
104: throw new UnsupportedOperationException("unimplemented");
105:
106: return false;
107: }
108:
109: /**
110: * Gets an attribute.
111: */
112: public Object getAttribute(ObjectName objectName, String attrName)
113: throws MBeanException, AttributeNotFoundException,
114: InstanceNotFoundException, ReflectionException, IOException {
115: try {
116: return getProxy().getAttribute(
117: objectName.getCanonicalName(), attrName);
118: } catch (JMException ex) {
119: if (ex instanceof MBeanException)
120: throw (MBeanException) ex;
121:
122: if (ex instanceof AttributeNotFoundException)
123: throw (AttributeNotFoundException) ex;
124:
125: if (ex instanceof InstanceNotFoundException)
126: throw (InstanceNotFoundException) ex;
127:
128: if (ex instanceof ReflectionException)
129: throw (ReflectionException) ex;
130:
131: throw new RuntimeException(ex);
132: }
133: }
134:
135: public AttributeList getAttributes(ObjectName name,
136: String[] attributes) throws InstanceNotFoundException,
137: ReflectionException, IOException {
138:
139: // XXX: unimplemented
140: if (true)
141: throw new UnsupportedOperationException("unimplemented");
142:
143: return null;
144: }
145:
146: public void setAttribute(ObjectName name, Attribute attribute)
147: throws InstanceNotFoundException,
148: AttributeNotFoundException, InvalidAttributeValueException,
149: MBeanException, ReflectionException, IOException {
150:
151: // XXX: unimplemented
152: if (true)
153: throw new UnsupportedOperationException("unimplemented");
154:
155: }
156:
157: public AttributeList setAttributes(ObjectName name,
158: AttributeList attributes) throws InstanceNotFoundException,
159: ReflectionException, IOException {
160:
161: // XXX: unimplemented
162: if (true)
163: throw new UnsupportedOperationException("unimplemented");
164:
165: return null;
166: }
167:
168: public Object invoke(ObjectName name, String operationName,
169: Object params[], String signature[])
170: throws InstanceNotFoundException, MBeanException,
171: ReflectionException, IOException {
172:
173: // XXX: unimplemented
174: if (true)
175: throw new UnsupportedOperationException("unimplemented");
176:
177: return null;
178: }
179:
180: public String getDefaultDomain() throws IOException {
181:
182: // XXX: unimplemented
183: if (true)
184: throw new UnsupportedOperationException("unimplemented");
185:
186: return null;
187: }
188:
189: public String[] getDomains() throws IOException {
190:
191: // XXX: unimplemented
192: if (true)
193: throw new UnsupportedOperationException("unimplemented");
194:
195: return new String[0];
196: }
197:
198: public void addNotificationListener(ObjectName name,
199: NotificationListener listener, NotificationFilter filter,
200: Object handback) throws InstanceNotFoundException,
201: IOException {
202:
203: // XXX: unimplemented
204: if (true)
205: throw new UnsupportedOperationException("unimplemented");
206:
207: }
208:
209: public void addNotificationListener(ObjectName name,
210: ObjectName listener, NotificationFilter filter,
211: Object handback) throws InstanceNotFoundException,
212: IOException {
213:
214: // XXX: unimplemented
215: if (true)
216: throw new UnsupportedOperationException("unimplemented");
217:
218: }
219:
220: public void removeNotificationListener(ObjectName name,
221: ObjectName listener) throws InstanceNotFoundException,
222: ListenerNotFoundException, IOException {
223:
224: // XXX: unimplemented
225: if (true)
226: throw new UnsupportedOperationException("unimplemented");
227:
228: }
229:
230: public void removeNotificationListener(ObjectName name,
231: ObjectName listener, NotificationFilter filter,
232: Object handback) throws InstanceNotFoundException,
233: ListenerNotFoundException, IOException {
234:
235: // XXX: unimplemented
236: if (true)
237: throw new UnsupportedOperationException("unimplemented");
238:
239: }
240:
241: public void removeNotificationListener(ObjectName name,
242: NotificationListener listener)
243: throws InstanceNotFoundException,
244: ListenerNotFoundException, IOException {
245:
246: // XXX: unimplemented
247: if (true)
248: throw new UnsupportedOperationException("unimplemented");
249:
250: }
251:
252: public void removeNotificationListener(ObjectName name,
253: NotificationListener listener, NotificationFilter filter,
254: Object handback) throws InstanceNotFoundException,
255: ListenerNotFoundException, IOException {
256:
257: // XXX: unimplemented
258: if (true)
259: throw new UnsupportedOperationException("unimplemented");
260:
261: }
262:
263: public ObjectInstance createMBean(String className, ObjectName name)
264: throws ReflectionException, InstanceAlreadyExistsException,
265: MBeanRegistrationException, MBeanException,
266: NotCompliantMBeanException, IOException {
267: // XXX: unimplemented
268: if (true)
269: throw new UnsupportedOperationException("unimplemented");
270:
271: return null;
272: }
273:
274: public ObjectInstance createMBean(String className,
275: ObjectName name, ObjectName loaderName)
276: throws ReflectionException, InstanceAlreadyExistsException,
277: MBeanRegistrationException, MBeanException,
278: NotCompliantMBeanException, InstanceNotFoundException,
279: IOException {
280:
281: // XXX: unimplemented
282: if (true)
283: throw new UnsupportedOperationException("unimplemented");
284:
285: return null;
286: }
287:
288: public ObjectInstance createMBean(String className,
289: ObjectName name, Object params[], String signature[])
290: throws ReflectionException, InstanceAlreadyExistsException,
291: MBeanRegistrationException, MBeanException,
292: NotCompliantMBeanException, IOException {
293:
294: // XXX: unimplemented
295: if (true)
296: throw new UnsupportedOperationException("unimplemented");
297:
298: return null;
299: }
300:
301: public ObjectInstance createMBean(String className,
302: ObjectName name, ObjectName loaderName, Object params[],
303: String signature[]) throws ReflectionException,
304: InstanceAlreadyExistsException, MBeanRegistrationException,
305: MBeanException, NotCompliantMBeanException,
306: InstanceNotFoundException, IOException {
307:
308: // XXX: unimplemented
309: if (true)
310: throw new UnsupportedOperationException("unimplemented");
311:
312: return null;
313: }
314:
315: public void unregisterMBean(ObjectName name)
316: throws InstanceNotFoundException,
317: MBeanRegistrationException, IOException {
318:
319: // XXX: unimplemented
320: if (true)
321: throw new UnsupportedOperationException("unimplemented");
322:
323: }
324:
325: /**
326: * Returns the object instance
327: */
328: public ObjectInstance getObjectInstance(ObjectName objectName)
329: throws InstanceNotFoundException, IOException {
330: MBeanInfo info = null;
331:
332: try {
333: info = getMBeanInfo(objectName);
334: } catch (IntrospectionException e) {
335: throw new IOExceptionWrapper(e);
336: } catch (ReflectionException e) {
337: throw new IOExceptionWrapper(e);
338: }
339:
340: String className = info.getClassName();
341:
342: return new ObjectInstance(objectName, className);
343: }
344:
345: public Set queryMBeans(ObjectName name, QueryExp query)
346: throws IOException {
347:
348: // XXX: unimplemented
349: if (true)
350: throw new UnsupportedOperationException("unimplemented");
351:
352: return null;
353: }
354:
355: public Set queryNames(ObjectName name, QueryExp query)
356: throws IOException {
357:
358: // XXX: unimplemented
359: if (true)
360: throw new UnsupportedOperationException("unimplemented");
361:
362: return null;
363: }
364:
365: public boolean isRegistered(ObjectName name) throws IOException {
366: return true;
367: }
368:
369: public Integer getMBeanCount() throws IOException {
370:
371: // XXX: unimplemented
372: if (true)
373: throw new UnsupportedOperationException("unimplemented");
374:
375: return null;
376: }
377:
378: private RemoteJMX getProxy() {
379: if (_jmxProxy == null) {
380: try {
381: HessianProxyFactory proxy = new HessianProxyFactory();
382: proxy.getSerializerFactory().addFactory(
383: new JMXSerializerFactory());
384: _jmxProxy = (RemoteJMX) proxy.create(_url);
385: } catch (Exception e) {
386: throw new RuntimeException(e);
387: }
388: }
389:
390: return _jmxProxy;
391: }
392: }
|