KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jmx > RMIConnectorImpl


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: RMIConnectorImpl.java,v 1.5 2004/04/27 14:44:21 danesa Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas.jmx;
26
27 import javax.management.Attribute JavaDoc;
28 import javax.management.AttributeList JavaDoc;
29 import javax.management.AttributeNotFoundException JavaDoc;
30 import javax.management.InstanceNotFoundException JavaDoc;
31 import javax.management.IntrospectionException JavaDoc;
32 import javax.management.InvalidAttributeValueException JavaDoc;
33 import javax.management.MBeanException JavaDoc;
34 import javax.management.MBeanInfo JavaDoc;
35 import javax.management.MBeanServer JavaDoc;
36 import javax.management.NotificationFilter JavaDoc;
37 import javax.management.NotificationListener JavaDoc;
38 import javax.management.ObjectName JavaDoc;
39 import javax.management.QueryExp JavaDoc;
40 import javax.management.ReflectionException JavaDoc;
41 import javax.rmi.PortableRemoteObject JavaDoc;
42 import java.rmi.RemoteException JavaDoc;
43
44
45 /**
46  * Implements RMIConnector, the interface for JMX Remote Calls used by thr management applications.
47  * Uses a simple remote delegation of the JMX methods called by the management applications.
48  *
49  * @author Michel Bruno and Guillaume Riviere
50  */

51 public class RMIConnectorImpl extends PortableRemoteObject JavaDoc implements RMIConnector {
52     protected MBeanServer JavaDoc server;
53
54     public RMIConnectorImpl(MBeanServer JavaDoc server) throws RemoteException JavaDoc {
55         super();
56         this.server = server;
57     }
58
59     /**
60      * Gets the names of MBeans controlled by the MBean server.
61      * @param name - The object name pattern identifying the MBeans to be retrieved.
62      * @param query - The query expression to be applied for selecting MBeans.
63      * @return A set containing the ObjectNames for the MBeans selected.
64      * If no MBean satisfies the query, an empty list is returned.
65      */

66     public java.util.Set JavaDoc queryNames(ObjectName JavaDoc name,
67                     QueryExp JavaDoc query)
68     throws RemoteException JavaDoc {
69         return server.queryNames(name, query);
70     }
71
72     /**
73      * Checks whether an MBean, identified by its object name, is
74      * already registered with the MBean server.
75      * @param name - The object name pattern identifying the MBeans
76      */

77     public boolean isRegistered(ObjectName JavaDoc name)
78         throws RemoteException JavaDoc
79     {
80         return server.isRegistered(name);
81     }
82
83     /**
84      * Gets the value of a specific attribute of a named MBean.
85      * @param name - The name of the MBean
86      * @param attribute - the name of the attribute to be retrieved.
87      * @return The value of the retrieved attribute.
88      */

89     public java.lang.Object JavaDoc getAttribute(ObjectName JavaDoc name,
90                      java.lang.String JavaDoc attribute)
91         throws MBeanException JavaDoc,
92                AttributeNotFoundException JavaDoc,
93                InstanceNotFoundException JavaDoc,
94                ReflectionException JavaDoc,
95                RemoteException JavaDoc {
96         return server.getAttribute(name, attribute);
97     }
98
99     public AttributeList JavaDoc getAttributes(ObjectName JavaDoc name,
100                                        String JavaDoc[] attributes)
101         throws InstanceNotFoundException JavaDoc,
102                ReflectionException JavaDoc,
103                RemoteException JavaDoc {
104         return server.getAttributes(name, attributes);
105     }
106     /**
107      * Sets the value of a specific attribute of a named MBean.
108      * @param name - The name of the MBean
109      */

110     public void setAttribute(ObjectName JavaDoc name,
111                  Attribute JavaDoc attribute)
112         throws InstanceNotFoundException JavaDoc,
113                AttributeNotFoundException JavaDoc,
114                InvalidAttributeValueException JavaDoc,
115                MBeanException JavaDoc,
116                ReflectionException JavaDoc,
117                RemoteException JavaDoc {
118         server.setAttribute(name, attribute);
119     }
120
121     public AttributeList JavaDoc setAttributes(ObjectName JavaDoc name,
122                                        AttributeList JavaDoc attributes)
123         throws InstanceNotFoundException JavaDoc,
124                ReflectionException JavaDoc,
125                RemoteException JavaDoc {
126         return server.setAttributes(name, attributes);
127     }
128     /**
129      * Invokes an operation on an MBean.
130      * @param name - The name of the MBean
131      * @param operationName - The name of the operation to be invoked.
132      * @param params - An array containing the parameters to be set when the operation is invoked
133      * @param signature - An array containing the signature of the operation.
134      * The class objects will be loaded using the same class loader as the one
135      * used for loading the MBean on which the operation was invoked.
136      * @return The object returned by the operation
137      */

138     public Object JavaDoc invoke(ObjectName JavaDoc name,
139              java.lang.String JavaDoc operationName,
140              java.lang.Object JavaDoc[] params,
141              java.lang.String JavaDoc[] signature)
142     throws InstanceNotFoundException JavaDoc,
143            MBeanException JavaDoc,
144            ReflectionException JavaDoc,
145            RemoteException JavaDoc
146     {
147     return server.invoke(name, operationName, params, signature);
148     }
149
150     /**
151      * This method discovers the attributes and operations that an MBean
152      * exposes for management.
153      * @param name - The name of the MBean to analyze
154      * @return An instance of MBeanInfo allowing the retrieval of all
155      * attributes and operations of this MBean.
156      */

157     public MBeanInfo JavaDoc getMBeanInfo(ObjectName JavaDoc name)
158     throws InstanceNotFoundException JavaDoc,
159            IntrospectionException JavaDoc,
160            ReflectionException JavaDoc,
161            RemoteException JavaDoc
162     {
163     return this.server.getMBeanInfo(name);
164     }
165
166     /**
167      * Adds a listener to a registered MBean.
168      * @param name - The name of the MBean on which the listener should be added.
169      * @param listener - The listener object which will handle the notifications emitted by the registered MBean.
170      * @param listener - The listener object which will handle the notifications emitted by the registered MBean.
171      * @param filter - The filter object. If filter is null, no filtering will be performed before handling notifications.
172      * @param handback - The context to be sent to the listener when a notification is emitted.
173      */

174     public void addNotificationListener(ObjectName JavaDoc name,
175                                     NotificationListener JavaDoc listener,
176                                     NotificationFilter JavaDoc filter,
177                                     Object JavaDoc handback)
178         throws InstanceNotFoundException JavaDoc,
179                RemoteException JavaDoc
180     {
181         this.server.addNotificationListener(name, listener, filter, handback);
182     }
183
184     /**
185      * Adds a listener to a registered MBean.
186      * @param name - The name of the MBean on which the listener should be added.
187      * @param listener - The object name of the listener which will handle the notifications emitted by the registered MBean.
188      * @param listener - The listener object which will handle the notifications emitted by the registered MBean.
189      * @param filter - The filter object. If filter is null, no filtering will be performed before handling notifications.
190      * @param handback - The context to be sent to the listener when a notification is emitted.
191      */

192     public void addNotificationListener(ObjectName JavaDoc name,
193                                     ObjectName JavaDoc listener,
194                                     NotificationFilter JavaDoc filter,
195                                     Object JavaDoc handback)
196         throws InstanceNotFoundException JavaDoc,
197                RemoteException JavaDoc
198     {
199         this.server.addNotificationListener(name, listener, filter, handback);
200     }
201 }
202
Popular Tags