001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)FrameworkStatisticsDataCreator.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.esb.management.common.data;
030:
031: import java.io.IOException;
032: import java.net.MalformedURLException;
033: import java.net.URISyntaxException;
034: import java.util.Map;
035: import java.util.Set;
036:
037: import javax.management.openmbean.CompositeData;
038: import javax.management.openmbean.CompositeDataSupport;
039: import javax.management.openmbean.CompositeType;
040: import javax.management.openmbean.OpenDataException;
041: import javax.management.openmbean.OpenType;
042: import javax.management.openmbean.SimpleType;
043: import javax.management.openmbean.TabularData;
044: import javax.management.openmbean.TabularDataSupport;
045: import javax.management.openmbean.TabularType;
046: import javax.xml.parsers.ParserConfigurationException;
047:
048: import org.xml.sax.SAXException;
049:
050: import com.sun.esb.management.common.ManagementRemoteException;
051: import com.sun.esb.management.common.data.helper.FrameworkStatisticsDataReader;
052: import com.sun.jbi.ui.common.JBIRemoteException;
053:
054: /**
055: * @author graj
056: *
057: */
058: public class FrameworkStatisticsDataCreator {
059:
060: /** framework startup time */
061: public static String FRAMEWORK_STARTUP_TIME = "StartupTime";
062:
063: /** framework last restart time */
064: public static String FRAMEWORK_LAST_RESTART_TIME = "LastRestartTime";
065:
066: /** FrameworkStats CompositeType item names */
067: static String[] FRAMEWORK_STATS_ITEM_NAMES = { "InstanceName",
068: "StartupTime", "UpTime" };
069:
070: /** FrameworkStats CompositeType item descriptions */
071: static String[] FRAMEWORK_STATS_ITEM_DESCRIPTIONS = {
072: "Instance Name",
073: "Time taken to startup the framework (ms)",
074: "Time elapsed since framework has been started (ms)" };
075:
076: /** FrameworkStats CompositeType item types */
077: static OpenType[] FRAMEWORK_STATS_ITEM_TYPES = { SimpleType.STRING,
078: SimpleType.LONG, SimpleType.LONG };
079:
080: /** FrameworkStats table index */
081: static String[] FRAMEWORK_STATS_TABLE_INDEX = new String[] { "InstanceName" };
082:
083: /**
084: *
085: */
086: public FrameworkStatisticsDataCreator() {
087: }
088:
089: /**
090: *
091: * @param data
092: * @return
093: * @throws ManagementRemoteException
094: */
095: public static TabularData createTabularData(
096: Map<String /* instanceName */, FrameworkStatisticsData> map)
097: throws ManagementRemoteException {
098: TabularData frameworkStatsTable = null;
099: try {
100: CompositeType frameworkStatsEntriesType = new CompositeType(
101: "FrameworkStatistics", "Framework Statistics",
102: FRAMEWORK_STATS_ITEM_NAMES,
103: FRAMEWORK_STATS_ITEM_DESCRIPTIONS,
104: FRAMEWORK_STATS_ITEM_TYPES);
105:
106: TabularType frameworkStatsType = new TabularType(
107: "FrameworkStats",
108: "Framework Statistic Information",
109: frameworkStatsEntriesType,
110: FRAMEWORK_STATS_TABLE_INDEX);
111:
112: frameworkStatsTable = new TabularDataSupport(
113: frameworkStatsType);
114: Set<String> instances = map.keySet();
115: for (String instanceName : instances) {
116: FrameworkStatisticsData data = map.get(instanceName);
117: frameworkStatsTable.put(getFrameworkStatistics(
118: frameworkStatsEntriesType, data));
119: }
120:
121: } catch (OpenDataException e) {
122: throw new ManagementRemoteException(e);
123: }
124: return frameworkStatsTable;
125: }
126:
127: /**
128: * This method is used to provide query framework statistics from
129: * the given data
130: * @param frameworkStatsEntriesType
131: * @param data
132: * @return
133: * @throws JBIRemoteException
134: */
135: protected static CompositeData getFrameworkStatistics(
136: CompositeType frameworkStatsEntriesType,
137: FrameworkStatisticsData data)
138: throws ManagementRemoteException {
139: try {
140: Object[] values = { data.getInstanceName(),
141: data.getStartupTime(), data.getUpTime() };
142:
143: return new CompositeDataSupport(frameworkStatsEntriesType,
144: FRAMEWORK_STATS_ITEM_NAMES, values);
145:
146: } catch (Exception ex) {
147: throw new ManagementRemoteException(ex);
148: }
149: }
150:
151: /**
152: * @param args
153: */
154: public static void main(String[] args) {
155: String uri = "C:/test/schema/frameworkstatistics/FrameworkStatisticsData.xml";
156: try {
157: Map<String /* instanceName */, FrameworkStatisticsData> map = null;
158: map = FrameworkStatisticsDataReader.parseFromFile(uri);
159: for (String instanceName : map.keySet()) {
160: System.out.println(map.get(instanceName)
161: .getDisplayString());
162: }
163: TabularData data = FrameworkStatisticsDataCreator
164: .createTabularData(map);
165: System.out.println(data);
166: } catch (MalformedURLException e) {
167: e.printStackTrace();
168: } catch (ManagementRemoteException e) {
169: e.printStackTrace();
170: } catch (ParserConfigurationException e) {
171: e.printStackTrace();
172: } catch (SAXException e) {
173: e.printStackTrace();
174: } catch (URISyntaxException e) {
175: e.printStackTrace();
176: } catch (IOException e) {
177: e.printStackTrace();
178: }
179: }
180:
181: }
|