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: * @(#)ConsumingEndpointStatisticsDataCreator.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.ArrayList;
032: import java.util.Map;
033: import java.util.Set;
034:
035: import javax.management.openmbean.CompositeData;
036: import javax.management.openmbean.CompositeDataSupport;
037: import javax.management.openmbean.CompositeType;
038: import javax.management.openmbean.OpenDataException;
039: import javax.management.openmbean.OpenType;
040: import javax.management.openmbean.SimpleType;
041: import javax.management.openmbean.TabularData;
042: import javax.management.openmbean.TabularDataSupport;
043: import javax.management.openmbean.TabularType;
044:
045: import com.sun.esb.management.common.ManagementRemoteException;
046: import com.sun.esb.management.common.data.ConsumingEndpointStatisticsData;
047: import com.sun.esb.management.common.data.IEndpointStatisticsData;
048:
049: /**
050: * @author graj
051: *
052: */
053: public class ConsumingEndpointStatisticsDataCreator {
054: /** table index */
055: static String[] STATS_TABLE_INDEX = new String[] { "InstanceName" };
056:
057: /**
058: *
059: */
060: public ConsumingEndpointStatisticsDataCreator() {
061: // TODO Auto-generated constructor stub
062: }
063:
064: /**
065: *
066: * @param data
067: * @return
068: * @throws ManagementRemoteException
069: */
070: public static TabularData createTabularData(
071: Map<String /* instanceName */, IEndpointStatisticsData> map)
072: throws ManagementRemoteException {
073: Set<String> instanceNames = map.keySet();
074:
075: TabularType endpointStatsTableType = null;
076: TabularData endpointsStatsTable = null;
077: CompositeData[] endpointStats = new CompositeData[instanceNames
078: .size()];
079: int index = 0;
080: for (String instanceName : instanceNames) {
081: IEndpointStatisticsData value = map.get(instanceName);
082: ConsumingEndpointStatisticsData data = (ConsumingEndpointStatisticsData) value;
083: endpointStats[index++] = composeConsumingEndpointStats(data);
084: }
085: // the tabular type could be constructed only after we have the endpoint
086: // stats composite type so we need atleast one entry
087: try {
088: if (index > 0 && endpointStats[0] != null) {
089: endpointStatsTableType = new TabularType(
090: "EndpointStats",
091: "Endpoint Statistic Information",
092: endpointStats[0].getCompositeType(),
093: STATS_TABLE_INDEX);
094: endpointsStatsTable = new TabularDataSupport(
095: endpointStatsTableType);
096:
097: for (int innerIndex = 0; innerIndex < index; innerIndex++) {
098: endpointsStatsTable.put(endpointStats[innerIndex]);
099: }
100: }
101: } catch (OpenDataException e) {
102: throw new ManagementRemoteException(e);
103: }
104:
105: return endpointsStatsTable;
106: }
107:
108: /**
109: * This method is used to compose consuming endpoint stats
110: * @param instanceName
111: * @param commonValues values common to both consuming and consumer
112: * @param consumingValues values specific to consuming
113: * @param ojcStats table of performance data
114: * @return CompositeData composite data
115: *
116: */
117: protected static CompositeData composeConsumingEndpointStats(
118: ConsumingEndpointStatisticsData data)
119: throws ManagementRemoteException {
120:
121: TabularType ojcStatsType = null;
122: if (data.getCategoryToPerformanceDataMap() != null) {
123: //ojcStatsType = ojcStats.getTabularType();
124: }
125:
126: ArrayList<String> consumerItemNames = new ArrayList<String>();
127: consumerItemNames.add("InstanceName");
128: consumerItemNames.add("NumSentRequests");
129: consumerItemNames.add("NumReceivedReplies");
130: consumerItemNames.add("NumReceivedDONEs");
131: consumerItemNames.add("NumSentDONEs");
132: consumerItemNames.add("NumReceivedFaults");
133: consumerItemNames.add("NumSentFaults");
134: consumerItemNames.add("NumReceivedErrors");
135: consumerItemNames.add("NumSentErrors");
136: consumerItemNames.add("NumActiveExchanges");
137: consumerItemNames.add("ComponentName");
138: consumerItemNames.add("ME-StatusTime-Avg");
139: consumerItemNames.add("ME-ComponentTime-Avg");
140: consumerItemNames.add("ME-DeliveryChannelTime-Avg");
141: consumerItemNames.add("ME-MessageServiceTime-Avg");
142: if (ojcStatsType != null) {
143: consumerItemNames.add("PerformanceMeasurements");
144: }
145:
146: ArrayList<String> consumerItemDescriptions = new ArrayList<String>();
147: consumerItemDescriptions.add("Instance Name");
148: consumerItemDescriptions.add("Number of Sent Requests");
149: consumerItemDescriptions.add("Number of Received Replies");
150: consumerItemDescriptions.add("Number of Received DONEs");
151: consumerItemDescriptions.add("Number of Sent DONEs");
152: consumerItemDescriptions.add("Number of Received Faults");
153: consumerItemDescriptions.add("Number of Sent Faults");
154: consumerItemDescriptions.add("Number of Received Errors");
155: consumerItemDescriptions.add("Number of Sent Errors");
156: consumerItemDescriptions.add("Number of active exchanges");
157: consumerItemDescriptions.add("Name of the owning component");
158: consumerItemDescriptions
159: .add("Message Exchange Status Time Avg in ns");
160: consumerItemDescriptions
161: .add("Message Exchange ComponentTime Avg in ns");
162: consumerItemDescriptions
163: .add("Message Exchange DeliveryChannelTime Avg in ns");
164: consumerItemDescriptions
165: .add("Message Exchange MessageServiceTime Avg in ns");
166: if (ojcStatsType != null) {
167: consumerItemDescriptions
168: .add("Performance Measurements recorded by OJC Components");
169: }
170: ;
171:
172: ArrayList<OpenType> consumerItemTypes = new ArrayList<OpenType>();
173: consumerItemTypes.add(SimpleType.STRING);
174: consumerItemTypes.add(SimpleType.LONG);
175: consumerItemTypes.add(SimpleType.LONG);
176: consumerItemTypes.add(SimpleType.LONG);
177: consumerItemTypes.add(SimpleType.LONG);
178: consumerItemTypes.add(SimpleType.LONG);
179: consumerItemTypes.add(SimpleType.LONG);
180: consumerItemTypes.add(SimpleType.LONG);
181: consumerItemTypes.add(SimpleType.LONG);
182: consumerItemTypes.add(SimpleType.LONG);
183: consumerItemTypes.add(SimpleType.STRING);
184: consumerItemTypes.add(SimpleType.LONG);
185: consumerItemTypes.add(SimpleType.LONG);
186: consumerItemTypes.add(SimpleType.LONG);
187: consumerItemTypes.add(SimpleType.LONG);
188: if (ojcStatsType != null) {
189: consumerItemTypes.add(ojcStatsType);
190: }
191:
192: ArrayList<Object> consumerItemValues = new ArrayList<Object>();
193: consumerItemValues.add(data.getInstanceName());
194: consumerItemValues.add(data.getNumberOfSentRequests());
195: consumerItemValues.add(data.getNumberOfReceivedReplies());
196: consumerItemValues.add(data.getNumberOfReceivedDones());
197: consumerItemValues.add(data.getNumberOfSentDones());
198: consumerItemValues.add(data.getNumberOfReceivedFaults());
199: consumerItemValues.add(data.getNumberOfSentFaults());
200: consumerItemValues.add(data.getNumberOfReceivedErrors());
201: consumerItemValues.add(data.getNumberOfSentErrors());
202: consumerItemValues.add(data.getNumberOfActiveExchanges());
203: consumerItemValues.add(data.getComponentName());
204: consumerItemValues.add(data
205: .getMessageExchangeStatusTimeAverage());
206: consumerItemValues.add(data
207: .getMessageExchangeComponentTimeAverage());
208: consumerItemValues.add(data
209: .getMessageExchangeDeliveryChannelTimeAverage());
210: consumerItemValues.add(data
211: .getMessageExchangeServiceTimeAverage());
212:
213: if (ojcStatsType != null) {
214: //consumerItemValues.add(ojcStats);
215: }
216:
217: try {
218: return new CompositeDataSupport(new CompositeType(
219: "ConsumerEndpointStats",
220: "Consumer Endpoint Statistics",
221: (String[]) consumerItemNames
222: .toArray(new String[] {}),
223: (String[]) consumerItemDescriptions
224: .toArray(new String[] {}),
225: (SimpleType[]) consumerItemTypes
226: .toArray(new SimpleType[] {})),
227: (String[]) consumerItemNames
228: .toArray(new String[] {}),
229: (Object[]) consumerItemValues
230: .toArray(new Object[] {}));
231: } catch (OpenDataException ode) {
232: throw new ManagementRemoteException(ode);
233: }
234:
235: }
236:
237: /**
238: * @param args
239: */
240: public static void main(String[] args) {
241: // TODO Auto-generated method stub
242:
243: }
244:
245: }
|