KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > monitor > stats > CustomMonitoringStatsImplBase


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.stats;
25
26 import com.sun.enterprise.management.monitor.*;
27 import javax.management.InstanceNotFoundException JavaDoc;
28 import javax.management.j2ee.statistics.Statistic JavaDoc;
29 import com.sun.appserv.management.j2ee.statistics.MapStatistic;
30 import com.sun.appserv.management.j2ee.statistics.MapStatisticImpl;
31 import com.sun.appserv.management.j2ee.statistics.StatisticImpl;
32 import com.sun.appserv.management.j2ee.statistics.StatisticFactory;
33 import com.sun.appserv.management.util.misc.ExceptionUtil;
34
35 /**
36     Base implementation class for LB Monitoring MBeans that provide Stats.
37 */

38 public abstract class CustomMonitoringStatsImplBase extends MonitoringStatsImplBase {
39
40     public CustomMonitoringStatsImplBase(String JavaDoc j2eeType) {
41         super(j2eeType);
42     }
43     
44     /**
45         Get all Statistics from the delegate (our only available call API).
46         Statistic names are translated appropriately.
47     */

48     protected Statistic JavaDoc[] getStatisticsFromImpl(CustomStatsImpl customStatsImpl) {
49         try {
50             final Statistic JavaDoc[] statistics = getStatisticsFromImplRaw(customStatsImpl);
51             // translate the names to be the ones we expose in MBeanInfo
52
for(int i = 0; i < statistics.length; ++i) {
53                 final Statistic JavaDoc origStatistic = statistics[i];
54
55                 final MapStatistic m = new MapStatisticImpl(origStatistic);
56
57                 final String JavaDoc convertedName = originalToDerivedStatisticName(origStatistic.getName());
58                 if (! convertedName.equals(origStatistic.getName()))
59                         m.setName(convertedName);
60
61                 final Class JavaDoc<? extends Statistic JavaDoc> theClass =
62                     StatisticFactory.getInterface(origStatistic);
63                 assert(theClass != null);
64
65                 // this will create one which implements the requisite interfaces
66
statistics[ i ] = StatisticFactory.create(theClass, m.asMap());
67
68                 assert(theClass.isAssignableFrom(statistics[ i ].getClass()));
69             }
70             return(statistics);
71         } catch (Exception JavaDoc e) {
72             final Throwable JavaDoc rootCause = ExceptionUtil.getRootCause(e);
73
74             if (!(rootCause instanceof InstanceNotFoundException JavaDoc))
75                     // don't rethrow--will make MBeanServer unuseable as it has a bug if we throw
76
// an exception of of getMBeanInfo() which halts any further processing of the query
77
//NOTE: WARNING_CHANGED_TO_FINE
78
logWarning("Can't get Statistics from impl of " + getObjectName() +
79                             "\n" + rootCause.getMessage() + "\n" + ExceptionUtil.getStackTrace(rootCause));
80             throw new RuntimeException JavaDoc(e);
81         }
82     }
83     
84     protected Statistic JavaDoc[] getStatisticsFromImplRaw(CustomStatsImpl impl) {
85     try {
86             final Statistic JavaDoc[] statistics = impl.getStatistics();
87             return statistics;
88     } catch (Exception JavaDoc e) {
89             final Throwable JavaDoc rootCause = ExceptionUtil.getRootCause( e );
90             logWarning( "CustomMonitoringStatsImplBase: " +
91                 "the stats impl for the stats of AMX MBean " +
92                 getObjectName() + " threw an exception: " + rootCause +
93                 ", stack = \n" + ExceptionUtil.getStackTrace( rootCause ) );
94         }
95         return new Statistic JavaDoc[0];
96     }
97 }
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
Popular Tags