KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > agent > MEJBBean


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.management.agent;
25
26 import java.security.*;
27 import java.rmi.RemoteException JavaDoc;
28 import java.util.*;
29 import java.io.ObjectInputStream JavaDoc;
30 import javax.ejb.*;
31 import javax.management.*;
32 import javax.management.j2ee.*;
33 import javax.naming.*;
34
35 /**
36  * @ejbHome <{com.sun.enterprise.management.agent.MEJBHome}>
37  * @ejbRemote <{com.sun.enterprise.management.agent.MEJB}>
38  *
39  * @author Hans Hrasna
40  */

41 public class MEJBBean implements SessionBean {
42     private SessionContext ctx;
43     private MEJBHelper mejbHelper = null;
44     
45     public void setSessionContext(SessionContext context) {
46         ctx = context;
47     }
48
49     public void ejbActivate() {
50     }
51
52     public void ejbPassivate() {
53     }
54
55     public void ejbRemove() {
56     }
57
58     public void ejbCreate() throws CreateException {
59         this.mejbHelper = MEJBHelper.getMEJBHelper();
60     }
61
62     // javax.management.j2ee.Management implementation starts here
63

64     /**
65      * Gets the names of managed objects controlled by the MEJB. This method
66      * enables any of the following to be obtained: The names of all managed objects,
67      * the names of a set of managed objects specified by pattern matching on the
68      * <CODE>ObjectName</CODE> and/or a Query expression, a specific managed object name (equivalent to
69      * testing whether an managed object is registered). When the object name is
70      * null or no domain and key properties are specified, all objects are selected (and filtered if a
71      * query is specified). It returns the set of ObjectNames for the managed objects selected.
72      * @param name The object name pattern identifying the managed objects to be retrieved. If
73      * null or no domain and key properties are specified, all the managed objects registered will be retrieved.
74      * @param query The query expression to be applied for selecting managed objects. If null
75      * no query expression will be applied for selecting managed objects.
76      * @return A set containing the ObjectNames for the managed objects selected.
77      * If no managed object satisfies the query, an empty list is returned.
78      */

79     public Set queryNames(ObjectName name, QueryExp query) throws RemoteException JavaDoc {
80         try{
81             return this.mejbHelper.queryNames(name,query);
82         }catch(Exception JavaDoc ex){
83             throw new RemoteException JavaDoc(this.toString() +"::queryNames", ex);
84         }
85     }
86
87     /**
88      * Checks whether an MBean, identified by its object name, is already registered with the MBean server.
89      * @param name The object name of the MBean to be checked.
90      * @return True if the MBean is already registered in the MBean server, false otherwise.
91      */

92     public boolean isRegistered(ObjectName name) throws RemoteException JavaDoc {
93         try{
94             return this.mejbHelper.isRegistered(name);
95         }catch(Exception JavaDoc ex){
96             throw new RemoteException JavaDoc(this.toString() +"::isRegistered", ex);
97         }
98     }
99
100     /** Returns the number of MBeans registered in the MBean server. */
101     public Integer JavaDoc getMBeanCount() throws RemoteException JavaDoc {
102         try{
103             return this.mejbHelper.getMBeanCount();
104         }catch(Exception JavaDoc ex){
105             throw new RemoteException JavaDoc(this.toString() +"::getMBeanCount", ex);
106         }
107     }
108
109     /**
110      * This method discovers the attributes and operations that an MBean exposes for management.
111      * @param name The name of the MBean to analyze
112      * @return An instance of <CODE>MBeanInfo</CODE> allowing the retrieval of all attributes and operations of this MBean.
113      * @exception IntrospectionException An exception occurs during introspection.
114      * @exception InstanceNotFoundException The MBean specified is not found.
115      * @exception ReflectionException An exception occurred when trying to invoke the getMBeanInfo of a Dynamic MBean.
116      */

117     public MBeanInfo getMBeanInfo(ObjectName name) throws javax.management.InstanceNotFoundException JavaDoc,
118         javax.management.IntrospectionException JavaDoc, javax.management.ReflectionException JavaDoc,
119     java.io.IOException JavaDoc, RemoteException JavaDoc {
120         return this.mejbHelper.getMBeanInfo(name);
121     }
122
123     /**
124      * Gets the value of a specific attribute of a named MBean. The MBean is identified by its object name.
125      * @param name The object name of the MBean from which the attribute is to be retrieved.
126      * @param attribute A String specifying the name of the attribute to be retrieved.
127      * @return The value of the retrieved attribute.
128      * @exception AttributeNotFoundException The attribute specified is not accessible in the MBean.
129      * @exception MBeanException Wraps an exception thrown by the MBean's getter.
130      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
131      * @exception ReflectionException Wraps a <CODE>java.lang.Exception</CODE> thrown when trying to invoke the setter.
132      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The object name in
133      * parameter is null or the attribute in parameter is null.
134      */

135     public Object JavaDoc getAttribute(ObjectName name, String JavaDoc attribute) throws MBeanException,
136         javax.management.AttributeNotFoundException JavaDoc, javax.management.InstanceNotFoundException JavaDoc,
137         javax.management.ReflectionException JavaDoc, java.io.IOException JavaDoc, RemoteException JavaDoc {
138         return this.mejbHelper.getAttribute(name,attribute);
139     }
140
141     /**
142      * Enables the values of several attributes of a named MBean. The MBean is identified by its object name.
143      * @param name The object name of the MBean from which the attributes are retrieved.
144      * @param attributes A list of the attributes to be retrieved.
145      * @return The list of the retrieved attributes.
146      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
147      * @exception ReflectionException An exception occurred when trying to invoke the getAttributes method of a Dynamic MBean.
148      * @exception RuntimeOperationsException Wrap a <CODE>java.lang.IllegalArgumentException</CODE>: The object name in
149      * parameter is null or attributes in parameter is null.
150      */

151     public javax.management.AttributeList JavaDoc getAttributes(ObjectName name, String JavaDoc[] attributes)
152         throws javax.management.InstanceNotFoundException JavaDoc, javax.management.ReflectionException JavaDoc, java.io.IOException JavaDoc, RemoteException JavaDoc {
153         return this.mejbHelper.getAttributes(name,attributes);
154     }
155
156     /**
157      * Sets the value of a specific attribute of a named MBean. The MBean is identified by its object name.
158      * @param name The name of the MBean within which the attribute is to be set.
159      * @param attribute The identification of the attribute to be set and the value it is to be set to.
160      * @return The value of the attribute that has been set.
161      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
162      * @exception AttributeNotFoundException The attribute specified is not accessible in the MBean.
163      * @exception InvalidAttributeValueException The value specified for the attribute is not valid.
164      * @exception MBeanException Wraps an exception thrown by the MBean's setter.
165      * @exception ReflectionException Wraps a <CODE>java.lang.Exception</CODE> thrown when trying to invoke the setter.
166      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The object name in
167      * parameter is null or the attribute in parameter is null.
168      */

169     public void setAttribute(ObjectName name, javax.management.Attribute JavaDoc attribute)
170         throws javax.management.InstanceNotFoundException JavaDoc, javax.management.AttributeNotFoundException JavaDoc,
171         javax.management.InvalidAttributeValueException JavaDoc, MBeanException,
172         javax.management.ReflectionException JavaDoc, java.io.IOException JavaDoc, RemoteException JavaDoc {
173     this.mejbHelper.setAttribute(name,attribute);
174     }
175
176     /**
177      * Sets the values of several attributes of a named MBean. The MBean is identified by its object name.
178      * @param name The object name of the MBean within which the attributes are to be set.
179      * @param attributes A list of attributes: The identification of the
180      * attributes to be set and the values they are to be set to.
181      * @return The list of attributes that were set, with their new values.
182      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
183      * @exception ReflectionException An exception occurred when trying to invoke the getAttributes method of a Dynamic MBean.
184      * @exception RuntimeOperationsException Wraps a <CODE>java.lang.IllegalArgumentException</CODE>: The object name in
185      * parameter is null or attributes in parameter is null.
186      */

187     public javax.management.AttributeList JavaDoc setAttributes(ObjectName name, javax.management.AttributeList JavaDoc attributes)
188         throws javax.management.InstanceNotFoundException JavaDoc, javax.management.ReflectionException JavaDoc, java.io.IOException JavaDoc, RemoteException JavaDoc {
189         return this.mejbHelper.setAttributes(name,attributes);
190     }
191
192     /**
193      * Invokes an operation on an MBean.
194      * @param name The object name of the MBean on which the method is to be invoked.
195      * @param operationName The name of the operation to be invoked.
196      * @param params An array containing the parameters to be set when the operation is invoked
197      * @param signature An array containing the signature of the operation. The class objects will
198      * be loaded using the same class loader as the one used for loading the MBean on which the operation was invoked.
199      * @return The object returned by the operation, which represents the result ofinvoking the operation
200      * on the MBean specified.
201      * @exception InstanceNotFoundException The MBean specified is not registered in the MBean server.
202      * @exception MBeanException Wraps an exception thrown by the MBean's invoked method.
203      * @exception ReflectionException Wraps a <CODE>java.lang.Exception</CODE> thrown while trying to invoke the method.
204      */

205     public Object JavaDoc invoke(ObjectName name, String JavaDoc operationName, Object JavaDoc[] params, String JavaDoc[] signature)
206         throws javax.management.InstanceNotFoundException JavaDoc, MBeanException,
207         javax.management.ReflectionException JavaDoc, java.io.IOException JavaDoc, RemoteException JavaDoc {
208         return this.mejbHelper.invoke(name,operationName,params,signature);
209     }
210
211     /**
212      * Returns the default domain used for naming the managed object.
213      * The default domain name is used as the domain part in the ObjectName
214      * of managed objects if no domain is specified by the user.
215      */

216     public String JavaDoc getDefaultDomain() throws java.io.IOException JavaDoc, RemoteException JavaDoc {
217         return this.mejbHelper.getDefaultDomain();
218     }
219
220     /*
221      * returns the ListenerRegistry implementation for this MEJB
222      */

223
224     public ListenerRegistration getListenerRegistry() throws RemoteException JavaDoc {
225         return this.mejbHelper.getListenerRegistry();
226     }
227
228 }
229
Popular Tags