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:
047: /**
048: * Instances of this class are sent back by both client and back end (server) in response to some Commands.
049: * An instance of the base Response class is used to signal just success or failure (with possible additional
050: * error message). Instances of its subclasses are used to pass additional information.
051: *
052: * @author Misha Dmitriev
053: */
054: public class Response {
055: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
056:
057: // Each new response class should have its own identifier, listed here.
058: public static final int NO_TYPE = 0;
059: public static final int CODE_REGION_CPU_RESULTS = 1;
060: public static final int INSTRUMENT_METHOD_GROUP = 2;
061: public static final int INTERNAL_STATS = 3;
062: public static final int VM_PROPERTIES = 4;
063: public static final int DUMP_RESULTS = 5;
064: public static final int OBJECT_ALLOCATION_RESULTS = 6;
065: public static final int METHOD_NAMES = 7;
066: public static final int THREAD_LIVENESS_STATUS = 8;
067: public static final int MONITORED_NUMBERS = 9;
068: public static final int DEFINING_LOADER = 10;
069: public static final int CALIBRATION_DATA = 11;
070: public static final int CLASSID_RESPONSE = 12;
071:
072: //~ Instance fields ----------------------------------------------------------------------------------------------------------
073:
074: protected String errorMessage;
075: protected boolean yes;
076: private int type;
077:
078: //~ Constructors -------------------------------------------------------------------------------------------------------------
079:
080: public Response(boolean yes) {
081: type = NO_TYPE;
082: this .yes = yes;
083: }
084:
085: public Response(String errorMessage) {
086: type = NO_TYPE;
087: this .errorMessage = errorMessage;
088: }
089:
090: protected Response(boolean yes, int type) {
091: this .yes = yes;
092: this .type = type;
093: }
094:
095: // Custom serialization support
096: Response() {
097: type = NO_TYPE;
098: }
099:
100: Response(int type) {
101: this .type = type;
102: }
103:
104: //~ Methods ------------------------------------------------------------------------------------------------------------------
105:
106: public String getErrorMessage() {
107: return errorMessage;
108: }
109:
110: public boolean isOK() {
111: return errorMessage == null;
112: }
113:
114: public int getType() {
115: return type;
116: }
117:
118: // For debugging
119: public String toString() {
120: String s = respTypeToString(type);
121:
122: return s
123: + (isOK() ? ("Ok, " + (yes() ? "yes" : "no"))
124: : ("Error, " + errorMessage)); // NOI18N
125: }
126:
127: public boolean yes() {
128: return yes;
129: }
130:
131: void setErrorMessage(String msg) {
132: this .errorMessage = msg;
133: }
134:
135: void setType(int type) {
136: this .type = type;
137: }
138:
139: void setYes(boolean yes) {
140: this .yes = yes;
141: }
142:
143: void readObject(ObjectInputStream in) throws IOException {
144: }
145:
146: static String respTypeToString(int type) {
147: if (type != NO_TYPE) {
148: switch (type) {
149: case CODE_REGION_CPU_RESULTS:
150: return "CODE_REGION_CPU_RESULTS "; // NOI18N
151: case INSTRUMENT_METHOD_GROUP:
152: return "INSTRUMENT_METHOD_GROUP "; // NOI18N
153: case INTERNAL_STATS:
154: return "INTERNAL_STATS"; // NOI18N
155: case VM_PROPERTIES:
156: return "VM_PROPERTIES"; // NOI18N
157: case DUMP_RESULTS:
158: return "DUMP_RESULTS"; // NOI18N
159: case OBJECT_ALLOCATION_RESULTS:
160: return "OBJECT_ALLOCATION_RESULTS"; // NOI18N
161: case METHOD_NAMES:
162: return "METHOD_NAMES"; // NOI18N
163: case THREAD_LIVENESS_STATUS:
164: return "THREAD_LIVENESS_STATUS"; // NOI18N
165: case MONITORED_NUMBERS:
166: return "MONITORED_NUMBERS"; // NOI18N
167: case DEFINING_LOADER:
168: return "DEFINING_LOADER"; // NOI18N
169: case CALIBRATION_DATA:
170: return "CALIBRATION_DATA"; // NOI18N
171: case CLASSID_RESPONSE:
172: return "CLASSID_RESPONSE"; // NOI18N
173: default:
174: return "Unknown response"; // NOI18N
175: }
176: } else {
177: return "NO TYPE"; // NOI18N
178: }
179: }
180:
181: void writeObject(ObjectOutputStream out) throws IOException {
182: }
183: }
|