KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > model > J2EEManagedObjectMdl


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.model;
25
26 import javax.management.*;
27 import java.util.Set JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import javax.management.j2ee.Management JavaDoc;
30 import javax.management.j2ee.ManagementHome JavaDoc;
31 //import javax.rmi.PortableRemoteObject;
32
import javax.naming.*;
33 import java.security.AccessController JavaDoc;
34 import java.security.PrivilegedAction JavaDoc;
35
36 import com.sun.enterprise.management.agent.MBSUtility;
37
38 /**
39  * The base class for all Managed Objects
40  *
41  * @author Hans Hrasna
42  */

43 public abstract class J2EEManagedObjectMdl {
44     // name - key attribute for the managed object
45
private String JavaDoc name;
46     private boolean stateManageable;
47     private boolean statisticsProvider;
48     private boolean eventProvider;
49
50     J2EEManagedObjectMdl(String JavaDoc name,boolean state, boolean statistics, boolean events) {
51         this.name = name;
52         stateManageable = state;
53         statisticsProvider = statistics;
54         eventProvider = events;
55     }
56
57     // returns the MBeanServer local to this VM
58
// creates one if it doesn't exsist yet
59
MBeanServer getMBeanServer() {
60         java.util.ArrayList JavaDoc servers =
61                 (java.util.ArrayList JavaDoc) AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
62                     public java.lang.Object JavaDoc run() {
63                         return MBeanServerFactory.findMBeanServer(null);
64                     }
65                 });
66         if (servers.isEmpty()) {
67             return (MBeanServer) AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
68                     public java.lang.Object JavaDoc run() {
69                         return MBeanServerFactory.createMBeanServer();
70                     }
71                 });
72         } else {
73             return (MBeanServer)servers.get(0);
74         }
75     }
76
77     MBSUtility getMBSUtility(){
78         //FIXME
79
//return com.sun.enterprise.Switch.getSwitch().getManagementObjectManager().getMEJBUtility();
80
return MBSUtility.getMBSUtility();
81     }
82     /* TBD FIXME
83     Management getMEJB() {
84         Management mejb=null;
85         try {
86             Context ic = new InitialContext();
87             String ejbName = System.getProperty("mejb.name","ejb/mgmt/MEJB");
88             java.lang.Object objref = ic.lookup(ejbName);
89             ManagementHome home = (ManagementHome)PortableRemoteObject.narrow(objref, ManagementHome.class);
90             mejb = home.create();
91         } catch (Exception ex) {
92             ex.printStackTrace();
93         }
94         return mejb;
95     }
96
97      */

98     
99     public Set JavaDoc findNames(String JavaDoc keys) {
100         Set JavaDoc s = new HashSet JavaDoc();
101         ObjectName namepattern = null;
102         try {
103             String JavaDoc pattern = J2EEDomainMdl.DOMAINNAME + ":" + keys + ",*";
104             namepattern = new ObjectName(pattern);
105         } catch (Exception JavaDoc e) {
106             e.printStackTrace();
107         }
108         if (namepattern != null) {
109             MBSUtility mejb = getMBSUtility();
110             if (mejb != null) {
111                 try {
112                     s = getMBSUtility().queryNames(namepattern, null);
113                 } catch (Exception JavaDoc e) {
114                     e.printStackTrace();
115                 }
116             }
117         }
118         return s;
119     }
120
121
122     /**
123      * The type of the J2EEManagedObject as specified by JSR77. The class that implements a specific type must override this
124      * method and return the appropriate type string.
125      */

126     public abstract String JavaDoc getj2eeType();
127
128     /**
129      * The name of the J2EEManagedObject. All managed objects must have a unique name within the context of the management
130      * domain. The name must not be null.
131      */

132     public abstract String JavaDoc getobjectName();
133
134     /**
135      * If true, indicates that this managed object implements the StateManageable interface and is state manageable. If false,
136      * the managed object does not support state management.
137      */

138     public boolean isstateManageable() {
139         return stateManageable;
140     }
141
142     /**
143      * If true, indicates that the managed object supports performance statistics and therefore implements the
144      * StatisticsProvider model. If false, the J2EEManagedObject does not support performance statistics
145      */

146     public boolean isstatisticsProvider() {
147         return statisticsProvider;
148     }
149
150     /**
151      * If true, indicates that the managed object provides event notification about events that occur on that object. All
152      * managed objects that support state management are by default event providers. If the stateManageable attribute for this
153      * managed object is true then the eventProvider attribute must also be true.
154      */

155     public boolean iseventProvider() {
156         return eventProvider;
157     }
158
159     /** Accessor method for the parent key */
160     public String JavaDoc getJ2EEServer() {
161         return "j2ee100";
162         
163         //TBD
164
//return (System.getProperty(com.sun.enterprise.server.J2EEServer.J2EE_APPNAME, "j2ee") +
165
// System.getProperty(com.sun.enterprise.server.J2EEServer.J2EE_SERVER_ID_PROP, "100"));
166
}
167     /** Accessor method for the parent key */
168     public String JavaDoc getname(){
169         return this.name;
170     }
171 }
172
Popular Tags