38 |
package gnu.java.rmi.server; |
package gnu.java.rmi.server; |
39 |
|
|
40 |
import java.lang.Exception; |
import java.lang.Exception; |
41 |
|
import java.io.DataInputStream; |
42 |
|
import java.io.DataOutputStream; |
43 |
import java.io.IOException; |
import java.io.IOException; |
44 |
import java.io.ObjectOutput; |
import java.io.ObjectOutput; |
45 |
import java.io.ObjectInput; |
import java.io.ObjectInput; |
46 |
import java.io.StreamCorruptedException; |
import java.io.StreamCorruptedException; |
47 |
import java.rmi.server.RemoteCall; |
import java.rmi.server.RemoteCall; |
48 |
|
import java.rmi.RemoteException; |
49 |
|
import java.rmi.MarshalException; |
50 |
|
import java.rmi.UnmarshalException; |
51 |
|
import java.rmi.server.UID; |
52 |
|
import java.rmi.server.ObjID; |
53 |
|
import java.rmi.server.RemoteObject; |
54 |
|
|
55 |
import java.util.Vector; |
import java.util.Vector; |
56 |
|
|
57 |
public class UnicastRemoteCall implements RemoteCall |
public class UnicastRemoteCall |
58 |
{ |
implements RemoteCall, ProtocolConstants { |
59 |
|
|
60 |
private UnicastConnection conn; |
private UnicastConnection conn; |
61 |
private Object result; |
private Object result; |
65 |
private Vector vec; |
private Vector vec; |
66 |
private int ptr; |
private int ptr; |
67 |
|
|
68 |
|
private ObjectOutput oout; |
69 |
|
private ObjectInput oin; |
70 |
|
|
71 |
/** |
/** |
72 |
* Incoming call. |
* Incoming call. |
73 |
*/ |
*/ |
74 |
UnicastRemoteCall(UnicastConnection conn) |
UnicastRemoteCall(UnicastConnection conn) { |
|
{ |
|
75 |
this.conn = conn; |
this.conn = conn; |
76 |
} |
} |
77 |
|
|
78 |
/** |
/** |
79 |
* Outgoing call. |
* Outgoing call. |
80 |
*/ |
*/ |
81 |
UnicastRemoteCall(Object obj, int opnum, long hash) |
/* |
82 |
{ |
UnicastRemoteCall(Object obj, int opnum, long hash) { |
83 |
this.object = obj; |
this.object = obj; |
84 |
this.opnum = opnum; |
this.opnum = opnum; |
85 |
this.hash = hash; |
this.hash = hash; |
86 |
} |
} |
87 |
|
*/ |
88 |
|
|
89 |
public ObjectOutput getOutputStream() throws IOException |
UnicastRemoteCall(UnicastConnection conn, ObjID objid, int opnum, long hash) throws RemoteException |
90 |
{ |
{ |
91 |
|
this.conn = conn; |
92 |
|
this.opnum = opnum; |
93 |
|
this.hash = hash; |
94 |
|
|
95 |
|
// signal the call when constructing |
96 |
|
try{ |
97 |
|
DataOutputStream dout = conn.getDataOutputStream(); |
98 |
|
dout.write(MESSAGE_CALL); |
99 |
|
|
100 |
|
oout = conn.getObjectOutputStream(); |
101 |
|
objid.write(oout); |
102 |
|
oout.writeInt(opnum); |
103 |
|
oout.writeLong(hash); |
104 |
|
}catch(IOException ex){ |
105 |
|
throw new MarshalException("Try to write header but failed.", ex); |
106 |
|
} |
107 |
|
} |
108 |
|
|
109 |
|
UnicastConnection getConnection(){ |
110 |
|
return conn; |
111 |
|
} |
112 |
|
|
113 |
|
public ObjectOutput getOutputStream() throws IOException { |
114 |
|
if (conn != null) { |
115 |
|
if(oout == null) |
116 |
|
return (oout = conn.getObjectOutputStream()); |
117 |
|
else |
118 |
|
return oout; |
119 |
|
}else{ |
120 |
vec = new Vector(); |
vec = new Vector(); |
121 |
return new DummyObjectOutputStream(); |
return (new DummyObjectOutputStream()); |
122 |
|
} |
123 |
} |
} |
124 |
|
|
125 |
public void releaseOutputStream() throws IOException |
public void releaseOutputStream() throws IOException { |
126 |
{ |
if(oout != null) |
127 |
// Does nothing. |
oout.flush(); |
128 |
} |
} |
129 |
|
|
130 |
public ObjectInput getInputStream() throws IOException |
public ObjectInput getInputStream() throws IOException { |
131 |
{ |
if (conn != null) { |
132 |
if (conn != null) |
if(oin == null) |
133 |
return conn.getObjectInputStream(); |
return (oin = conn.getObjectInputStream()); |
134 |
|
else |
135 |
|
return oin; |
136 |
|
} |
137 |
|
else { |
138 |
ptr = 0; |
ptr = 0; |
139 |
return new DummyObjectInputStream(); |
return (new DummyObjectInputStream()); |
140 |
|
} |
141 |
} |
} |
142 |
|
|
143 |
public void releaseInputStream() throws IOException |
public void releaseInputStream() throws IOException { |
|
{ |
|
144 |
// Does nothing. |
// Does nothing. |
145 |
} |
} |
146 |
|
|
147 |
public ObjectOutput getResultStream(boolean success) |
public ObjectOutput getResultStream(boolean success) throws IOException, StreamCorruptedException { |
|
throws IOException, StreamCorruptedException |
|
|
{ |
|
148 |
vec = new Vector(); |
vec = new Vector(); |
149 |
return new DummyObjectOutputStream(); |
return (new DummyObjectOutputStream()); |
150 |
} |
} |
151 |
|
|
152 |
public void executeCall() throws Exception |
public void executeCall() throws Exception { |
153 |
{ |
byte returncode; |
154 |
throw new Error("Not implemented"); |
ObjectInput oin; |
155 |
|
try{ |
156 |
|
releaseOutputStream(); |
157 |
|
DataInputStream din = conn.getDataInputStream(); |
158 |
|
if (din.readByte() != MESSAGE_CALL_ACK) { |
159 |
|
throw new RemoteException("Call not acked"); |
160 |
|
} |
161 |
|
oin = getInputStream(); |
162 |
|
returncode = oin.readByte(); |
163 |
|
UID.read(oin); |
164 |
|
}catch(IOException ex){ |
165 |
|
throw new UnmarshalException("Try to read header but failed:", ex); |
166 |
} |
} |
167 |
|
|
168 |
public void done() throws IOException |
//check return code |
169 |
{ |
switch(returncode){ |
170 |
/* Does nothing */ |
case RETURN_ACK: //it's ok |
171 |
|
return; |
172 |
|
case RETURN_NACK:{ |
173 |
|
Object returnobj; |
174 |
|
try{ |
175 |
|
returnobj = oin.readObject(); |
176 |
|
} |
177 |
|
catch(Exception ex2){ |
178 |
|
throw new UnmarshalException("Try to read exception object but failed", ex2); |
179 |
|
} |
180 |
|
if(!(returnobj instanceof Exception)) |
181 |
|
throw new UnmarshalException("Should be Exception type here"); |
182 |
|
throw (Exception)returnobj; |
183 |
|
} |
184 |
|
default: |
185 |
|
throw new UnmarshalException("Invalid return code"); |
186 |
|
} |
187 |
} |
} |
188 |
|
|
189 |
Object returnValue() |
public void done() throws IOException { |
190 |
{ |
// conn.disconnect(); |
|
return vec.elementAt(0); |
|
191 |
} |
} |
192 |
|
|
193 |
Object[] getArguments() |
Object returnValue() { |
194 |
{ |
return (vec.elementAt(0)); |
|
return vec.toArray(); |
|
195 |
} |
} |
196 |
|
|
197 |
Object getObject() |
Object[] getArguments() { |
198 |
{ |
return (vec.toArray()); |
|
return object; |
|
199 |
} |
} |
200 |
|
|
201 |
int getOpnum() |
Object getObject() { |
202 |
{ |
return (object); |
|
return opnum; |
|
203 |
} |
} |
204 |
|
|
205 |
long getHash() |
int getOpnum() { |
206 |
{ |
return (opnum); |
|
return hash; |
|
207 |
} |
} |
208 |
|
|
209 |
void setReturnValue(Object obj) |
long getHash() { |
210 |
{ |
return (hash); |
211 |
|
} |
212 |
|
|
213 |
|
void setReturnValue(Object obj) { |
214 |
vec.removeAllElements(); |
vec.removeAllElements(); |
215 |
vec.addElement(obj); |
vec.addElement(obj); |
216 |
} |
} |
218 |
/** |
/** |
219 |
* Dummy object output class. |
* Dummy object output class. |
220 |
*/ |
*/ |
221 |
private class DummyObjectOutputStream implements ObjectOutput |
private class DummyObjectOutputStream implements ObjectOutput { |
|
{ |
|
|
/** |
|
|
* Non-private constructor to reduce bytecode emitted. |
|
|
*/ |
|
|
DummyObjectOutputStream() |
|
|
{ |
|
|
} |
|
222 |
|
|
223 |
public void writeBoolean(boolean v) throws IOException |
public void writeBoolean(boolean v) throws IOException { |
|
{ |
|
224 |
vec.addElement(new Boolean(v)); |
vec.addElement(new Boolean(v)); |
225 |
} |
} |
226 |
|
|
227 |
public void writeByte(int v) throws IOException |
public void writeByte(int v) throws IOException { |
|
{ |
|
228 |
vec.addElement(new Byte((byte) v)); |
vec.addElement(new Byte((byte) v)); |
229 |
} |
} |
230 |
|
|
231 |
public void writeChar(int v) throws IOException |
public void writeChar(int v) throws IOException { |
|
{ |
|
232 |
vec.addElement(new Character((char) v)); |
vec.addElement(new Character((char) v)); |
233 |
} |
} |
234 |
|
|
235 |
public void writeDouble(double v) throws IOException |
public void writeDouble(double v) throws IOException { |
|
{ |
|
236 |
vec.addElement(new Double(v)); |
vec.addElement(new Double(v)); |
237 |
} |
} |
238 |
|
|
239 |
public void writeFloat(float v) throws IOException |
public void writeFloat(float v) throws IOException { |
|
{ |
|
240 |
vec.addElement(new Float(v)); |
vec.addElement(new Float(v)); |
241 |
} |
} |
242 |
|
|
243 |
public void writeInt(int v) throws IOException |
public void writeInt(int v) throws IOException { |
|
{ |
|
244 |
vec.addElement(new Integer(v)); |
vec.addElement(new Integer(v)); |
245 |
} |
} |
246 |
|
|
247 |
public void writeLong(long v) throws IOException |
public void writeLong(long v) throws IOException { |
|
{ |
|
248 |
vec.addElement(new Long(v)); |
vec.addElement(new Long(v)); |
249 |
} |
} |
250 |
|
|
251 |
public void writeShort(int v) throws IOException |
public void writeShort(int v) throws IOException { |
|
{ |
|
252 |
vec.addElement(new Short((short) v)); |
vec.addElement(new Short((short) v)); |
253 |
} |
} |
254 |
|
|
255 |
public void writeObject(Object obj) throws IOException |
public void writeObject(Object obj) throws IOException { |
|
{ |
|
256 |
vec.addElement(obj); |
vec.addElement(obj); |
257 |
} |
} |
258 |
|
|
259 |
public void write(byte b[]) throws IOException |
public void write(byte b[]) throws IOException { |
|
{ |
|
260 |
throw new IOException("not required"); |
throw new IOException("not required"); |
261 |
} |
} |
262 |
|
|
263 |
public void write(byte b[], int off, int len) throws IOException |
public void write(byte b[], int off, int len) throws IOException { |
|
{ |
|
264 |
throw new IOException("not required"); |
throw new IOException("not required"); |
265 |
} |
} |
266 |
|
|
267 |
public void write(int b) throws IOException |
public void write(int b) throws IOException { |
|
{ |
|
268 |
throw new IOException("not required"); |
throw new IOException("not required"); |
269 |
} |
} |
270 |
|
|
271 |
public void writeBytes(String s) throws IOException |
public void writeBytes(String s) throws IOException { |
|
{ |
|
272 |
throw new IOException("not required"); |
throw new IOException("not required"); |
273 |
} |
} |
274 |
|
|
275 |
public void writeChars(String s) throws IOException |
public void writeChars(String s) throws IOException { |
|
{ |
|
276 |
throw new IOException("not required"); |
throw new IOException("not required"); |
277 |
} |
} |
278 |
|
|
279 |
public void writeUTF(String str) throws IOException |
public void writeUTF(String str) throws IOException { |
|
{ |
|
280 |
throw new IOException("not required"); |
throw new IOException("not required"); |
281 |
} |
} |
282 |
|
|
283 |
public void flush() throws IOException |
public void flush() throws IOException { |
284 |
{ |
} |
285 |
|
|
286 |
|
public void close() throws IOException { |
287 |
} |
} |
288 |
|
|
|
public void close() throws IOException |
|
|
{ |
|
289 |
} |
} |
|
} // class DummyObjectOutputStream |
|
290 |
|
|
291 |
/** |
/** |
292 |
* Dummy object input class. |
* Dummy object input class. |
293 |
*/ |
*/ |
294 |
private class DummyObjectInputStream implements ObjectInput |
private class DummyObjectInputStream implements ObjectInput { |
|
{ |
|
|
/** |
|
|
* Non-private constructor to reduce bytecode emitted. |
|
|
*/ |
|
|
DummyObjectInputStream() |
|
|
{ |
|
|
} |
|
295 |
|
|
296 |
public boolean readBoolean() throws IOException |
public boolean readBoolean() throws IOException { |
|
{ |
|
297 |
Object obj = vec.elementAt(ptr++); |
Object obj = vec.elementAt(ptr++); |
298 |
return ((Boolean) obj).booleanValue(); |
return (((Boolean)obj).booleanValue()); |
299 |
} |
} |
300 |
|
|
301 |
public byte readByte() throws IOException |
public byte readByte() throws IOException { |
|
{ |
|
302 |
Object obj = vec.elementAt(ptr++); |
Object obj = vec.elementAt(ptr++); |
303 |
return ((Byte) obj).byteValue(); |
return (((Byte)obj).byteValue()); |
304 |
} |
} |
305 |
|
|
306 |
public char readChar() throws IOException |
public char readChar() throws IOException { |
|
{ |
|
307 |
Object obj = vec.elementAt(ptr++); |
Object obj = vec.elementAt(ptr++); |
308 |
return ((Character) obj).charValue(); |
return (((Character)obj).charValue()); |
309 |
} |
} |
310 |
|
|
311 |
public double readDouble() throws IOException |
public double readDouble() throws IOException { |
|
{ |
|
312 |
Object obj = vec.elementAt(ptr++); |
Object obj = vec.elementAt(ptr++); |
313 |
return ((Double) obj).doubleValue(); |
return (((Double)obj).doubleValue()); |
314 |
} |
} |
315 |
|
|
316 |
public float readFloat() throws IOException |
public float readFloat() throws IOException { |
|
{ |
|
317 |
Object obj = vec.elementAt(ptr++); |
Object obj = vec.elementAt(ptr++); |
318 |
return ((Float) obj).floatValue(); |
return (((Float)obj).floatValue()); |
319 |
} |
} |
320 |
|
|
321 |
public int readInt() throws IOException |
public int readInt() throws IOException { |
|
{ |
|
322 |
Object obj = vec.elementAt(ptr++); |
Object obj = vec.elementAt(ptr++); |
323 |
return ((Integer) obj).intValue(); |
return (((Integer)obj).intValue()); |
324 |
} |
} |
325 |
|
|
326 |
public long readLong() throws IOException |
public long readLong() throws IOException { |
|
{ |
|
327 |
Object obj = vec.elementAt(ptr++); |
Object obj = vec.elementAt(ptr++); |
328 |
return ((Long) obj).longValue(); |
return (((Long)obj).longValue()); |
329 |
} |
} |
330 |
|
|
331 |
public short readShort() throws IOException |
public short readShort() throws IOException { |
|
{ |
|
332 |
Object obj = vec.elementAt(ptr++); |
Object obj = vec.elementAt(ptr++); |
333 |
return ((Short) obj).shortValue(); |
return (((Short)obj).shortValue()); |
334 |
} |
} |
335 |
|
|
336 |
public Object readObject() throws IOException |
public Object readObject() throws IOException { |
337 |
{ |
return (vec.elementAt(ptr++)); |
|
return vec.elementAt(ptr++); |
|
338 |
} |
} |
339 |
|
|
340 |
public int read(byte b[]) throws IOException |
public int read(byte b[]) throws IOException { |
|
{ |
|
341 |
throw new IOException("not required"); |
throw new IOException("not required"); |
342 |
} |
} |
343 |
|
|
344 |
public int read(byte b[], int off, int len) throws IOException |
public int read(byte b[], int off, int len) throws IOException { |
|
{ |
|
345 |
throw new IOException("not required"); |
throw new IOException("not required"); |
346 |
} |
} |
347 |
|
|
348 |
public int read() throws IOException |
public int read() throws IOException { |
|
{ |
|
349 |
throw new IOException("not required"); |
throw new IOException("not required"); |
350 |
} |
} |
351 |
|
|
352 |
public long skip(long n) throws IOException |
public long skip(long n) throws IOException { |
|
{ |
|
353 |
throw new IOException("not required"); |
throw new IOException("not required"); |
354 |
} |
} |
355 |
|
|
356 |
public int available() throws IOException |
public int available() throws IOException { |
|
{ |
|
357 |
throw new IOException("not required"); |
throw new IOException("not required"); |
358 |
} |
} |
359 |
|
|
360 |
public void readFully(byte b[]) throws IOException |
public void readFully(byte b[]) throws IOException { |
|
{ |
|
361 |
throw new IOException("not required"); |
throw new IOException("not required"); |
362 |
} |
} |
363 |
|
|
364 |
public void readFully(byte b[], int off, int len) throws IOException |
public void readFully(byte b[], int off, int len) throws IOException { |
|
{ |
|
365 |
throw new IOException("not required"); |
throw new IOException("not required"); |
366 |
} |
} |
367 |
|
|
368 |
public String readLine() throws IOException |
public String readLine() throws IOException { |
|
{ |
|
369 |
throw new IOException("not required"); |
throw new IOException("not required"); |
370 |
} |
} |
371 |
|
|
372 |
public String readUTF() throws IOException |
public String readUTF() throws IOException { |
|
{ |
|
373 |
throw new IOException("not required"); |
throw new IOException("not required"); |
374 |
} |
} |
375 |
|
|
376 |
public int readUnsignedByte() throws IOException |
public int readUnsignedByte() throws IOException { |
|
{ |
|
377 |
throw new IOException("not required"); |
throw new IOException("not required"); |
378 |
} |
} |
379 |
|
|
380 |
public int readUnsignedShort() throws IOException |
public int readUnsignedShort() throws IOException { |
|
{ |
|
381 |
throw new IOException("not required"); |
throw new IOException("not required"); |
382 |
} |
} |
383 |
|
|
384 |
public int skipBytes(int n) throws IOException |
public int skipBytes(int n) throws IOException { |
|
{ |
|
385 |
throw new IOException("not required"); |
throw new IOException("not required"); |
386 |
} |
} |
387 |
|
|
388 |
public void close() throws IOException |
public void close() throws IOException { |
389 |
{ |
} |
390 |
|
|
391 |
} |
} |
|
} // class DummyObjectInputStream |
|
392 |
|
|
393 |
} |
} |