001: /*
002: * %W% %E%
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.jump.command;
028:
029: import com.sun.jump.common.JUMPIsolate;
030: import com.sun.jump.message.JUMPMessage;
031: import com.sun.jump.message.JUMPMessageReader;
032: import com.sun.jump.message.JUMPOutgoingMessage;
033:
034: /**
035: * <code>JUMPIsolateLifecycleRequest</code> defines all the lifecycle
036: * related requests that originate from the <Code>JUMPIsolate</code>
037: */
038: public class JUMPIsolateLifecycleRequest extends JUMPRequest {
039: private int isolateId;
040: private int appId;
041:
042: /* FIXME: do these state constants belong here, or the lifecycle module? */
043: /**
044: * Newly created isolate in state ISOLATE_STATE_CREATED
045: */
046: public static final int ISOLATE_STATE_CREATED = 1;
047:
048: /**
049: * Initialized isolate in state ISOLATE_STATE_INITIALIZED
050: */
051: public static final int ISOLATE_STATE_INITIALIZED = 2;
052:
053: /**
054: * Isolate running at least one application
055: */
056: public static final int ISOLATE_STATE_RUNNING = 3;
057:
058: /**
059: * Isolate has been destroyed
060: */
061: public static final int ISOLATE_STATE_DESTROYED = 4;
062:
063: /**
064: * Application requesting the executive to pause itself.
065: * <ol>
066: * <li>args[0] - Isolate Id</li>
067: * <li>args[1] - Application Id</li>
068: * </ol>
069: * Asynchronous request. No <code>JUMPResponse</code> required.
070: */
071: public static final String ID_APP_REQUEST_PAUSE = "AppRequestPause";
072:
073: /**
074: * Application requesting the executive to resume itself.
075: * <ol>
076: * <li>args[0] - Isolate Id</li>
077: * <li>args[1] - Application Id</li>
078: * </ol>
079: * Asynchronous request. No <code>JUMPResponse</code> required.
080: */
081: public static final String ID_APP_REQUEST_RESUME = "AppRequestResume";
082:
083: /**
084: * Application indicating that it has paused itself.
085: * <ol>
086: * <li>args[0] - Isolate Id</li>
087: * <li>args[1] - Application Id</li>
088: * </ol>
089: * Asynchronous request. No <code>JUMPResponse</code> required.
090: */
091: public static final String ID_APP_PAUSED = "AppPaused";
092:
093: /**
094: * Application indicating that it has paused itself.
095: * <ol>
096: * <li>args[0] - Isolate Id</li>
097: * <li>args[1] - Application Id</li>
098: * </ol>
099: * Asynchronous request. No <code>JUMPResponse</code> required.
100: */
101: public static final String ID_APP_RESUMED = "AppResumed";
102:
103: /**
104: * Isolate Initialized.
105: * <ol>
106: * <li>args[0] - Isolate Id</li>
107: * </ol>
108: * Asynchronous request. No <code>JUMPResponse</code> required.
109: */
110: public static final String ID_ISOLATE_INITIALIZED = "IsolateInitialized";
111:
112: /**
113: * Death of an Isolate.
114: * <ol>
115: * <li>args[0] - Isolate Id</li>
116: * </ol>
117: * Asynchronous request. No <code>JUMPResponse</code> required.
118: */
119: public static final String ID_ISOLATE_DESTROYED = "IsolateDestroyed";
120:
121: public static final String MESSAGE_TYPE = "mvm/lifecycle";
122:
123: JUMPIsolateLifecycleRequest() {
124: super (MESSAGE_TYPE, null, null);
125: }
126:
127: private JUMPIsolateLifecycleRequest(String id) {
128: super (MESSAGE_TYPE, id, null);
129: }
130:
131: public JUMPIsolateLifecycleRequest(String id, JUMPIsolate isolate,
132: int appId) {
133: this (id);
134: this .isolateId = isolate.getIsolateId();
135: this .appId = appId;
136: }
137:
138: public JUMPIsolateLifecycleRequest(String id, JUMPIsolate isolate) {
139: this (id, isolate, -1);
140: }
141:
142: public int getIsolateId() {
143: return isolateId;
144: }
145:
146: public int getAppId() {
147: return appId;
148: }
149:
150: /**
151: * For subclasses to use to initialize any fields
152: * using <code>JUMPMessage.get*</code> methods.
153: */
154: protected void deserializeFrom(JUMPMessageReader message) {
155: // First deserialize any shared fields
156: super .deserializeFrom(message);
157: // And now window request specific fields
158: this .isolateId = message.getInt();
159: this .appId = message.getInt();
160: }
161:
162: /**
163: * For subclasses to use to put data in a message
164: * using <code>JUMPOutgoingMessage.add*</code> methods.
165: */
166: protected void serializeInto(JUMPOutgoingMessage message) {
167: super .serializeInto(message);
168: // And now window request specific fields
169: message.addInt(this .isolateId);
170: message.addInt(this .appId);
171: }
172:
173: public static JUMPCommand fromMessage(JUMPMessage message) {
174: return JUMPCommand.fromMessage(message,
175: JUMPIsolateLifecycleRequest.class);
176: }
177:
178: }
|