Ejemplo n.º 1
0
  public static LiveRef read(ObjectInput in, boolean useNewFormat)
      throws IOException, ClassNotFoundException {
    Endpoint ep;
    ObjID id;

    // Now read in the endpoint, id, and result flag
    // (need to choose whether or not to read old JDK1.1 endpoint format)
    if (useNewFormat) {
      ep = TCPEndpoint.read(in);
    } else {
      ep = TCPEndpoint.readHostPortFormat(in);
    }
    id = ObjID.read(in);
    boolean isResultStream = in.readBoolean();

    LiveRef ref = new LiveRef(id, ep, false);

    if (in instanceof ConnectionInputStream) {
      ConnectionInputStream stream = (ConnectionInputStream) in;
      // save ref to send "dirty" call after all args/returns
      // have been unmarshaled.
      stream.saveRef(ref);
      if (isResultStream) {
        // set flag in stream indicating that remote objects were
        // unmarshaled.  A DGC ack should be sent by the transport.
        stream.setAckNeeded();
      }
    } else {
      DGCClient.registerRefs(ep, Arrays.asList(new LiveRef[] {ref}));
    }

    return ref;
  }
Ejemplo n.º 2
0
  public boolean remoteEquals(Object obj) {
    if (obj != null && obj instanceof LiveRef) {
      LiveRef ref = (LiveRef) obj;

      TCPEndpoint thisEp = ((TCPEndpoint) ep);
      TCPEndpoint refEp = ((TCPEndpoint) ref.ep);

      RMIClientSocketFactory thisClientFactory = thisEp.getClientSocketFactory();
      RMIClientSocketFactory refClientFactory = refEp.getClientSocketFactory();

      /**
       * Fix for 4254103: LiveRef.remoteEquals should not fail if one of the objects in the
       * comparison has a null server socket. Comparison should only consider the following
       * criteria:
       *
       * <p>hosts, ports, client socket factories and object IDs.
       */
      if (thisEp.getPort() != refEp.getPort() || !thisEp.getHost().equals(refEp.getHost())) {
        return false;
      }
      if ((thisClientFactory == null) ^ (refClientFactory == null)) {
        return false;
      }
      if ((thisClientFactory != null)
          && !((thisClientFactory.getClass() == refClientFactory.getClass())
              && (thisClientFactory.equals(refClientFactory)))) {
        return false;
      }
      return (id.equals(ref.id));
    } else {
      return false;
    }
  }
Ejemplo n.º 3
0
  public boolean equals(Object obj) {
    if (obj != null && obj instanceof LiveRef) {
      LiveRef ref = (LiveRef) obj;

      return (ep.equals(ref.ep) && id.equals(ref.id) && isLocal == ref.isLocal);
    } else {
      return false;
    }
  }
Ejemplo n.º 4
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);
  }
Ejemplo n.º 5
0
 public int hashCode() {
   return id.hashCode();
 }