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: * @(#)ServiceUnitStatisticsData.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.ArrayList;
033: import java.util.Collection;
034: import java.util.List;
035:
036: /**
037: * Provides Service Unit Statistics
038: *
039: * @author graj
040: *
041: */
042: public class ServiceUnitStatisticsData implements Serializable {
043: static final long serialVersionUID = -1L;
044:
045: public static final String NAME_KEY = "ServiceUnitName";
046:
047: public static final String STARTUP_TIME_AVG_KEY = "ServiceUnitStartupTime Avg (ms)";
048:
049: public static final String STOP_TIME_AVG_KEY = "ServiceUnitStopTime Avg (ms)";
050:
051: public static final String SHUTDOWN_TIME_AVG_KEY = "ServiceUnitShutdownTime Avg (ms)";
052:
053: public static final String ENDPOINTS_KEY = "Endpoints";
054:
055: protected String name;
056:
057: protected long startupTimeAverage;
058:
059: protected long stopTimeAverage;
060:
061: protected long shutdownTimeAverage;
062:
063: protected List<String /* endpointName */> endpointNameList = new ArrayList<String /* endpointName */>();
064:
065: /** Constructor - creates a ServiceUnitStatisticsData object */
066: public ServiceUnitStatisticsData() {
067: }
068:
069: /**
070: * @return the serviceUnitName
071: */
072: public String getName() {
073: return this .name;
074: }
075:
076: /**
077: * @param serviceUnitName
078: * the serviceUnitName to set
079: */
080: public void setName(String serviceUnitName) {
081: this .name = serviceUnitName;
082: }
083:
084: /**
085: * @return the startupTimeAverage
086: */
087: public double getStartupTimeAverage() {
088: return this .startupTimeAverage;
089: }
090:
091: /**
092: * @param startupTimeAverage
093: * the startupTimeAverage to set
094: */
095: public void setStartupTimeAverage(long serviceUnitStartTime) {
096: this .startupTimeAverage = serviceUnitStartTime;
097: }
098:
099: /**
100: * @return the stopTimeAverage
101: */
102: public double getStopTimeAverage() {
103: return this .stopTimeAverage;
104: }
105:
106: /**
107: * @param stopTimeAverage
108: * the stopTimeAverage to set
109: */
110: public void setStopTimeAverage(long serviceUnitStopTime) {
111: this .stopTimeAverage = serviceUnitStopTime;
112: }
113:
114: /**
115: * @return the shutdownTimeAverage
116: */
117: public double getShutdownTimeAverage() {
118: return this .shutdownTimeAverage;
119: }
120:
121: /**
122: * @param shutdownTimeAverage
123: * the shutdownTimeAverage to set
124: */
125: public void setShutdownTimeAverage(long serviceUnitShutdownTime) {
126: this .shutdownTimeAverage = serviceUnitShutdownTime;
127: }
128:
129: /**
130: * @return the endpointNameList
131: */
132: public List<String> getEndpointNameList() {
133: return this .endpointNameList;
134: }
135:
136: /**
137: * @return the endpointNameArray
138: */
139: public String[] getEndpointNameArray() {
140: String[] result = toArray(this .endpointNameList, String.class);
141: return result;
142: }
143:
144: /**
145: * @param endpointNameList
146: * the endpointNameList to set
147: */
148: public void setEndpointNameList(List<String> endpointNameList) {
149: this .endpointNameList = endpointNameList;
150: }
151:
152: /**
153: * @param endpointNameArray
154: * the endpointNameArray to set
155: */
156: public void setEndpointNameList(String[] endpointNameArray) {
157: for (String endpointName : endpointNameArray) {
158: this .endpointNameList.add(endpointName);
159: }
160: }
161:
162: /**
163: * Convert a collection to an array
164: *
165: * @param collection
166: * @param componentType
167: * @return
168: */
169: @SuppressWarnings("unchecked")
170: static protected <Type> Type[] toArray(Collection<Type> collection,
171: Class<Type> componentType) {
172: // unchecked cast
173: Type[] array = (Type[]) java.lang.reflect.Array.newInstance(
174: componentType, collection.size());
175: int index = 0;
176: for (Type value : collection) {
177: array[index++] = value;
178: }
179: return array;
180: }
181:
182: /**
183: *
184: * @return
185: */
186: public String getDisplayString() {
187: StringBuffer buffer = new StringBuffer();
188: buffer.append("\n Service Unit Name" + "=" + this .getName());
189: buffer.append("\n Service Unit Shutdown Time" + "="
190: + this .getShutdownTimeAverage());
191: buffer.append("\n Service Unit Start Time" + "="
192: + this .getStartupTimeAverage());
193: buffer.append("\n Service Unit Stop Time" + "="
194: + this .getStopTimeAverage());
195: if ((this .getEndpointNameList() != null)
196: && (this .getEndpointNameList().size() > 0)) {
197: buffer.append("\n Endpoints List:");
198: for (String endpoint : this .getEndpointNameList()) {
199: buffer.append("\n Endpoint Name" + "=" + endpoint);
200: }
201: }
202: buffer.append("\n\n");
203: return buffer.toString();
204:
205: }
206:
207: /**
208: * @param args
209: */
210: public static void main(String[] args) {
211: // TODO Auto-generated method stub
212:
213: }
214:
215: }
|