ObjectOutputStream out; DataOutputStream dout; try { dout = conn.getDataOutputStream(); dout.writeByte(MESSAGE_CALL);  out = conn.startObjectOutputStream();  objid.write(out); out.writeInt(opnum); out.writeLong(hash);   Class clss[] = method.getParameterTypes(); for (int i = 0; i < clss.length; i++) ((RMIObjectOutputStream) out).writeValue(params[i], clss[i]);  out.flush(); } catch (IOException e2) { throw new RemoteException("call failed: ", e2); }  int returncode; Object returnval; DataInputStream din; ObjectInputStream in; UID ack; try { din = conn.getDataInputStream();  if ((returncode = din.readUnsignedByte()) != MESSAGE_CALL_ACK) { conn.disconnect(); throw new RemoteException("Call not acked:" + returncode); }  in = conn.startObjectInputStream(); returncode = in.readUnsignedByte(); ack = UID.read(in);  Class cls = method.getReturnType();  if (returncode == RETURN_NACK) { returnval = in.readObject();  } else if (cls == Void.TYPE) { returnval = null;   } else { returnval = ((RMIObjectInputStream) in).readValue(cls);  } } catch (IOException e3) {  throw new RemoteException("call return failed: ", e3); }    manager.discardConnection(conn);  if (returncode != RETURN_ACK && returnval != null) { if (returncode == RETURN_NACK) throw (Exception) returnval; else throw new RemoteException("unexpected returncode: " + returncode); }  return (returnval);
  private Object invokeCommon(Remote obj, Method method, Object[] params,                              int opnum, long hash) throws Exception  {	UnicastConnection conn;    try      {		conn = manager.getConnection();	}    catch (IOException e1)      {        throw new RemoteException("connection failed to host: "                                  + manager.serverName, e1);	}	ObjectOutputStream out;	DataOutputStream dout;    try      {		dout = conn.getDataOutputStream();		dout.writeByte(MESSAGE_CALL);		out = conn.startObjectOutputStream(); // (re)start ObjectOutputStream				objid.write(out);		out.writeInt(opnum);		out.writeLong(hash);				// must handle primitive class and their wrapper classes		Class clss[] = method.getParameterTypes();        for (int i = 0; i < clss.length; i++)          ((RMIObjectOutputStream) out).writeValue(params[i], clss[i]);		out.flush();	}    catch (IOException e2)      {		throw new RemoteException("call failed: ", e2);	}	int returncode;	Object returnval;	DataInputStream din;	ObjectInputStream in;	UID ack;    try      {		din = conn.getDataInputStream();		        if ((returncode = din.readUnsignedByte()) != MESSAGE_CALL_ACK)          {		    conn.disconnect();			throw new RemoteException("Call not acked:" + returncode);		}		in = conn.startObjectInputStream(); // (re)start ObjectInputStream		returncode = in.readUnsignedByte();		ack = UID.read(in);		Class cls = method.getReturnType();        if (returncode == RETURN_NACK)          {	    returnval = in.readObject();  // get Exception          }        else if (cls == Void.TYPE)          {            returnval = null;            // in.readObject() // not required! returntype 'void' means no field            // is returned.          }        else          {            returnval = ((RMIObjectInputStream) in).readValue(cls); // get                                                                    // returnvalue          }	}    catch (IOException e3)      {        // for debug: e3.printStackTrace();		throw new RemoteException("call return failed: ", e3);	}    /*     * if DGCAck is necessary?? //According to RMI wire protocol, send a DGCAck //     * to indicate receiving return value dout.writeByte(MESSAGE_DGCACK);     * ack.write(dout); out.flush();    */    	manager.discardConnection(conn);    if (returncode != RETURN_ACK && returnval != null)      {        if (returncode == RETURN_NACK)          throw (Exception) returnval;        else          throw new RemoteException("unexpected returncode: " + returncode);	}	return (returnval);  }