Example #1
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);
  }