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: * @(#)FrameworkStatisticsData.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.Serializable;
032: import java.util.HashMap;
033: import java.util.Iterator;
034: import java.util.Map;
035:
036: import javax.management.openmbean.CompositeData;
037: import javax.management.openmbean.CompositeType;
038: import javax.management.openmbean.TabularData;
039: import javax.xml.parsers.ParserConfigurationException;
040: import javax.xml.transform.TransformerException;
041:
042: import com.sun.esb.management.common.ManagementRemoteException;
043: import com.sun.esb.management.common.data.helper.FrameworkStatisticsDataWriter;
044:
045: /**
046: * @author graj
047: *
048: */
049: public class FrameworkStatisticsData implements Serializable {
050: static final long serialVersionUID = -1L;
051:
052: public static final String INSTANCENAME_KEY = "InstanceName";
053: public static final String STARTUPTIME_KEY = "StartupTime (ms)";
054: public static final String UPTIME_KEY = "UpTime (ms)";
055:
056: String instanceName;
057: long startupTime;
058: long upTime;
059:
060: /**
061: * Generate Tabular Data for this object
062: * @return tabular data of this object
063: */
064: static public TabularData generateTabularData(
065: Map<String /* instanceName */, FrameworkStatisticsData> map) {
066: TabularData tabularData = null;
067: try {
068: tabularData = FrameworkStatisticsDataCreator
069: .createTabularData(map);
070: } catch (ManagementRemoteException e) {
071: }
072: return tabularData;
073: }
074:
075: /**
076: * Retrieves the Framework Statistics Data Map
077: *
078: * @param tabularData
079: * @return Framework Statistics Data
080: */
081: @SuppressWarnings("unchecked")
082: static public Map<String /* instanceName */, FrameworkStatisticsData> retrieveDataMap(
083: TabularData tabularData) {
084: FrameworkStatisticsData data = null;
085: Map<String /* instanceName */, FrameworkStatisticsData> dataMap = null;
086: dataMap = new HashMap<String /* instanceName */, FrameworkStatisticsData>();
087: for (Iterator dataIterator = tabularData.values().iterator(); dataIterator
088: .hasNext();) {
089: CompositeData compositeData = (CompositeData) dataIterator
090: .next();
091: CompositeType compositeType = compositeData
092: .getCompositeType();
093: data = new FrameworkStatisticsData();
094: for (Iterator<String> itemIterator = compositeType.keySet()
095: .iterator(); itemIterator.hasNext();) {
096: String item = (String) itemIterator.next();
097: if (true == item
098: .equals(FrameworkStatisticsData.INSTANCENAME_KEY)) {
099: String value = (String) compositeData.get(item);
100: data.setInstanceName(value);
101: }
102: if (true == item
103: .equals(FrameworkStatisticsData.STARTUPTIME_KEY)) {
104: Long value = (Long) compositeData.get(item);
105: data.setStartupTime(value.longValue());
106: }
107: if (true == item
108: .equals(FrameworkStatisticsData.UPTIME_KEY)) {
109: Long value = (Long) compositeData.get(item);
110: data.setUpTime(value.longValue());
111: }
112: }
113: dataMap.put(data.getInstanceName(), data);
114:
115: }
116: return dataMap;
117: }
118:
119: /**
120: * Converts a Framework Statistics Data to an XML String
121: *
122: * @param map
123: * @return XML string representing a Framework Statistics Datum
124: * @throws ManagementRemoteException
125: */
126: static public String convertDataMapToXML(
127: Map<String /* instanceName */, FrameworkStatisticsData> map)
128: throws ManagementRemoteException {
129: String xmlText = null;
130: try {
131: xmlText = FrameworkStatisticsDataWriter.serialize(map);
132: } catch (ParserConfigurationException e) {
133: throw new ManagementRemoteException(e);
134: } catch (TransformerException e) {
135: throw new ManagementRemoteException(e);
136: }
137:
138: return xmlText;
139:
140: }
141:
142: /**
143: * @return the instanceName
144: */
145: public String getInstanceName() {
146: return this .instanceName;
147: }
148:
149: /**
150: * @param instanceName the instanceName to set
151: */
152: public void setInstanceName(String instanceName) {
153: this .instanceName = instanceName;
154: }
155:
156: /**
157: * @return the startupTime
158: */
159: public long getStartupTime() {
160: return this .startupTime;
161: }
162:
163: /**
164: * @param startupTime the startupTime to set
165: */
166: public void setStartupTime(long startupTime) {
167: this .startupTime = startupTime;
168: }
169:
170: /**
171: * @return the upTime
172: */
173: public long getUpTime() {
174: return this .upTime;
175: }
176:
177: /**
178: * @param upTime the upTime to set
179: */
180: public void setUpTime(long uptime) {
181: this .upTime = uptime;
182: }
183:
184: /**
185: *
186: * @return
187: */
188: public String getDisplayString() {
189: StringBuffer buffer = new StringBuffer();
190: buffer.append("\n Instance Name" + "="
191: + this .getInstanceName());
192: buffer.append("\n Startup Time" + "=" + this .getStartupTime());
193: buffer.append("\n Up Time" + "=" + this .getUpTime());
194: buffer.append("\n ========================================\n");
195: return buffer.toString();
196:
197: }
198:
199: /**
200: * @param args
201: */
202: public static void main(String[] args) {
203: // TODO Auto-generated method stub
204:
205: }
206:
207: }
|