KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > web > MonitorUtil


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 /*
25  * MonitorUtil.java
26  *
27  * Created on May 7, 2004, 2:09 PM
28  */

29
30 package com.sun.enterprise.web;
31
32 import java.util.logging.*;
33 import com.sun.logging.*;
34 import org.apache.catalina.Context;
35 import org.apache.catalina.Container;
36 import org.apache.catalina.Engine;
37 import com.sun.enterprise.server.ServerContext;
38 import com.sun.enterprise.admin.monitor.stats.WebModuleStats;
39 import com.sun.enterprise.admin.monitor.registry.MonitoringRegistry;
40
41 /**
42  *
43  * @author lwhite
44  */

45 public class MonitorUtil {
46     
47     private static Logger _logger;
48
49     static {
50         _logger = LogDomains.getLogger(LogDomains.WEB_LOGGER);
51     }
52     
53     /**
54      * Resets the stats of all web modules.
55      */

56     public static void resetMonitorStats(EmbeddedWebContainer embedded,
57                                          ServerContext serverContext) {
58
59         MonitoringRegistry monitoringRegistry =
60             serverContext.getMonitoringRegistry();
61
62         Engine[] engines = embedded.getEngines();
63         for(int h=0; h<engines.length; h++) {
64             Container engine = (Container) engines[h];
65             Container[] hosts = engine.findChildren();
66             for(int i=0; i<hosts.length; i++) {
67                 Container nextHost = hosts[i];
68                 Container [] webModules = nextHost.findChildren();
69                 for (int j=0; j<webModules.length; j++) {
70                     WebModule webModule = (WebModule) webModules[j];
71                     if (!webModule.hasWebXml()) {
72                         // Dummy root context
73
continue;
74                     }
75                     /*
76                      * Standalone webmodules are loaded with the application
77                      * name set to the string "null"
78                      */

79                     String JavaDoc j2eeApp = webModule.getJ2EEApplication();
80                     if ("null".equalsIgnoreCase(j2eeApp)) {
81                         j2eeApp = null;
82                     }
83                     WebModuleStats stats =
84                         monitoringRegistry.getWebModuleStats(
85                             j2eeApp,
86                             webModule.getModuleName(),
87                             webModule.getPath(),
88                             nextHost.getName());
89                     if (stats != null) {
90                         try {
91                             stats.reset();
92                         } catch (Throwable JavaDoc th) {
93                             _logger.log(Level.SEVERE,
94                                         "Error resetting WebModuleStats", th);
95                         }
96                     }
97                 }
98             }
99         }
100     }
101     
102 }
103
Popular Tags