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: * Base class for all Commands, i.e. wire protocol messages that can be sent by both client and
049: * server at any moment. Some Commands contain nothing but their type, and therefore instances of
050: * this Command class can be used to transfer them. Others contain additional information, and
051: * therefore specialized subclasses of Command are used for them.
052: *
053: * @author Misha Dmitriev
054: */
055: public class Command {
056: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
057:
058: public static final int CHECK_CONNECTION = 1;
059: public static final int START_TARGET_APP = 2;
060: public static final int CLASS_LOADED = 3;
061: public static final int SET_CHANGEABLE_INSTR_PARAMS = 4;
062: public static final int SET_UNCHANGEABLE_INSTR_PARAMS = 5;
063: public static final int CPU_RESULTS_EXIST = 6;
064: public static final int INSTRUMENT_METHOD_GROUP = 7;
065: public static final int GET_CODE_REGION_CPU_RESULTS = 8;
066: public static final int DEACTIVATE_INJECTED_CODE = 9;
067: public static final int SUSPEND_TARGET_APP = 10;
068: public static final int RESUME_TARGET_APP = 11;
069: public static final int TERMINATE_TARGET_JVM = 12;
070: public static final int INITIATE_INSTRUMENTATION = 13;
071: public static final int MESSAGE = 14;
072: public static final int SHUTDOWN_OK = 15; // profiled VM can proceed with shutdown
073: public static final int GET_THREAD_LIVENESS_STATUS = 16;
074: public static final int ROOT_CLASS_LOADED = 17;
075: public static final int SHUTDOWN_INITIATED = 18; // profiled VM shutdown initiated
076: public static final int SHUTDOWN_COMPLETED = 19; // profiled VM shutdown completed, clean up
077: public static final int INSTRUMENT_REFLECTION = 20;
078: public static final int DEINSTRUMENT_REFLECTION = 21;
079: public static final int METHOD_LOADED = 22;
080: public static final int METHOD_INVOKED_FIRST_TIME = 23;
081: public static final int GET_INTERNAL_STATS = 24;
082: public static final int DETACH = 25;
083: public static final int EVENT_BUFFER_DUMPED = 26;
084: public static final int DUMP_EXISTING_RESULTS = 27;
085: public static final int GET_VM_PROPERTIES = 28;
086: public static final int RESET_PROFILER_COLLECTORS = 29;
087: public static final int GET_OBJECT_ALLOCATION_RESULTS = 30;
088: public static final int GET_METHOD_NAMES_FOR_JMETHOD_IDS = 31;
089: public static final int GET_MONITORED_NUMBERS = 32;
090: public static final int RUN_GC = 33;
091: public static final int RUN_CALIBRATION_AND_GET_DATA = 34;
092: public static final int GET_DEFINING_CLASS_LOADER = 35;
093: public static final int CLASS_LOADER_UNLOADING = 36;
094: public static final int GET_STORED_CALIBRATION_DATA = 37;
095: public static final int RESULTS_AVAILABLE = 38;
096: public static final int TAKE_SNAPSHOT = 39;
097: public static final int DUMP_EXISTING_RESULTS_LIVE = 40;
098: public static final int TAKE_HEAP_DUMP = 41;
099: public static final int GET_CLASSID = 42;
100: public static final int STILL_ALIVE = 43;
101:
102: //~ Instance fields ----------------------------------------------------------------------------------------------------------
103:
104: private int type; // One of the above constants determining the Command type.
105:
106: //~ Constructors -------------------------------------------------------------------------------------------------------------
107:
108: public Command(int type) {
109: this .type = type;
110: }
111:
112: // Custom serialization support
113: Command() {
114: }
115:
116: //~ Methods ------------------------------------------------------------------------------------------------------------------
117:
118: public int getType() {
119: return type;
120: }
121:
122: public static String cmdTypeToString(int type) {
123: switch (type) {
124: case CHECK_CONNECTION:
125: return "CHECK_CONNECTION"; // NOI18N
126: case START_TARGET_APP:
127: return "START_TARGET_APP"; // NOI18N
128: case CLASS_LOADED:
129: return "CLASS_LOADED"; // NOI18N
130: case SET_CHANGEABLE_INSTR_PARAMS:
131: return "SET_CHANGEABLE_INSTR_PARAMS"; // NOI18N
132: case SET_UNCHANGEABLE_INSTR_PARAMS:
133: return "SET_UNCHANGEABLE_INSTR_PARAMS"; // NOI18N
134: case CPU_RESULTS_EXIST:
135: return "CPU_RESULTS_EXIST"; // NOI18N
136: case INSTRUMENT_METHOD_GROUP:
137: return "INSTRUMENT_METHOD_GROUP"; // NOI18N
138: case GET_CODE_REGION_CPU_RESULTS:
139: return "GET_CODE_REGION_CPU_RESULTS"; // NOI18N
140: case DEACTIVATE_INJECTED_CODE:
141: return "DEACTIVATE_INJECTED_CODE"; // NOI18N
142: case SUSPEND_TARGET_APP:
143: return "SUSPEND_TARGET_APP"; // NOI18N
144: case RESUME_TARGET_APP:
145: return "RESUME_TARGET_APP"; // NOI18N
146: case TERMINATE_TARGET_JVM:
147: return "TERMINATE_TARGET_JVM"; // NOI18N
148: case INITIATE_INSTRUMENTATION:
149: return "INITIATE_INSTRUMENTATION"; // NOI18N
150: case MESSAGE:
151: return "MESSAGE"; // NOI18N
152: case SHUTDOWN_OK:
153: return "SHUTDOWN_OK"; // NOI18N
154: case GET_THREAD_LIVENESS_STATUS:
155: return "GET_THREAD_LIVENESS_STATUS"; // NOI18N
156: case ROOT_CLASS_LOADED:
157: return "ROOT_CLASS_LOADED"; // NOI18N
158: case SHUTDOWN_INITIATED:
159: return "SHUTDOWN_INITIATED"; // NOI18N
160: case SHUTDOWN_COMPLETED:
161: return "SHUTDOWN_COMPLETED"; // NOI18N
162: case INSTRUMENT_REFLECTION:
163: return "INSTRUMENT_REFLECTION"; // NOI18N
164: case DEINSTRUMENT_REFLECTION:
165: return "DEINSTRUMENT_REFLECTION"; // NOI18N
166: case METHOD_LOADED:
167: return "METHOD_LOADED"; // NOI18N
168: case METHOD_INVOKED_FIRST_TIME:
169: return "METHOD_INVOKED_FIRST_TIME"; // NOI18N
170: case GET_INTERNAL_STATS:
171: return "GET_INTERNAL_STATS"; // NOI18N
172: case DETACH:
173: return "DETACH"; // NOI18N
174: case EVENT_BUFFER_DUMPED:
175: return "EVENT_BUFFER_DUMPED"; // NOI18N
176: case DUMP_EXISTING_RESULTS:
177: return "DUMP_EXISTING_RESULTS"; // NOI18N
178: case GET_VM_PROPERTIES:
179: return "GET_VM_PROPERTIES"; // NOI18N
180: case RESET_PROFILER_COLLECTORS:
181: return "RESET_PROFILER_COLLECTORS"; // NOI18N
182: case GET_OBJECT_ALLOCATION_RESULTS:
183: return "GET_OBJECT_ALLOCATION_RESULTS"; // NOI18N
184: case GET_METHOD_NAMES_FOR_JMETHOD_IDS:
185: return "GET_METHOD_NAMES_FOR_JMETHOD_IDS"; // NOI18N
186: case GET_MONITORED_NUMBERS:
187: return "MONITORED_NUMBERS"; // NOI18N
188: case RUN_GC:
189: return "RUN_GC"; // NOI18N
190: case RUN_CALIBRATION_AND_GET_DATA:
191: return "RUN_CALIBRATION_AND_GET_DATA"; // NOI18N
192: case GET_DEFINING_CLASS_LOADER:
193: return "GET_DEFINING_CLASSLOADER"; // NOI18N
194: case CLASS_LOADER_UNLOADING:
195: return "CLASS_LOADER_UNLOADING"; // NOI18N
196: case GET_STORED_CALIBRATION_DATA:
197: return "GET_STORED_CALIBRATION_DATA"; // NOI18N
198: case RESULTS_AVAILABLE:
199: return "RESULTS_AVAILABLE"; // NOI18N
200: case TAKE_SNAPSHOT:
201: return "TAKE_SNAPSHOT"; // NOI18N
202: case DUMP_EXISTING_RESULTS_LIVE:
203: return "DUMP_EXISTING_RESULTS_LIVE"; // NOI18N
204: case TAKE_HEAP_DUMP:
205: return "TAKE_HEAP_DUMP"; // NOI18N
206: case GET_CLASSID:
207: return "GET_CLASSID"; // NOI18N
208: case STILL_ALIVE:
209: return "STILL_ALIVE"; // NOI18N
210: }
211:
212: return "Unknown command"; // NOI18N
213: }
214:
215: // For debugging
216: public String toString() {
217: return cmdTypeToString(type);
218: }
219:
220: void setType(int type) {
221: this .type = type;
222: }
223:
224: void readObject(ObjectInputStream in) throws IOException {
225: }
226:
227: void writeObject(ObjectOutputStream out) throws IOException {
228: }
229: }
|