001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: RMIConnectorImpl.java 4654 2004-04-27 14:44:22Z danesa $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jmx;
025:
026: import javax.management.Attribute;
027: import javax.management.AttributeList;
028: import javax.management.AttributeNotFoundException;
029: import javax.management.InstanceNotFoundException;
030: import javax.management.IntrospectionException;
031: import javax.management.InvalidAttributeValueException;
032: import javax.management.MBeanException;
033: import javax.management.MBeanInfo;
034: import javax.management.MBeanServer;
035: import javax.management.NotificationFilter;
036: import javax.management.NotificationListener;
037: import javax.management.ObjectName;
038: import javax.management.QueryExp;
039: import javax.management.ReflectionException;
040: import javax.rmi.PortableRemoteObject;
041: import java.rmi.RemoteException;
042:
043: /**
044: * Implements RMIConnector, the interface for JMX Remote Calls used by thr management applications.
045: * Uses a simple remote delegation of the JMX methods called by the management applications.
046: *
047: * @author Michel Bruno and Guillaume Riviere
048: */
049: public class RMIConnectorImpl extends PortableRemoteObject implements
050: RMIConnector {
051: protected MBeanServer server;
052:
053: public RMIConnectorImpl(MBeanServer server) throws RemoteException {
054: super ();
055: this .server = server;
056: }
057:
058: /**
059: * Gets the names of MBeans controlled by the MBean server.
060: * @param name - The object name pattern identifying the MBeans to be retrieved.
061: * @param query - The query expression to be applied for selecting MBeans.
062: * @return A set containing the ObjectNames for the MBeans selected.
063: * If no MBean satisfies the query, an empty list is returned.
064: */
065: public java.util.Set queryNames(ObjectName name, QueryExp query)
066: throws RemoteException {
067: return server.queryNames(name, query);
068: }
069:
070: /**
071: * Checks whether an MBean, identified by its object name, is
072: * already registered with the MBean server.
073: * @param name - The object name pattern identifying the MBeans
074: */
075: public boolean isRegistered(ObjectName name) throws RemoteException {
076: return server.isRegistered(name);
077: }
078:
079: /**
080: * Gets the value of a specific attribute of a named MBean.
081: * @param name - The name of the MBean
082: * @param attribute - the name of the attribute to be retrieved.
083: * @return The value of the retrieved attribute.
084: */
085: public java.lang.Object getAttribute(ObjectName name,
086: java.lang.String attribute) throws MBeanException,
087: AttributeNotFoundException, InstanceNotFoundException,
088: ReflectionException, RemoteException {
089: return server.getAttribute(name, attribute);
090: }
091:
092: public AttributeList getAttributes(ObjectName name,
093: String[] attributes) throws InstanceNotFoundException,
094: ReflectionException, RemoteException {
095: return server.getAttributes(name, attributes);
096: }
097:
098: /**
099: * Sets the value of a specific attribute of a named MBean.
100: * @param name - The name of the MBean
101: */
102: public void setAttribute(ObjectName name, Attribute attribute)
103: throws InstanceNotFoundException,
104: AttributeNotFoundException, InvalidAttributeValueException,
105: MBeanException, ReflectionException, RemoteException {
106: server.setAttribute(name, attribute);
107: }
108:
109: public AttributeList setAttributes(ObjectName name,
110: AttributeList attributes) throws InstanceNotFoundException,
111: ReflectionException, RemoteException {
112: return server.setAttributes(name, attributes);
113: }
114:
115: /**
116: * Invokes an operation on an MBean.
117: * @param name - The name of the MBean
118: * @param operationName - The name of the operation to be invoked.
119: * @param params - An array containing the parameters to be set when the operation is invoked
120: * @param signature - An array containing the signature of the operation.
121: * The class objects will be loaded using the same class loader as the one
122: * used for loading the MBean on which the operation was invoked.
123: * @return The object returned by the operation
124: */
125: public Object invoke(ObjectName name,
126: java.lang.String operationName, java.lang.Object[] params,
127: java.lang.String[] signature)
128: throws InstanceNotFoundException, MBeanException,
129: ReflectionException, RemoteException {
130: return server.invoke(name, operationName, params, signature);
131: }
132:
133: /**
134: * This method discovers the attributes and operations that an MBean
135: * exposes for management.
136: * @param name - The name of the MBean to analyze
137: * @return An instance of MBeanInfo allowing the retrieval of all
138: * attributes and operations of this MBean.
139: */
140: public MBeanInfo getMBeanInfo(ObjectName name)
141: throws InstanceNotFoundException, IntrospectionException,
142: ReflectionException, RemoteException {
143: return this .server.getMBeanInfo(name);
144: }
145:
146: /**
147: * Adds a listener to a registered MBean.
148: * @param name - The name of the MBean on which the listener should be added.
149: * @param listener - The listener object which will handle the notifications emitted by the registered MBean.
150: * @param listener - The listener object which will handle the notifications emitted by the registered MBean.
151: * @param filter - The filter object. If filter is null, no filtering will be performed before handling notifications.
152: * @param handback - The context to be sent to the listener when a notification is emitted.
153: */
154: public void addNotificationListener(ObjectName name,
155: NotificationListener listener, NotificationFilter filter,
156: Object handback) throws InstanceNotFoundException,
157: RemoteException {
158: this .server.addNotificationListener(name, listener, filter,
159: handback);
160: }
161:
162: /**
163: * Adds a listener to a registered MBean.
164: * @param name - The name of the MBean on which the listener should be added.
165: * @param listener - The object name of the listener which will handle the notifications emitted by the registered MBean.
166: * @param listener - The listener object which will handle the notifications emitted by the registered MBean.
167: * @param filter - The filter object. If filter is null, no filtering will be performed before handling notifications.
168: * @param handback - The context to be sent to the listener when a notification is emitted.
169: */
170: public void addNotificationListener(ObjectName name,
171: ObjectName listener, NotificationFilter filter,
172: Object handback) throws InstanceNotFoundException,
173: RemoteException {
174: this.server.addNotificationListener(name, listener, filter,
175: handback);
176: }
177: }
|