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: * @(#)ServiceAssemblyStatisticsDataCreator.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.List;
032: import java.util.Map;
033: import java.util.Set;
034:
035: import javax.management.openmbean.ArrayType;
036: import javax.management.openmbean.CompositeData;
037: import javax.management.openmbean.CompositeDataSupport;
038: import javax.management.openmbean.CompositeType;
039: import javax.management.openmbean.OpenDataException;
040: import javax.management.openmbean.OpenType;
041: import javax.management.openmbean.SimpleType;
042: import javax.management.openmbean.TabularData;
043: import javax.management.openmbean.TabularDataSupport;
044: import javax.management.openmbean.TabularType;
045:
046: import com.sun.esb.management.common.ManagementRemoteException;
047: import com.sun.esb.management.common.data.ServiceAssemblyStatisticsData;
048: import com.sun.esb.management.common.data.ServiceUnitStatisticsData;
049:
050: /**
051: * @author graj
052: *
053: */
054: public class ServiceAssemblyStatisticsDataCreator {
055:
056: protected static CompositeType serviceUnitStatsType;
057:
058: protected static CompositeType serviceAssemblyStatsType;
059:
060: /** table index */
061: static String[] STATS_TABLE_INDEX = new String[] { "InstanceName" };
062:
063: /**
064: * item names for service unit stats
065: */
066: protected static String[] SU_STATS_ITEMS = { "ServiceUnitName",
067: "ServiceUnitStartupTime Avg (ms)",
068: "ServiceUnitStopTime Avg (ms)",
069: "ServiceUnitShutdownTime Avg (ms)", "Endpoints" };
070:
071: /**
072: * descriptions for service unit stats
073: */
074: protected static String[] SU_STATS_DESCRIPTIONS = {
075: "Service Unit Name", "Service Unit StartupTime Avg (ms)",
076: "Service Unit StopTime Avg (ms)",
077: "Service Unit ShutdownTime Avg (ms)", "Endpoints List" };
078:
079: /**
080: * item names for SA stats
081: */
082: protected static String[] SA_STATS_ITEMS = { "InstanceName",
083: "ServiceAssemblyName", "LastStartupTime",
084: "StartupTime Avg (ms)", "StopTime Avg (ms)",
085: "ShutdownTime Avg (ms)", "UpTime", "ServiceUnitStatistics" };
086:
087: /**
088: * item descriptions for SA stats
089: */
090: protected static String[] SA_STATS_DESCRIPTIONS = {
091: "JBI Instance Name", "Service Assembly Name",
092: "Last Startup Time", "Startup Time Avg (ms)",
093: "Stop Time Avg (ms)", "Up Time (ms)",
094: "Shutdown Time Avg (ms)", "ServiceUnit Statistics" };
095:
096: /**
097: *
098: */
099: public ServiceAssemblyStatisticsDataCreator() {
100: }
101:
102: /**
103: *
104: * @param data
105: * @return
106: * @throws ManagementRemoteException
107: */
108: public static TabularData createTabularData(
109: Map<String /* instanceName */, ServiceAssemblyStatisticsData> map)
110: throws ManagementRemoteException {
111: TabularType saStatsTableType = null;
112: TabularData saStatsTable = null;
113: Set<String> instances = map.keySet();
114: CompositeData[] saStats = new CompositeData[instances.size()];
115:
116: try {
117: //All the stats provided by deployment service are
118: //exposed. So we don't have a static composite type.
119:
120: int index = 0;
121: for (String instance : instances) {
122: ServiceAssemblyStatisticsData data = map.get(instance);
123: if (data != null) {
124:
125: saStats[index++] = getCompositeData(data);
126: }
127: }
128: //the tabular type could be constructed only after we have the component stats composite type
129: //so we need atleast one entry
130: if (index > 0 && saStats[0] != null) {
131: saStatsTableType = new TabularType(
132: "DeploymentServiceStatistics",
133: "Deployment Service Statistics", saStats[0]
134: .getCompositeType(), STATS_TABLE_INDEX);
135: saStatsTable = new TabularDataSupport(saStatsTableType);
136:
137: for (int innerIndex = 0; innerIndex < index; innerIndex++) {
138: saStatsTable.put(saStats[innerIndex]);
139: }
140: }
141: } catch (OpenDataException ex) {
142: throw new ManagementRemoteException(ex);
143:
144: }
145: return saStatsTable;
146: }
147:
148: /**
149: * return the stats as composite data
150: */
151: protected static CompositeData getCompositeData(
152: ServiceAssemblyStatisticsData data)
153: throws OpenDataException {
154: List<ServiceUnitStatisticsData> serviceUnitStatisticsList = null;
155: serviceUnitStatisticsList = data.getServiceUnitStatisticsList();
156:
157: CompositeData[] serviceUnitStats = new CompositeData[serviceUnitStatisticsList
158: .size()];
159:
160: int index = 0;
161: for (ServiceUnitStatisticsData unitData : serviceUnitStatisticsList) {
162: serviceUnitStats[index++] = getCompositeData(unitData);
163: }
164: Object values[] = { data.getInstanceName(), data.getName(),
165: data.getLastStartupTime(),
166: data.getStartupTimeAverage(),
167: data.getStopTimeAverage(),
168: data.getShutdownTimeAverage(), serviceUnitStats };
169: return new CompositeDataSupport(serviceAssemblyStatsType,
170: SA_STATS_ITEMS, values);
171: }
172:
173: /**
174: * This method is used to obtain a CompositeData represenation
175: * of the collected statistics
176: * @return CompositeData
177: */
178: protected static CompositeData getCompositeData(
179: ServiceUnitStatisticsData data) throws OpenDataException {
180:
181: Object values[] = new Object[] { data.getName(),
182: data.getStartupTimeAverage(),
183: data.getStopTimeAverage(),
184: data.getShutdownTimeAverage(),
185: data.getEndpointNameArray() };
186: return new CompositeDataSupport(serviceUnitStatsType,
187: SU_STATS_ITEMS, values);
188:
189: }
190:
191: /**
192: * This is a helper method that is used to create the
193: * composite types for SA stats and SU stats
194: */
195: protected void createCompositeTypes() {
196: try {
197: OpenType[] SU_STATS_ITEM_TYPES = new OpenType[] {
198: SimpleType.STRING, SimpleType.LONG,
199: SimpleType.LONG, SimpleType.LONG,
200: new ArrayType(1, SimpleType.STRING) };
201:
202: //CompositeType for Service Unit stats
203: serviceUnitStatsType = new CompositeType(
204: "ServiceUnitStatistics", "Service Unit Statistics",
205: SU_STATS_ITEMS, SU_STATS_DESCRIPTIONS,
206: SU_STATS_ITEM_TYPES);
207:
208: //Item types for SA stats
209: OpenType[] SA_STATS_TYPES = new OpenType[] {
210: SimpleType.STRING, SimpleType.STRING,
211: SimpleType.DATE, SimpleType.LONG, SimpleType.LONG,
212: SimpleType.LONG, SimpleType.LONG,
213: new ArrayType(1, serviceUnitStatsType) };
214:
215: //CompositeType for SA stats
216: serviceAssemblyStatsType = new CompositeType(
217: "ServiceAssemblyStatistics",
218: "Service Assembly Statistics", SA_STATS_ITEMS,
219: SA_STATS_DESCRIPTIONS, SA_STATS_TYPES);
220: } catch (OpenDataException ode) {
221:
222: }
223: }
224:
225: /**
226: * @param args
227: */
228: public static void main(String[] args) {
229: // TODO Auto-generated method stub
230:
231: }
232:
233: }
|