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: * @(#)ComponentStatisticsDataCreator.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.helper;
030:
031: import java.util.Map;
032: import java.util.Set;
033:
034: import javax.management.openmbean.CompositeData;
035: import javax.management.openmbean.CompositeDataSupport;
036: import javax.management.openmbean.CompositeType;
037: import javax.management.openmbean.OpenDataException;
038: import javax.management.openmbean.OpenType;
039: import javax.management.openmbean.SimpleType;
040: import javax.management.openmbean.TabularData;
041: import javax.management.openmbean.TabularDataSupport;
042: import javax.management.openmbean.TabularType;
043:
044: import com.sun.esb.management.common.ManagementRemoteException;
045: import com.sun.esb.management.common.data.ComponentStatisticsData;
046:
047: /**
048: * @author graj
049: *
050: */
051: public class ComponentStatisticsDataCreator {
052: /** table index */
053: protected static String[] STATS_TABLE_INDEX = new String[] { "InstanceName" };
054:
055: protected static String[] itemNames = new String[] {
056: "InstanceName", "ComponentUpTime", "NumActivatedEndpoints",
057: "NumReceivedRequests", "NumSentRequests",
058: "NumReceivedReplies", "NumSentReplies", "NumReceivedDONEs",
059: "NumSentDONEs", "NumReceivedFaults", "NumSentFaults",
060: "NumReceivedErrors", "NumSentErrors",
061: "NumCompletedExchanges", "NumActiveExchanges",
062: "NumErrorExchanges", "ME-ResponseTime-Avg",
063: "ME-ComponentTime-Avg", "ME-DeliveryChannelTime-Avg",
064: "ME-MessageServiceTime-Avg", "ComponentExtensionStats" };
065:
066: protected static String[] itemDescriptions = new String[] {
067: "Instance Name", "Component Uptime",
068: "Number of activated endpoints",
069: "Number of received requests", "Number of sent requests",
070: "Number of received replies", "Number of sent replies",
071: "Number of received DONEs", "Number of sent DONEs",
072: "Number of received faults", "Number of sent faults",
073: "Number of received errors", "Number of sent errors",
074: "Number of completed exchanges",
075: "Number of active exchanges", "Number of error exchanges",
076: "Avg. response time for message exchange",
077: "Avg. time taken in component by message exchange",
078: "Avg. time taken in delivery channel by message exchange",
079: "Avg. time taken in message service by message exchange",
080: "Statistics reported by component statistics MBeans" };
081:
082: protected static String[] itemNamesNoExt = new String[] {
083: "InstanceName", "ComponentUpTime", "NumActivatedEndpoints",
084: "NumReceivedRequests", "NumSentRequests",
085: "NumReceivedReplies", "NumSentReplies", "NumReceivedDONEs",
086: "NumSentDONEs", "NumReceivedFaults", "NumSentFaults",
087: "NumReceivedErrors", "NumSentErrors",
088: "NumCompletedExchanges", "NumActiveExchanges",
089: "NumErrorExchanges", "ME-ResponseTime-Avg",
090: "ME-ComponentTime-Avg", "ME-DeliveryChannelTime-Avg",
091: "ME-MessageServiceTime-Avg" };
092:
093: protected static String[] itemDescriptionsNoExt = new String[] {
094: "Instance Name", "Component Uptime",
095: "Number of activated endpoints",
096: "Number of received requests", "Number of sent requests",
097: "Number of received replies", "Number of sent replies",
098: "Number of received DONEs", "Number of sent DONEs",
099: "Number of received faults", "Number of sent faults",
100: "Number of received errors", "Number of sent errors",
101: "Number of completed exchanges",
102: "Number of active exchanges", "Number of error exchanges",
103: "Avg. response time for message exchange",
104: "Avg. time taken in component by message exchange",
105: "Avg. time taken in delivery channel by message exchange",
106: "Avg. time taken in message service by message exchange" };
107:
108: /**
109: *
110: */
111: public ComponentStatisticsDataCreator() {
112: }
113:
114: /**
115: *
116: * @param data
117: * @return
118: * @throws ManagementRemoteException
119: */
120: public static TabularData createTabularData(
121: Map<String /* instanceName */, ComponentStatisticsData> map)
122: throws ManagementRemoteException {
123: TabularData componentStatisticsTable = null;
124: TabularType componentStatisticsTableType = null;
125:
126: Set<String> instanceNames = map.keySet();
127: CompositeData[] componentStatistics = new CompositeData[instanceNames
128: .size()];
129: int index = 0;
130: for (String instanceName : instanceNames) {
131: ComponentStatisticsData data = map.get(instanceName);
132: if (data != null) {
133: componentStatistics[index++] = composeComponentStatistics(data);
134: }
135: }
136: // The tabular type can be constructed only after we have the component
137: // statistics composite type. We need at least one entry
138: try {
139: if (index > 0 && componentStatistics[0] != null) {
140: componentStatisticsTableType = new TabularType(
141: "ComponentStats",
142: "Component Statistic Information",
143: componentStatistics[0].getCompositeType(),
144: STATS_TABLE_INDEX);
145: componentStatisticsTable = new TabularDataSupport(
146: componentStatisticsTableType);
147:
148: for (int innerIndex = 0; innerIndex < index; innerIndex++) {
149: componentStatisticsTable
150: .put(componentStatistics[innerIndex]);
151: }
152: }
153: } catch (OpenDataException e) {
154: throw new ManagementRemoteException(e);
155: }
156:
157: return componentStatisticsTable;
158: }
159:
160: /**
161: * This method is used compose component statistics composite data
162: * @param data
163: * @return
164: * @throws ManagementRemoteException
165: */
166: protected static CompositeData composeComponentStatistics(
167: ComponentStatisticsData data)
168: throws ManagementRemoteException {
169: try {
170: CompositeType type = null;
171: if (data.getComponentExtensionStatus() != null) {
172: type = data.getComponentExtensionStatus()
173: .getCompositeType();
174: }
175:
176: OpenType[] itemTypes = null;
177: Object[] itemValues = null;
178: if (type != null) {
179: itemTypes = new OpenType[] { SimpleType.STRING,
180: SimpleType.LONG, SimpleType.LONG,
181: SimpleType.LONG, SimpleType.LONG,
182: SimpleType.LONG, SimpleType.LONG,
183: SimpleType.LONG, SimpleType.LONG,
184: SimpleType.LONG, SimpleType.LONG,
185: SimpleType.LONG, SimpleType.LONG,
186: SimpleType.LONG, SimpleType.LONG,
187: SimpleType.LONG, SimpleType.LONG,
188: SimpleType.LONG, SimpleType.LONG,
189: SimpleType.LONG, type };
190:
191: itemValues = new Object[] {
192: data.getInstanceName(),
193: data.getComponentUpTime(),
194: data.getNumberOfReceivedRequests(),
195: data.getNumberOfSentRequests(),
196: data.getNumberOfReceivedReplies(),
197: data.getNumberOfSentReplies(),
198: data.getNumberOfReceivedDones(),
199: data.getNumberOfSentDones(),
200: data.getNumberOfReceivedFaults(),
201: data.getNumberOfSentFaults(),
202: data.getNumberOfReceivedErrors(),
203: data.getNumberOfSentErrors(),
204: data.getNumberOfCompletedExchanges(),
205: data.getNumberOfActiveExchanges(),
206: data.getNumberOfActiveExchanges(),
207: data.getNumberOfErrorExchanges(),
208: data.getMessageExchangeResponseTimeAverage(),
209: data.getMessageExchangeComponentTimeAverage(),
210: data
211: .getMessageExchangeDeliveryChannelTimeAverage(),
212: data
213: .getMessageExchangeMessageServiceTimeAverage(),
214: data.getComponentExtensionStatus() };
215:
216: return new CompositeDataSupport(new CompositeType(
217: "ComponentStats", "Component Statistics",
218: itemNames, itemDescriptions, itemTypes),
219: itemNames, itemValues);
220: } else {
221: itemTypes = new OpenType[] { SimpleType.STRING,
222: SimpleType.LONG, SimpleType.LONG,
223: SimpleType.LONG, SimpleType.LONG,
224: SimpleType.LONG, SimpleType.LONG,
225: SimpleType.LONG, SimpleType.LONG,
226: SimpleType.LONG, SimpleType.LONG,
227: SimpleType.LONG, SimpleType.LONG,
228: SimpleType.LONG, SimpleType.LONG,
229: SimpleType.LONG, SimpleType.LONG,
230: SimpleType.LONG, SimpleType.LONG,
231: SimpleType.LONG, };
232:
233: itemValues = new Object[] {
234: data.getInstanceName(),
235: data.getComponentUpTime(),
236: data.getNumberOfReceivedRequests(),
237: data.getNumberOfSentRequests(),
238: data.getNumberOfReceivedReplies(),
239: data.getNumberOfSentReplies(),
240: data.getNumberOfReceivedDones(),
241: data.getNumberOfSentDones(),
242: data.getNumberOfReceivedFaults(),
243: data.getNumberOfSentFaults(),
244: data.getNumberOfReceivedErrors(),
245: data.getNumberOfSentErrors(),
246: data.getNumberOfCompletedExchanges(),
247: data.getNumberOfActiveExchanges(),
248: data.getNumberOfActiveExchanges(),
249: data.getNumberOfErrorExchanges(),
250: data.getMessageExchangeResponseTimeAverage(),
251: data.getMessageExchangeComponentTimeAverage(),
252: data
253: .getMessageExchangeDeliveryChannelTimeAverage(),
254: data
255: .getMessageExchangeMessageServiceTimeAverage() };
256:
257: return new CompositeDataSupport(new CompositeType(
258: "ComponentStats", "Component Statistics",
259: itemNamesNoExt, itemDescriptionsNoExt,
260: itemTypes), itemNamesNoExt, itemValues);
261: }
262:
263: } catch (OpenDataException ex) {
264: throw new ManagementRemoteException(ex);
265: }
266: }
267:
268: /**
269: * @param args
270: */
271: public static void main(String[] args) {
272: // TODO Auto-generated method stub
273:
274: }
275:
276: }
|