KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > lifecycle > AppServWSMonitorLifeCycleProvider


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 package com.sun.enterprise.admin.wsmgmt.lifecycle;
24
25 import java.util.Set JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.HashSet JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 import com.sun.enterprise.admin.monitor.WSMonitorLifeCycleProvider;
31 import com.sun.enterprise.admin.monitor.WSMonitorLifeCycleFactory;
32
33 import com.sun.enterprise.admin.wsmgmt.config.spi.WebServiceConfig;
34 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigFactory;
35 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigProvider;
36 import com.sun.enterprise.admin.wsmgmt.config.impl.WebServiceConfigImpl;
37 import com.sun.enterprise.admin.wsmgmt.config.impl.AppServConfigProvider;
38
39 import com.sun.enterprise.admin.wsmgmt.transform.TransformMgr;
40
41 import com.sun.enterprise.deployment.Application;
42 import com.sun.enterprise.deployment.BundleDescriptor;
43 import com.sun.enterprise.deployment.WebBundleDescriptor;
44 import com.sun.enterprise.deployment.EjbBundleDescriptor;
45 import com.sun.enterprise.deployment.WebService;
46 import com.sun.enterprise.config.serverbeans.WebServiceEndpoint;
47 import com.sun.enterprise.config.serverbeans.J2eeApplication;
48 import com.sun.enterprise.config.serverbeans.ServerHelper;
49 import com.sun.enterprise.config.serverbeans.Server;
50 import com.sun.enterprise.config.serverbeans.EjbModule;
51 import com.sun.enterprise.config.serverbeans.WebModule;
52 import com.sun.enterprise.config.serverbeans.ApplicationRef;
53 import com.sun.enterprise.config.ConfigBean;
54 import com.sun.enterprise.config.ConfigException;
55 import com.sun.enterprise.admin.wsmgmt.WebServiceMgrBackEnd;
56 import com.sun.enterprise.admin.monitor.registry.MonitoringLevel;
57 import com.sun.enterprise.admin.monitor.registry.MonitoringRegistrationException;
58 import com.sun.enterprise.server.ApplicationServer;
59 import com.sun.enterprise.server.ServerContext;
60 import com.sun.enterprise.instance.AppsManager;
61 import com.sun.enterprise.instance.InstanceEnvironment;
62
63 import java.util.logging.Logger JavaDoc;
64 import java.util.logging.Level JavaDoc;
65 import com.sun.logging.LogDomains;
66 import com.sun.enterprise.util.i18n.StringManager;
67
68 /**
69  * This is the mechanism to initialize web service management functionality.
70  * <br>
71  */

