001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.lib.profiler.wireprotocol;
042:
043: import java.io.IOException;
044: import java.io.ObjectInputStream;
045: import java.io.ObjectOutputStream;
046: import java.util.Arrays;
047:
048: /**
049: * This Response, issued by the back end, contains the current information about free and total memory available
050: * for the target application.
051: *
052: * @author Tomas Hurka
053: * @author Misha Dmitriev
054: * @author Ian Formanek
055: */
056: public class MonitoredNumbersResponse extends Response {
057: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
058:
059: public static final int FREE_MEMORY_IDX = 0;
060: public static final int TOTAL_MEMORY_IDX = 1;
061: public static final int USER_THREADS_IDX = 2;
062: public static final int SYSTEM_THREADS_IDX = 3;
063: public static final int SURVIVING_GENERATIONS_IDX = 4;
064: public static final int GC_TIME_IDX = 5;
065: public static final int GC_PAUSE_IDX = 6;
066: public static final int LOADED_CLASSES_IDX = 7;
067: public static final int TIMESTAMP_IDX = 8;
068: public static final int GENERAL_NUMBERS_SIZE = 9;
069:
070: //~ Instance fields ----------------------------------------------------------------------------------------------------------
071:
072: private long[] gcFinishs;
073: private long[] gcStarts;
074: private long[] generalNumbers = new long[GENERAL_NUMBERS_SIZE];
075: private String[] newThreadClassNames;
076: private int[] newThreadIds;
077: private String[] newThreadNames;
078: private long[] stateTimestamps = new long[10];
079: private int[] threadIds = new int[10];
080: private byte[] threadStates = new byte[100];
081: private int nNewThreads;
082: private int nThreadStates;
083: private int nThreads;
084:
085: //~ Constructors -------------------------------------------------------------------------------------------------------------
086:
087: public MonitoredNumbersResponse(long[] generalNumbers) {
088: super (true, MONITORED_NUMBERS);
089: this .generalNumbers = generalNumbers;
090: this .nNewThreads = 0;
091: }
092:
093: // Custom serialization support
094: MonitoredNumbersResponse() {
095: super (true, MONITORED_NUMBERS);
096: }
097:
098: //~ Methods ------------------------------------------------------------------------------------------------------------------
099:
100: public void setDataOnNewThreads(int nNewThreads,
101: int[] newThreadIds, String[] newThreadNames,
102: String[] newThreadClassNames) {
103: this .nNewThreads = nNewThreads;
104: this .newThreadIds = newThreadIds;
105: this .newThreadNames = newThreadNames;
106: this .newThreadClassNames = newThreadClassNames;
107: }
108:
109: public void setDataOnThreads(int nThreads, int nThreadStates,
110: int[] threadIds, long[] stateTimestamps, byte[] threadStates) {
111: this .nThreads = nThreads;
112: this .nThreadStates = nThreadStates;
113: this .threadIds = threadIds;
114: this .stateTimestamps = stateTimestamps;
115: this .threadStates = threadStates;
116: }
117:
118: public long[] getGCFinishs() {
119: return gcFinishs;
120: }
121:
122: public long[] getGCStarts() {
123: return gcStarts;
124: }
125:
126: public void setGCstartFinishData(long[] start, long[] finish) {
127: gcStarts = start;
128: gcFinishs = finish;
129: }
130:
131: public long[] getGeneralMonitoredNumbers() {
132: return generalNumbers;
133: }
134:
135: public int getNNewThreads() {
136: return nNewThreads;
137: }
138:
139: public int getNThreadStates() {
140: return nThreadStates;
141: }
142:
143: public int getNThreads() {
144: return nThreads;
145: }
146:
147: public String[] getNewThreadClassNames() {
148: return newThreadClassNames;
149: }
150:
151: public int[] getNewThreadIds() {
152: return newThreadIds;
153: }
154:
155: public String[] getNewThreadNames() {
156: return newThreadNames;
157: }
158:
159: public long[] getStateTimestamps() {
160: return stateTimestamps;
161: }
162:
163: public int[] getThreadIds() {
164: return threadIds;
165: }
166:
167: public byte[] getThreadStates() {
168: return threadStates;
169: }
170:
171: // For debugging
172: public String toString() {
173: return "MonitoredNumbersResponse, " + super .toString(); // NOI18N
174: }
175:
176: void readObject(ObjectInputStream in) throws IOException {
177: int arrSize;
178:
179: for (int i = 0; i < generalNumbers.length; i++) {
180: generalNumbers[i] = in.readLong();
181: }
182:
183: nThreads = in.readInt();
184: nThreadStates = in.readInt();
185:
186: if (threadIds.length < nThreads) {
187: threadIds = new int[nThreads];
188: }
189:
190: if (stateTimestamps.length < nThreadStates) {
191: stateTimestamps = new long[nThreadStates];
192: }
193:
194: int len = nThreads * nThreadStates;
195:
196: if (threadStates.length < len) {
197: threadStates = new byte[len];
198: }
199:
200: for (int i = 0; i < nThreads; i++) {
201: threadIds[i] = in.readInt();
202: }
203:
204: for (int i = 0; i < nThreadStates; i++) {
205: stateTimestamps[i] = in.readLong();
206: }
207:
208: in.readFully(threadStates, 0, len);
209:
210: nNewThreads = in.readInt();
211:
212: if (nNewThreads > 0) {
213: if ((newThreadIds == null)
214: || (newThreadIds.length < nNewThreads)) {
215: newThreadIds = new int[nNewThreads];
216: newThreadNames = new String[nNewThreads];
217: newThreadClassNames = new String[nNewThreads];
218: }
219:
220: for (int i = 0; i < nNewThreads; i++) {
221: newThreadIds[i] = in.readInt();
222: newThreadNames[i] = in.readUTF();
223: newThreadClassNames[i] = in.readUTF();
224: }
225: }
226:
227: arrSize = in.readInt();
228: gcStarts = new long[arrSize];
229:
230: for (int i = 0; i < arrSize; i++) {
231: gcStarts[i] = in.readLong();
232: }
233:
234: arrSize = in.readInt();
235: gcFinishs = new long[arrSize];
236:
237: for (int i = 0; i < arrSize; i++) {
238: gcFinishs[i] = in.readLong();
239: }
240:
241: Arrays.sort(gcStarts);
242: Arrays.sort(gcFinishs);
243: }
244:
245: void writeObject(ObjectOutputStream out) throws IOException {
246: for (int i = 0; i < generalNumbers.length; i++) {
247: out.writeLong(generalNumbers[i]);
248: }
249:
250: out.writeInt(nThreads);
251: out.writeInt(nThreadStates);
252:
253: for (int i = 0; i < nThreads; i++) {
254: out.writeInt(threadIds[i]);
255: }
256:
257: for (int i = 0; i < nThreadStates; i++) {
258: out.writeLong(stateTimestamps[i]);
259: }
260:
261: int len = nThreads * nThreadStates;
262: out.write(threadStates, 0, len);
263:
264: if (nNewThreads == 0) {
265: out.writeInt(0);
266: } else {
267: out.writeInt(nNewThreads);
268:
269: for (int i = 0; i < nNewThreads; i++) {
270: out.writeInt(newThreadIds[i]);
271: out.writeUTF(newThreadNames[i]);
272: out.writeUTF(newThreadClassNames[i]);
273: }
274: }
275:
276: out.writeInt(gcStarts.length);
277:
278: for (int i = 0; i < gcStarts.length; i++) {
279: out.writeLong(gcStarts[i]);
280: }
281:
282: out.writeInt(gcFinishs.length);
283:
284: for (int i = 0; i < gcFinishs.length; i++) {
285: out.writeLong(gcFinishs[i]);
286: }
287: }
288: }
|