示例#1
0
  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");
    }
  }
示例#2
0
  public void write(ObjectOutput out, boolean useNewFormat) throws IOException {
    boolean isResultStream = false;
    if (out instanceof ConnectionOutputStream) {
      ConnectionOutputStream stream = (ConnectionOutputStream) out;
      isResultStream = stream.isResultStream();
      /*
       * Ensure that referential integrity is not broken while
       * this LiveRef is in transit.  If it is being marshalled
       * as part of a result, it may not otherwise be strongly
       * reachable after the remote call has completed; even if
       * it is being marshalled as part of an argument, the VM
       * may determine that the reference on the stack is no
       * longer reachable after marshalling (see 6181943)--
       * therefore, tell the stream to save a reference until a
       * timeout expires or, for results, a DGCAck message has
       * been received from the caller, or for arguments, the
       * remote call has completed.  For a "local" LiveRef, save
       * a reference to the impl directly, because the impl is
       * not reachable from the LiveRef (see 4114579);
       * otherwise, save a reference to the LiveRef, for the
       * client-side DGC to watch over.  (Also see 4017232.)
       */
      if (isLocal) {
        ObjectEndpoint oe = new ObjectEndpoint(id, ep.getInboundTransport());
        Target target = ObjectTable.getTarget(oe);

        if (target != null) {
          Remote impl = target.getImpl();
          if (impl != null) {
            stream.saveObject(impl);
          }
        }
      } else {
        stream.saveObject(this);
      }
    }
    // All together now write out the endpoint, id, and flag

    // (need to choose whether or not to use old JDK1.1 endpoint format)
    if (useNewFormat) {
      ((TCPEndpoint) ep).write(out);
    } else {
      ((TCPEndpoint) ep).writeHostPortFormat(out);
    }
    id.write(out);
    out.writeBoolean(isResultStream);
  }
示例#3
0
  public void write(ObjectOutput out, boolean useNewFormat) throws IOException {
    boolean isResultStream = false;
    if (out instanceof ConnectionOutputStream) {
      ConnectionOutputStream stream = (ConnectionOutputStream) out;
      isResultStream = stream.isResultStream();
      /*
       * If this LiveRef is being marshalled as part of a return value,
       * then we have to worry about referential integrity being broken
       * while the reference is in transit, in case there no longer
       * remains a strong reference in this VM after the call has
       * completed.  Therefore, we tell the stream to save a reference
       * until an acknowledgment has been received from the caller; for
       * "local" LiveRefs, save a reference to the impl directly,
       * because the impl is not reachable from this LiveRef (see
       * 4114579); otherwise, save a reference to the LiveRef, for the
       * client-side DGC to watch over (see 4017232 for more details).
       */
      if (isResultStream) {
        if (isLocal) {
          Target target = ObjectTable.getTarget(id);
          if (target != null) {
            Remote impl = target.getImpl();
            if (impl != null) {
              stream.saveObject(impl);
            }
          }
        } else {
          stream.saveObject(this);
        }
      }
    }
    // All together now write out the endpoint, id, and flag

    // (need to choose whether or not to use old JDK1.1 endpoint format)
    if (useNewFormat) {
      ((TCPEndpoint) ep).write(out);
    } else {
      ((TCPEndpoint) ep).writeHostPortFormat(out);
    }
    id.write(out);
    out.writeBoolean(isResultStream);
  }