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: * @(#)ProvisioningEndpointStatisticsDataCreator.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.IEndpointStatisticsData;
047: import com.sun.esb.management.common.data.ProvisioningEndpointStatisticsData;
048:
049: /**
050: * @author graj
051: *
052: */
053: public class ProvisioningEndpointStatisticsDataCreator {
054: /** table index */
055: static String[] STATS_TABLE_INDEX = new String[] { "InstanceName" };
056:
057: /**
058: *
059: */
060: public ProvisioningEndpointStatisticsDataCreator() {
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: ProvisioningEndpointStatisticsData data = (ProvisioningEndpointStatisticsData) value;
083: endpointStats[index++] = composeProviderEndpointStats(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 provider endpoint stats
110: * @param instanceName
111: * @param commonValues values common to both provider and consumer
112: * @param providerValues values specific to provider
113: * @param ojcStats table of performance data
114: * @return CompositeData composite data
115: *
116: */
117: protected static CompositeData composeProviderEndpointStats(
118: ProvisioningEndpointStatisticsData data)
119: throws ManagementRemoteException {
120:
121: TabularType ojcStatsType = null;
122: if (data.getCategoryToPerformanceDataMap() != null) {
123: //ojcStatsType = ojcStats.getTabularType();
124: }
125:
126: ArrayList<String> providerItemNames = new ArrayList<String>();
127: providerItemNames.add("InstanceName");
128: providerItemNames.add("ActivationTime");
129: providerItemNames.add("UpTime");
130: providerItemNames.add("NumActiveExchanges");
131: providerItemNames.add("NumReceivedRequests");
132: providerItemNames.add("NumSentReplies");
133: providerItemNames.add("NumReceivedDONEs");
134: providerItemNames.add("NumSentDONEs");
135: providerItemNames.add("NumReceivedFaults");
136: providerItemNames.add("NumSentFaults");
137: providerItemNames.add("NumReceivedErrors");
138: providerItemNames.add("NumSentErrors");
139: providerItemNames.add("ComponentName");
140: providerItemNames.add("ME-ResponseTime-Avg");
141: providerItemNames.add("ME-ComponentTime-Avg");
142: providerItemNames.add("ME-DeliveryChannelTime-Avg");
143: providerItemNames.add("ME-MessageServiceTime-Avg");
144: if (ojcStatsType != null) {
145: providerItemNames.add("PerformanceMeasurements");
146: }
147:
148: ArrayList<String> providerItemDescriptions = new ArrayList<String>();
149: providerItemDescriptions.add("Instance Name");
150: providerItemDescriptions.add("Time taken for activation");
151: providerItemDescriptions.add("Endpoint upTime");
152: providerItemDescriptions.add("Number of Active Exchanges");
153: providerItemDescriptions.add("Number of Received Requests");
154: providerItemDescriptions.add("Number of Sent Replies");
155: providerItemDescriptions.add("Number of Received DONEs");
156: providerItemDescriptions.add("Number of Sent DONEs");
157: providerItemDescriptions.add("Number of Received Faults");
158: providerItemDescriptions.add("Number of Sent Faults");
159: providerItemDescriptions.add("Number of Received Errors");
160: providerItemDescriptions.add("Number of Sent Errors");
161: providerItemDescriptions.add("Component Name");
162: providerItemDescriptions
163: .add("Message Exchange ResponseTime Avg in ns");
164: providerItemDescriptions
165: .add("Message Exchange ComponentTime Avg in ns");
166: providerItemDescriptions
167: .add("Message Exchange DeliveryChannelTime Avg in ns");
168: providerItemDescriptions
169: .add("Message Exchange MessageServiceTime Avg in ns");
170: if (ojcStatsType != null) {
171: providerItemDescriptions
172: .add("Performance Measurements recorded by OJC Components");
173: }
174:
175: ArrayList<OpenType> providerItemTypes = new ArrayList<OpenType>();
176: providerItemTypes.add(SimpleType.STRING);
177: providerItemTypes.add(SimpleType.LONG);
178: providerItemTypes.add(SimpleType.LONG);
179: providerItemTypes.add(SimpleType.LONG);
180: providerItemTypes.add(SimpleType.LONG);
181: providerItemTypes.add(SimpleType.LONG);
182: providerItemTypes.add(SimpleType.LONG);
183: providerItemTypes.add(SimpleType.LONG);
184: providerItemTypes.add(SimpleType.LONG);
185: providerItemTypes.add(SimpleType.LONG);
186: providerItemTypes.add(SimpleType.LONG);
187: providerItemTypes.add(SimpleType.LONG);
188: providerItemTypes.add(SimpleType.STRING);
189: providerItemTypes.add(SimpleType.LONG);
190: providerItemTypes.add(SimpleType.LONG);
191: providerItemTypes.add(SimpleType.LONG);
192: providerItemTypes.add(SimpleType.LONG);
193: if (ojcStatsType != null) {
194: providerItemTypes.add(ojcStatsType);
195: }
196: ;
197:
198: ArrayList<Object> providerItemValues = new ArrayList<Object>();
199: providerItemValues.add(data.getInstanceName());
200: providerItemValues.add(data.getActivationTime()); //ActivationTimestamp
201: providerItemValues.add(new Long(Long.MIN_VALUE)); //todo calculate uptime
202: providerItemValues.add(data.getNumberOfActiveExchanges()); //ActiveExchanges
203: providerItemValues.add(data.getNumberOfReceivedRequests()); //ReceiveRequest
204: providerItemValues.add(data.getNumberOfSentReplies()); //SendReply
205: providerItemValues.add(data.getNumberOfReceivedDones()); //ReceiveDONE
206: providerItemValues.add(data.getNumberOfSentDones()); //SendDONE
207: providerItemValues.add(data.getNumberOfReceivedFaults()); //ReceiveFault
208: providerItemValues.add(data.getNumberOfSentFaults()); //SendFault
209: providerItemValues.add(data.getNumberOfReceivedErrors()); //ReceiveERROR
210: providerItemValues.add(data.getNumberOfSentErrors()); //SendERROR
211: providerItemValues.add(data.getComponentName()); //OwningChannel
212: providerItemValues.add(data
213: .getMessageExchangeResponseTimeAverage()); //Response Time
214: providerItemValues.add(data
215: .getMessageExchangeDeliveryChannelTimeAverage()); //ChannelTimeAvg
216: providerItemValues.add(data
217: .getMessageExchangeComponentTimeAverage()); //ComponenTimeAvg
218: providerItemValues.add(data
219: .getMessageExchangeServiceTimeAverage()); //NMRTimeAvg
220: if (ojcStatsType != null) {
221: //providerItemValues.add(ojcStats);
222: }
223:
224: try {
225: return new CompositeDataSupport(new CompositeType(
226: "ProviderEndpointStats",
227: "Provider Endpoint Statistics",
228: (String[]) providerItemNames
229: .toArray(new String[] {}),
230: (String[]) providerItemDescriptions
231: .toArray(new String[] {}),
232: (SimpleType[]) providerItemTypes
233: .toArray(new SimpleType[] {})),
234: (String[]) providerItemNames
235: .toArray(new String[] {}),
236: (Object[]) providerItemValues
237: .toArray(new Object[] {}));
238: } catch (OpenDataException ode) {
239: throw new ManagementRemoteException(ode);
240: }
241: }
242:
243: /**
244: * @param args
245: */
246: public static void main(String[] args) {
247: // TODO Auto-generated method stub
248:
249: }
250:
251: }
|