001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: /*
038: * RuntimeMonitoringUtils.java
039: *
040: */
041:
042: package com.sun.jbi.jsf.util;
043:
044: import com.sun.jbi.jsf.util.BeanUtilities;
045: import com.sun.jbi.ui.common.JBIAdminCommands;
046: import java.util.Properties;
047: import java.util.logging.Level;
048: import java.util.logging.Logger;
049: import javax.management.openmbean.TabularData;
050:
051: /**
052: *
053: * This class is used to provide utilitiies for the Component
054: * Application Configuration use-cases
055: *
056: **/
057:
058: public final class RuntimeMonitoringUtils {
059:
060: /**
061: * Controls printing of diagnostic messages to the log
062: */
063: private static Logger sLog = JBILogger.getInstance();
064:
065: /**
066: * Gets endpoint statistics for specified endpoint on the specified
067: * target
068: * @param anEndpointName endpoint
069: * @param anInstanceName target cluster name or standalone instance name
070: * @param aStatus Properties to receive a status result
071: * @return TabularData with endpoint statistics (or null)
072: */
073: public static TabularData getEndpointStats(String anEndpointName,
074: String aClusterOrSaTargetName, Properties aStatus) {
075: sLog.fine("RuntimeMonitoringUtils.getEndpointStats("
076: + anEndpointName + ", " + aClusterOrSaTargetName + ", "
077: + aStatus + ")");
078:
079: TabularData result = null;
080:
081: try {
082: JBIAdminCommands jac = BeanUtilities.getClient();
083:
084: result = jac.getEndpointStats(anEndpointName,
085: aClusterOrSaTargetName);
086: aStatus.put("success-result", anEndpointName);
087: } catch (com.sun.jbi.ui.common.JBIRemoteException jrEx) {
088: sLog
089: .log(
090: Level.FINE,
091: ("RuntimeMonitoringUtils.getEndpointStats(...) caught jrEx=" + jrEx),
092: jrEx);
093: aStatus.put("failure-result", jrEx.toString()); // TBD management message
094: }
095:
096: sLog.fine("RuntimeMonitoringUtils.getEndpoint(...), result="
097: + result + ", aStatus=" + aStatus);
098:
099: return result;
100: }
101:
102: /**
103: * Gets framework statistics for specified instance, if available
104: * @param anInstanceName String instance with target MBean for the component
105: * @param aStatus Properties to receive a status result
106: * @return TabularData with framework statistics (or null)
107: */
108: public static TabularData getFrameworkStats(String anInstanceName,
109: Properties aStatus) {
110: sLog.fine("RuntimeMonitoringUtils.getFrameworkStats("
111: + anInstanceName + ", " + aStatus + ")");
112:
113: TabularData result = null;
114:
115: try {
116: JBIAdminCommands jac = BeanUtilities.getClient();
117:
118: result = jac.getFrameworkStats(anInstanceName);
119: aStatus.put("success-result", anInstanceName);
120: } catch (com.sun.jbi.ui.common.JBIRemoteException jrEx) {
121: sLog
122: .log(
123: Level.FINE,
124: ("RuntimeMonitoringUtils.getFrameworkStats(...) caught jrEx=" + jrEx),
125: jrEx);
126: aStatus.put("failure-result", jrEx.toString()); // TBD management message
127: }
128:
129: sLog
130: .fine("RuntimeMonitoringUtils.getFrameworkStats(...), result="
131: + result + ", aStatus=" + aStatus);
132:
133: return result;
134: }
135:
136: /**
137: * Gets NMR statistics for specified instance, if available
138: * @param anInstanceName String instance with target MBean for the component
139: * @param aStatus Properties to receive a status result
140: * @return TabularData with NMR statistics (or null)
141: */
142: public static TabularData getNMRStats(String anInstanceName,
143: Properties aStatus) {
144: sLog.fine("RuntimeMonitoringUtils.getNMRStats("
145: + anInstanceName + ", " + aStatus + ")");
146:
147: TabularData result = null;
148:
149: try {
150: JBIAdminCommands jac = BeanUtilities.getClient();
151:
152: result = jac.getNMRStats(anInstanceName);
153: aStatus.put("success-result", anInstanceName);
154: } catch (com.sun.jbi.ui.common.JBIRemoteException jrEx) {
155: sLog
156: .log(
157: Level.FINE,
158: ("RuntimeMonitoringUtils.getNMRStats(...) caught jrEx=" + jrEx),
159: jrEx);
160: aStatus.put("failure-result", jrEx.toString()); // TBD management message
161: }
162:
163: sLog.fine("RuntimeMonitoringUtils.getNMRStats(...), result="
164: + result + ", aStatus=" + aStatus);
165:
166: return result;
167: }
168:
169: }
|