KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > j2ee > ServletImpl


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.management.j2ee;
24  
25 import java.util.Map JavaDoc;
26 import java.util.Set JavaDoc;
27
28 import javax.management.ObjectName JavaDoc;
29 import javax.management.j2ee.statistics.ServletStats JavaDoc;
30
31
32 import com.sun.appserv.management.j2ee.Servlet;
33 import com.sun.appserv.management.j2ee.WebModule;
34 import com.sun.appserv.management.j2ee.J2EETypes;
35
36 import com.sun.appserv.management.base.XTypes;
37 import com.sun.appserv.management.base.Util;
38
39
40 import com.sun.appserv.management.util.misc.MapUtil;
41 import com.sun.appserv.management.util.misc.ExceptionUtil;
42 import com.sun.appserv.management.util.misc.GSetUtil;
43 import com.sun.appserv.management.util.misc.StringUtil;
44 import com.sun.appserv.management.util.misc.CollectionUtil;
45
46 import com.sun.enterprise.management.support.Delegate;
47
48 import com.sun.appserv.management.monitor.statistics.AltServletStats;
49
50 import com.sun.appserv.management.monitor.WebModuleVirtualServerMonitor;
51 import com.sun.appserv.management.monitor.ServletMonitor;
52
53 import com.sun.enterprise.management.support.WebModuleSupport;
54
55 /**
56  */

57 public final class ServletImpl
58     extends J2EEManagedObjectImplBase
59     // implements Servlet
60
{
61         public
62     ServletImpl( final Delegate delegate )
63     {
64         super( delegate );
65     }
66     
67     
68     static private final Set JavaDoc<String JavaDoc> IGNORE_MISSING =
69         GSetUtil.newUnmodifiableStringSet(
70             "maxTimeMillis", "minTimeMillis", "processingTimeMillis",
71             "requestCount", "errorCount"
72         );
73         
74     /**
75         We don't map any of the Attributes derived from statistics.
76      */

77         protected void
78     handleMissingOriginals( final Set JavaDoc<String JavaDoc> missingOriginals )
79     {
80         missingOriginals.removeAll( IGNORE_MISSING );
81         
82         super.handleMissingOriginals( missingOriginals );
83     }
84     
85     
86     
87         protected String JavaDoc
88     getMonitoringPeerJ2EEType()
89     {
90         return( XTypes.SERVLET_MONITOR );
91     }
92     
93         protected ObjectName JavaDoc
94     queryMonitoringPeerFailed( final Map JavaDoc<String JavaDoc,String JavaDoc> propsMap )
95     {
96         final WebModule webModule = (WebModule)getContainer();
97         
98         debug( "queryMonitoringPeerFailed: expecting to find " +
99             MapUtil.toString( propsMap ) );
100             
101         if ( webModule == null )
102         {
103             logWarning(
104                 "ServletImpl.queryMonitoringPeerFailed: " +
105                 "Can't get containing WebModule, my ObjectName = " + getObjectName());
106         }
107         
108         ObjectName JavaDoc result = null;
109         
110         try
111         {
112             final WebModuleVirtualServerMonitor webModuleVirtualServerMonitor =
113                 (WebModuleVirtualServerMonitor)webModule.getMonitoringPeer();
114             if ( webModuleVirtualServerMonitor == null )
115             {
116                 final ObjectName JavaDoc objectName = Util.getObjectName( webModule );
117                 
118                 final String JavaDoc msg = "ServletImpl.queryMonitoringPeerFailed: " +
119                     "Can't get WebModuleVirtualServerMonitor for " +
120                         quote( toString( objectName ));
121                 debug( msg );
122                 logFine( msg );
123             }
124             else
125             {
126                 final Map JavaDoc<String JavaDoc,ServletMonitor> servletMap =
127                     webModuleVirtualServerMonitor.getServletMonitorMap();
128                 
129                 final ServletMonitor sm = servletMap.get( getName() );
130                 if ( sm != null )
131                 {
132                     result = Util.getObjectName( sm );
133                 }
134                 else
135                 {
136                     final String JavaDoc servletMonitorNames = CollectionUtil.toString(
137                         Util.toObjectNames( servletMap ).values(), StringUtil.NEWLINE() );
138                     
139                     logWarning(
140                         "ServletImpl.queryMonitoringPeerFailed: " +
141                         "Can't find ServletMonitor, my ObjectName = " +
142                             quote( toString( getObjectName() ) ) +
143                             ", WebModuleVirtualServerMonitor " +
144                             quote( toString( Util.getObjectName(webModuleVirtualServerMonitor) )) +
145                             " ServletMonitor names:" + StringUtil.NEWLINE() + servletMonitorNames );
146                 }
147             }
148         }
149         catch( Exception JavaDoc e )
150         {
151             logWarning( "ServletImpl.queryMonitoringPeerFailed: " + e);
152             debug( "ServletImpl.queryMonitoringPeerFailed: " + e + "\n" +
153                 ExceptionUtil.getStackTrace( e ) );
154         }
155         
156         return result;
157     }
158 }
159
160
161
162
163
164
Popular Tags