KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > monitor > MonitoringImplBase


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.monitor;
25
26 import javax.management.ObjectName JavaDoc;
27 import javax.management.MBeanServer JavaDoc;
28
29 import com.sun.appserv.management.base.AMX;
30 import com.sun.appserv.management.base.XTypes;
31 import com.sun.appserv.management.base.Util;
32 import com.sun.appserv.management.monitor.ServerRootMonitor;
33 import com.sun.appserv.management.monitor.MonitoringRoot;
34
35 import com.sun.enterprise.management.support.AMXImplBase;
36 import com.sun.enterprise.management.support.Delegate;
37
38 import com.sun.appserv.management.util.misc.StringUtil;
39 import com.sun.appserv.management.util.jmx.JMXUtil;
40
41 /**
42     Base implementation class for Monitoring MBeans of all stripes; both
43     those that have Stats and those that do not.
44 */

45 public class MonitoringImplBase extends AMXImplBase
46 {
47         public
48     MonitoringImplBase( final String JavaDoc j2eeType, final Delegate delegate )
49     {
50         super( j2eeType, delegate );
51     }
52
53         public
54     MonitoringImplBase( final String JavaDoc j2eeType )
55     {
56         this( j2eeType, null );
57     }
58
59         public String JavaDoc
60     getGroup()
61     {
62         return( AMX.GROUP_MONITORING );
63     }
64
65         public ObjectName JavaDoc
66     getServerRootMonitorObjectName()
67     {
68         ObjectName JavaDoc objectName = null;
69         
70         final String JavaDoc name = getObjectName().getKeyProperty( XTypes.SERVER_ROOT_MONITOR );
71         if ( name != null )
72         {
73             final MonitoringRoot root = getDomainRoot().getMonitoringRoot();
74             final ServerRootMonitor mon =
75                 (ServerRootMonitor)root.getServerRootMonitorMap().get( name );
76         
77             objectName = Util.getObjectName( mon );
78         }
79         
80         return( objectName );
81     }
82     
83     /**
84         For whatever reason the com.sun.appserv MBeans use:
85         <key>=foo.jar,categor=runtime (JSR 77)
86         <key>=foo_jar,category=monitor (monitoring)
87         
88         We want both to be named "foo.jar" for two reasons:
89         (1) for consistency, (2) so that the JSR 77 MBeans can find
90         their corresponding monitors by name.
91         
92      */

93         protected final String JavaDoc
94     fixEJBModuleName( final String JavaDoc moduleName )
95     {
96         final String JavaDoc JAR = "jar";
97         
98         String JavaDoc result = moduleName;
99         
100         if ( moduleName.endsWith( "_" + JAR ) )
101         {
102             result = StringUtil.stripSuffix( moduleName, "_" + JAR ) + "." +JAR;
103         }
104         
105         return( result );
106     }
107     
108         protected final ObjectName JavaDoc
109     fixEJBModuleName(
110         final ObjectName JavaDoc objectNameIn,
111         final String JavaDoc key )
112     {
113         ObjectName JavaDoc objectNameOut = objectNameIn;
114         
115         final String JavaDoc origName = objectNameIn.getKeyProperty( key );
116         if ( origName != null )
117         {
118             final String JavaDoc fixedName = fixEJBModuleName( origName );
119             
120             if ( ! fixedName.equals( origName ) )
121             {
122                 objectNameOut = JMXUtil.setKeyProperty( objectNameIn, key, fixedName);
123             }
124         }
125         
126         if ( ! objectNameOut.equals( objectNameIn ) )
127         {
128             logFiner( "MonitoringImplBase.fixEJBModuleName: modified " +
129                 quote( objectNameIn ) + " => " + quote( objectNameOut ) );
130         }
131         return( objectNameOut );
132     }
133     
134     /**
135         See {@link #fixEJBModuleName} for info on why this is being done.
136      */

137         protected ObjectName JavaDoc
138     preRegisterModifyName(
139         final MBeanServer JavaDoc server,
140         final ObjectName JavaDoc nameIn )
141     {
142         ObjectName JavaDoc objectNameOut = super.preRegisterModifyName( server, nameIn );
143         
144         if ( nameIn.getKeyProperty( XTypes.EJB_MODULE_MONITOR ) != null )
145         {
146             objectNameOut = fixEJBModuleName( objectNameOut, XTypes.EJB_MODULE_MONITOR );
147         }
148         
149         return objectNameOut;
150     }
151 }
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
Popular Tags