KickJava   Java API By Example, From Geeks To Geeks.

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


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.ObjectName JavaDoc;
27 import java.util.Set JavaDoc;
28 import java.util.Map JavaDoc;
29 import java.io.Serializable JavaDoc;
30 import com.sun.enterprise.admin.wsmgmt.msg.MessageTraceMgr;
31 import com.sun.appserv.management.ext.wsmgmt.MessageTrace;
32 import com.sun.appserv.management.util.misc.TypeCast;
33 import com.sun.enterprise.admin.wsmgmt.stats.spi.StatsProviderManager;
34 import com.sun.enterprise.admin.wsmgmt.stats.spi.WebServiceEndpointStatsProvider;
35
36 /**
37  * WebServiceEndpoint rutime MBean. This MBean acts as base class for
38  * ServletWebServiceEndpoint and EJBWebServiceEndpoint.
39  * Please use either ServletWebServiceEndpoint or EJBWebServiceEndpoint, inorder
40  * to instantiate runtime mbean of type WebServiceEndpoint.
41  */

42 public abstract class WebServiceEndpointMdl extends J2EEManagedObjectMdl {
43     
44     private static String JavaDoc MANAGED_OBJECT_TYPE = "WebServiceEndpoint";
45     protected static String JavaDoc WEB_MBEAN = "ServletWebServiceEndpoint";
46     protected static String JavaDoc EJB_MBEAN = "EJBWebServiceEndpoint";
47
48     private String JavaDoc moduleName = null;
49     private String JavaDoc registrationName = null;
50     private String JavaDoc applicationName = null;
51     private String JavaDoc epName = null;
52     private boolean isEjb = false;
53     private boolean isStandAlone = false;
54     private String JavaDoc mbeanName = null;
55     
56     /**
57      * constructor.
58      *
59      * @param name Name of the web service endpoint
60      * @param moduleName Name of the module (which this web service belongs)
61      * @param regName registration name of the application or module
62      * @param isVirtual true, if the module is stand alone, false otherwise
63      * @param isEjb If this Web service endpoint is implemented as EJB
64      * or Servlet
65      */

66     WebServiceEndpointMdl(String JavaDoc name, String JavaDoc mName, String JavaDoc regName,
67     boolean isVirtual, boolean isejb) {
68         super(name,false, false, false);
69         this.moduleName = mName;
70         this.applicationName = regName;
71         this.registrationName = regName;
72         this.isStandAlone = isVirtual;
73         this.epName = name;
74         this.isEjb = isejb;
75         if (isejb == true) {
76             mbeanName = EJB_MBEAN;
77         } else {
78             mbeanName = WEB_MBEAN;
79         }
80     }
81
82     /**
83      * constructor.
84      *
85      * @param name Name of the web service endpoint
86      * @param moduleName Name of the module (which this web service belongs)
87      * @param regName registration name of the application or module
88      * @param serverName Name of the server instance
89      * @param isVirtual true, if the module is stand alone, false otherwise
90      * @param isEjb If this Web service endpoint is implemented as EJB
91      * or Servlet
92      */

93     WebServiceEndpointMdl(String JavaDoc name, String JavaDoc moduleName,
94             String JavaDoc regName, String JavaDoc serverName, boolean isVirtual,
95             boolean isejb) {
96
97         super(name, serverName, false, false, false);
98         this.moduleName = moduleName;
99         this.applicationName = regName;
100         this.registrationName = regName;
101         this.epName = name;
102         this.isEjb = isejb;
103         if (isejb == true) {
104             mbeanName = EJB_MBEAN;
105         } else {
106             mbeanName = WEB_MBEAN;
107         }
108         this.isStandAlone = isVirtual;
109     }
110
111     /**
112      * Accessor method for the module name key
113      *
114      * @return String Module's name
115      */

116     public String JavaDoc getModule(){
117        return this.moduleName;
118     }
119
120     /**
121      * Accessor method for the J2EE Application key
122      *
123      * @return String Application's name
124      */

125     public String JavaDoc getJ2EEApplication(){
126        return this.applicationName;
127     }
128     
129     /**
130      * This returns the underlying implementation Servlet or EJB' type
131      * It could be J2EETypes.SERVLET or J2EETypes.EJB.
132      *
133      * @return String "EJB" or "SERVLET"
134      */

135     public String JavaDoc getImplementationType() {
136         if (isEjb) {
137             return "EJB";
138         } else {
139             return "SERVLET";
140         }
141     }
142
143     /**
144      * Returns last N message content and info collected for this web service.
145      *
146      * @return MessageTrace[] collection message content/trace information
147      */

148     public Map JavaDoc<String JavaDoc,Serializable JavaDoc>[] getMessagesInHistory() {
149         String JavaDoc partialEpName = null;
150
151         if (isStandAlone) {
152             // standalone module
153
partialEpName = this.epName;
154         } else {
155             partialEpName = this.moduleName+ "#" + this.epName;
156         }
157
158         Map JavaDoc<String JavaDoc,Serializable JavaDoc>[] maps = null;
159         MessageTrace[] result =
160             MessageTraceMgr.getInstance().getMessages(this.registrationName,
161                  partialEpName);
162         if ( result == null) {
163             return null;
164         }
165         if ( result.length > 0 ) {
166             maps = new Map JavaDoc[result.length];
167             for ( int idx =0; idx < result.length; idx++) {
168                 maps[idx] = result[idx].asMap();
169                 TypeCast.checkSerializable( maps[ idx] );
170             }
171         }
172         return maps;
173         
174     }
175
176     /**
177      * The name of the J2EEManagedObject. All managed objects must have a unique
178      * name within the context of the management
179      * domain. The name must not be null.
180      *
181      * @return String Object name of this J2EEManagedObject
182      */

183     public String JavaDoc getobjectName() {
184         Set JavaDoc s = null;
185         
186         if ( isEjb ) {
187             s = findNames("j2eeType="+getj2eeType()+",name="+this.epName+
188             ",EJBModule="+this.getModule()+",J2EEApplication="+
189             this.getJ2EEApplication()+",J2EEServer="+this.getJ2EEServer());
190         } else {
191             s = findNames("j2eeType="+getj2eeType()+",name="+this.epName+
192             ",WebModule="+this.getModule()+",J2EEApplication="+
193             this.getJ2EEApplication()+",J2EEServer="+this.getJ2EEServer());
194         }
195         Object JavaDoc [] objs = s.toArray();
196         if (objs.length > 0) {
197             String JavaDoc name = ((ObjectName JavaDoc)objs[0]).toString();
198             return name;
199         } else {
200             return null;
201         }
202     }
203
204     /**
205      * The type of the J2EEManagedObject as specified by JSR77. The class that
206      * implements a specific type must override this method and return the
207      * appropriate type string.
208      *
209      * @return String J2eeType of this Managed Object
210      */

211     public String JavaDoc getj2eeType() {
212         return MANAGED_OBJECT_TYPE;
213     }
214
215     /**
216      * The MBean name of the J2EEManagedObject as specified in
217      * runtime-mbeans-descriptors.xml. This value is used in registering the
218      * MBean.
219      *
220      * @return String MBeanName value of this Managed Object
221      */

222     public abstract String JavaDoc getMBeanName();
223
224     /**
225      * Returns the stats provider for this web service endpoint.
226      */

227     private WebServiceEndpointStatsProvider getWSProvider() {
228         final String JavaDoc NS = "#";
229         StatsProviderManager spMgr = StatsProviderManager.getInstance();
230
231         String JavaDoc fqName = null;
232         if (isStandAlone == false) {
233             fqName = registrationName + NS + moduleName + NS + epName;
234         } else {
235             fqName = registrationName + NS + epName;
236         }
237         WebServiceEndpointStatsProvider provider =
238                 spMgr.getEndpointStatsProvider(fqName);
239
240         return provider;
241     }
242
243     /**
244      * Resets the statistics.
245      */

246     public void resetStats() {
247         WebServiceEndpointStatsProvider provider = getWSProvider();
248         if (provider != null) {
249             provider.reset();
250         }
251     }
252
253     /**
254      * Returns the last reset time stamp in milliseconds.
255      *
256      * @return last reset time stamp in milliseconds
257      */

258     public long getLastResetTime() {
259         long resetTime = 0;
260         WebServiceEndpointStatsProvider provider = getWSProvider();
261         if (provider != null) {
262             resetTime = provider.getLastResetTime();
263         }
264
265         return resetTime;
266     }
267 }
268
Popular Tags