コード例 #1
0
ファイル: UnicastRemoteCall.java プロジェクト: Blueash/gcc
  public void executeCall() throws Exception {
    byte returncode;
    ObjectInput oin;

    // signal the call when constructing
    try {
      DataOutputStream dout = conn.getDataOutputStream();
      dout.write(MESSAGE_CALL);

      oout = conn.startObjectOutputStream(); // (re)start ObjectOutputStream
      objid.write(oout);
      oout.writeInt(opnum);
      oout.writeLong(hash);
    } catch (IOException ex) {
      throw new MarshalException("Try to write header but failed.", ex);
    }

    try {
      releaseOutputStream();
      DataInputStream din = conn.getDataInputStream();
      if (din.readByte() != MESSAGE_CALL_ACK) throw new RemoteException("Call not acked");

      oin = startInputStream();
      returncode = oin.readByte();
      UID.read(oin);
    } catch (IOException ex) {
      throw new UnmarshalException("Try to read header but failed:", ex);
    }

    // check return code
    switch (returncode) {
      case RETURN_ACK: // it's ok
        return;
      case RETURN_NACK:
        Object returnobj;
        try {
          returnobj = oin.readObject();
        } catch (Exception ex2) {
          throw new UnmarshalException("Try to read exception object but failed", ex2);
        }

        if (!(returnobj instanceof Exception))
          throw new UnmarshalException("Should be Exception type here: " + returnobj);
        throw (Exception) returnobj;

      default:
        throw new UnmarshalException("Invalid return code");
    }
  }