KickJava   Java API By Example, From Geeks To Geeks.

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


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  * DebugMonitor.java
26  *
27  * Created on January 14, 2003, 1:10 PM
28  */

29
30 package com.sun.enterprise.web;
31
32 import java.util.logging.*;
33 import com.sun.logging.*;
34 import java.util.Hashtable JavaDoc;
35 import java.util.Enumeration JavaDoc;
36 import org.apache.catalina.Context;
37 import org.apache.catalina.Container;
38 import org.apache.catalina.Engine;
39 import org.apache.catalina.Manager;
40 //FIXME remove after testing
41
//import com.sun.appserv.ee.web.sessmgmt.HAManagerBase;
42
import org.apache.catalina.session.PersistentManagerBase;
43 import org.apache.catalina.session.StandardManager;
44
45 /**
46  *
47  * @author Administrator
48  */

49 public class DebugMonitor extends java.util.TimerTask JavaDoc {
50     
51     private Hashtable JavaDoc _instances = null;
52     private EmbeddedWebContainer _embedded = null;
53     private static Logger _logger;
54     private WebContainer webContainer = null;
55     static
56     {
57             _logger=LogDomains.getLogger(LogDomains.WEB_LOGGER);
58     }
59     
60     /** Creates a new instance of DebugMonitor */
61     public DebugMonitor() {
62     }
63     
64     /** Creates a new instance of DebugMonitor */
65     public DebugMonitor(EmbeddedWebContainer embedded) {
66         _embedded = embedded;
67     }
68     
69     public String JavaDoc getApplicationId(Context ctx) {
70         com.sun.enterprise.web.WebModule wm =
71             (com.sun.enterprise.web.WebModule)ctx;
72         return wm.getID();
73     }
74     
75     public String JavaDoc getApplicationName(Context ctx) {
76         return ctx.getName();
77     }
78     
79     public void run() {
80         try {
81             Engine[] engines = _embedded.getEngines();
82             
83             for(int h=0; h<engines.length; h++) {
84                 Container engine = (Container) engines[h];
85                 Container[] hosts = engine.findChildren();
86                 for(int i=0; i<hosts.length; i++) {
87                     Container nextHost = hosts[i];
88                     Container [] webModules = nextHost.findChildren();
89                     for (int j=0; j<webModules.length; j++) {
90                         Container nextWebModule = webModules[j];
91                         Context ctx = (Context)nextWebModule;
92                         //this code gets managers
93
String JavaDoc webAppName = this.getApplicationName(ctx);
94                         Manager nextManager = nextWebModule.getManager();
95                         _logger.finest("webAppName = " + webAppName);
96                         
97                         if(nextManager instanceof StandardManager) {
98                         } else {
99                             _logger.log(Level.SEVERE, "MONITORING::" + webAppName + ": " +
100                                        ((PersistentManagerBase)nextManager).getMonitorAttributeValues() );
101                         }
102                         
103                     }
104                 }
105             }
106         } catch (Throwable JavaDoc th) {
107             _logger.log(Level.SEVERE, "Exception thrown", th);
108         }
109                 
110     }
111
112 }
113
Popular Tags