72 public class AppServWSMonitorLifeCycleProvider implements WSMonitorLifeCycleProvider {
73
74     public AppServWSMonitorLifeCycleProvider() {
75         try {
76             cfgProv = ConfigFactory.getConfigFactory().getConfigProvider();
77             InstanceEnvironment ienv =
78                 ApplicationServer.getServerContext().getInstanceEnvironment();
79             appsMgr = new AppsManager(ienv);
80         } catch (Exception JavaDoc e) {
81             _logger.fine(" Exception during initialization of AppServWSMonitorLifeCycleProvider " + e.getMessage());
82             // log exception in FINE level. This excpetion should never occur.
83
}
84     }
85
86     /**
87      * Returns the unique identifier for this RepositoryProvider object.
88      *
89      * @return fully qualified class name of this RepositoryProvider
90      */

91     public String JavaDoc getProviderID() {
92         return WSMonitorLifeCycleFactory.WSMGMT_DEFAULT_PROVIDER;
93     }
94
95     /**
96      * Registers the web service endpoints in this application
97      *
98      * @param app application object
99      */

100     void instrumentWebServiceEndpoints(String JavaDoc appId, BundleDescriptor bd,
101         boolean shouldRegister) {
102
103         boolean isEjb = false;
104         boolean isStandAlone = false;
105         String JavaDoc modName = null;
106         String JavaDoc ctxRoot = null;
107         String JavaDoc vs = WebServiceMgrBackEnd.DEFAULT_VIRTUAL_SERVER;
108         Server server = null;
109         try {
110             ServerContext sCtx = ApplicationServer.getServerContext();
111             server = ServerHelper.getServerByName(sCtx.getConfigContext(),
112                                                   sCtx.getInstanceName());
113             ApplicationRef aRef = server.getApplicationRefByRef(appId);
114             if (aRef != null) {
115                 vs = aRef.getVirtualServers();
116                 if ((vs == null) || ( vs.length() == 0)) {
117                     vs = WebServiceMgrBackEnd.DEFAULT_VIRTUAL_SERVER;
118                 }
119             } else {
120                     throw new IllegalArgumentException JavaDoc();
121             }
122         } catch( Exception JavaDoc e) {
123             throw new RuntimeException JavaDoc(e);
124         }
125         
126         modName = bd.getModuleDescriptor().getArchiveUri();
127
128         if ( bd instanceof EjbBundleDescriptor ) {
129             isEjb = true;
130         } else if ( bd instanceof WebBundleDescriptor ) {
131             isEjb = false;
132             ctxRoot = ((WebBundleDescriptor) bd).getContextRoot();
133         } else {
134             return;
135         }
136         
137         Application app = bd.getApplication();
138         if ( app == null) {
139             String JavaDoc msg = _stringMgr.getString("Application_NotFound", appId);
140             throw new RuntimeException JavaDoc(msg);
141         }
142         isStandAlone = app.isVirtual();
143
144         Collection JavaDoc wsCollec = bd.getWebServices().getWebServices();
145         Set JavaDoc wsSet = new HashSet JavaDoc();
146         for (Iterator JavaDoc i1 = wsCollec.iterator(); i1.hasNext();) {
147             WebService ws = (WebService) i1.next();
148             wsSet.addAll(ws.getEndpoints());
149         }
150         for (Iterator JavaDoc i2 = wsSet.iterator(); i2.hasNext();) {
151             com.sun.enterprise.deployment.WebServiceEndpoint wse =
152             (com.sun.enterprise.deployment.WebServiceEndpoint) i2.next();
153             String JavaDoc epName = wse.getEndpointName();
154                 if ( shouldRegister == true ) {
155                     instrument( epName, modName, ctxRoot, isStandAlone, appId,
156                             isEjb, vs);
157                 } else {
158                     uninstrument( epName, modName, ctxRoot, isStandAlone, appId,
159                               isEjb, vs);
160                 }
161         }
162     }
163
164     /**
165      * un registers the web service endpoints in this application
166      *
167      * @param app application object
168      */

169      public void unregisterWebServiceEndpoints(String JavaDoc appId,
170          BundleDescriptor bd) {
171         instrumentWebServiceEndpoints(appId, bd, false);
172      }
173
174     /**
175      * registers the web service endpoints in this application
176      *
177      * @param app application object
178      */

179      public void registerWebServiceEndpoints(String JavaDoc appId,BundleDescriptor bd) {
180         instrumentWebServiceEndpoints(appId, bd, true);
181      }
182
183     /**
184      * Returns the list of Web Service Endpoint config in this application
185      *
186      * @param appName Name of the application
187      *
188      * @return the array of WebServiceConfig
189      */

190      void instrument(String JavaDoc endpoint, String JavaDoc modName, String JavaDoc ctxRoot,
191         boolean isStandAlone, String JavaDoc appId, boolean isEjbModule, String JavaDoc vs) {
192
193             WebServiceConfigImpl wsConfig = (WebServiceConfigImpl) cfgProv.
194                 getWebServiceConfig( appId, modName, isStandAlone, endpoint) ;
195
196             if (wsConfig == null) {
197                 return;
198             }
199             if (isStandAlone) {
200                 modName = appId;
201                 appId = null;
202             }
203
204             TransformMgr.getInstance().init(appId, wsConfig);
205
206              try {
207                  new MonitoringLifeCycleImpl().initializeMonitoring(appId,
208                  modName, ctxRoot, isStandAlone, isEjbModule, vs, wsConfig);
209             } catch ( Exception JavaDoc e) {
210                 // log a warning
211
_logger.fine("Exception during monitoring initialization " +
212                 e.getMessage());
213             }
214         }
215
216     /**
217      * Returns the list of Web Service Endpoint config in this application
218      *
219      * @param appName Name of the application
220      *
221      * @return the array of WebServiceConfig
222      */

223      void uninstrument(String JavaDoc endpoint, String JavaDoc modName, String JavaDoc ctxRoot,
224         boolean isStandAlone,
225         String JavaDoc appId, boolean isEjbModule, String JavaDoc vs) {
226
227             WebServiceConfigImpl wsConfig = (WebServiceConfigImpl) cfgProv.
228                 getWebServiceConfig(appId, modName, isStandAlone, endpoint) ;
229
230             if (wsConfig == null) {
231                 return;
232             }
233             if (isStandAlone) {
234                 modName = appId;
235                 appId = null;
236             }
237
238             TransformMgr.getInstance().stop(appId, wsConfig);
239
240             try {
241                  new MonitoringLifeCycleImpl().uninitializeMonitoring(appId,
242                  modName, ctxRoot, isStandAlone, isEjbModule, vs, wsConfig);
243             } catch ( Exception JavaDoc e) {
244                 // log a warning
245
_logger.fine("Exception during monitoring shutdown " +
246                 e.getMessage());
247             }
248         }
249
250     public void reconfigureMonitoring(WebServiceEndpoint ep, String JavaDoc appId,
251     MonitoringLevel oldLevel, MonitoringLevel newLevel) throws MonitoringRegistrationException {
252     
253         if ( ep == null) {
254             return;
255         }
256
257         boolean isEjb = false;
258         boolean isStandAlone = false;
259         String JavaDoc modName = null;
260         String JavaDoc ctxRoot = null;
261         String JavaDoc appName = null;
262         String JavaDoc epName = null;
263         String JavaDoc vs = WebServiceMgrBackEnd.DEFAULT_VIRTUAL_SERVER;
264
265         ConfigBean parent = (ConfigBean) ep.parent();
266         if (parent instanceof J2eeApplication) {
267             isStandAlone = false;
268             appName = appId;
269             modName =
270             WebServiceMgrBackEnd.getManager().getModuleName(ep.getName());
271             // set isEjb to true in case of ejb embedded module
272
if (modName.endsWith("jar")) {
273                 isEjb = true;
274             } else {
275                 if (appsMgr != null) {
276                     Application app = null;
277                     try {
278                         app = appsMgr.getDescriptor(appId);
279                     } catch (ConfigException ce) {
280                         // log a warning
281
}
282                     if (app != null) {
283                         WebBundleDescriptor wbd
284                             = app.getWebBundleDescriptorByUri(modName);
285                         if (wbd != null) {
286                             ctxRoot = wbd.getContextRoot();
287                         }
288                     }
289                 }
290             }
291         } else if (parent instanceof WebModule) {
292             isStandAlone = true;
293             appName = null;
294             modName = appId;
295             ctxRoot = ((WebModule) parent).getContextRoot();
296         } else if (parent instanceof EjbModule) {
297             isStandAlone = true;
298             isEjb = true;
299             appName = null;
300             modName = appId;
301         }
302         epName= WebServiceMgrBackEnd.getManager().getEndpointName(ep.getName());
303         
304         new MonitoringLifeCycleImpl().instrumentMonitoring(epName,
305                 modName, ctxRoot, isStandAlone, vs, appName,
306                 oldLevel, newLevel, isEjb);
307
308     }
309
310
311     // PRIVATE VARS
312
private AppsManager appsMgr = null;
313     private ConfigProvider cfgProv = null;
314     private static final StringManager _stringMgr =
315         StringManager.getManager(AppServWSMonitorLifeCycleProvider.class);
316     private static final Logger JavaDoc _logger =
317         Logger.getLogger(LogDomains.ADMIN_LOGGER);
318
319
320 }
321
Popular Tags