src/share/classes/sun/rmi/transport/WeakRef.java

Print this page




  24  */
  25 package sun.rmi.transport;
  26 
  27 import java.lang.ref.*;
  28 import sun.rmi.runtime.Log;
  29 
  30 /**
  31  * WeakRef objects are used by the RMI runtime to hold potentially weak
  32  * references to exported remote objects in the local object table.
  33  *
  34  * This class extends the functionality of java.lang.ref.WeakReference in
  35  * several ways.  The methods pin() and unpin() can be used to set
  36  * whether the contained reference is strong or weak (it is weak upon
  37  * construction).  The hashCode() and equals() methods are overridden so
  38  * that WeakRef objects hash and compare to each other according to the
  39  * object identity of their referents.
  40  *
  41  * @author  Ann Wollrath
  42  * @author  Peter Jones
  43  */
  44 class WeakRef extends WeakReference {
  45 
  46     /** value of the referent's "identity" hash code */
  47     private int hashValue;
  48 
  49     /** strong reference to the referent, for when this WeakRef is "pinned" */
  50     private Object strongRef = null;
  51 
  52     /**
  53      * Create a new WeakRef to the given object.
  54      */
  55     public WeakRef(Object obj) {
  56         super(obj);
  57         setHashValue(obj);      // cache object's "identity" hash code
  58     }
  59 
  60     /**
  61      * Create a new WeakRef to the given object, registered with a queue.
  62      */
  63     public WeakRef(Object obj, ReferenceQueue q) {
  64         super(obj, q);
  65         setHashValue(obj);      // cache object's "identity" hash code
  66     }
  67 
  68     /**
  69      * Pin the contained reference (make this a strong reference).
  70      */
  71     public synchronized void pin() {
  72         if (strongRef == null) {
  73             strongRef = get();
  74 
  75             if (DGCImpl.dgcLog.isLoggable(Log.VERBOSE)) {
  76                 DGCImpl.dgcLog.log(Log.VERBOSE,
  77                                    "strongRef = " + strongRef);
  78             }
  79         }
  80     }
  81 
  82     /**
  83      * Unpin the contained reference (make this a weak reference).




  24  */
  25 package sun.rmi.transport;
  26 
  27 import java.lang.ref.*;
  28 import sun.rmi.runtime.Log;
  29 
  30 /**
  31  * WeakRef objects are used by the RMI runtime to hold potentially weak
  32  * references to exported remote objects in the local object table.
  33  *
  34  * This class extends the functionality of java.lang.ref.WeakReference in
  35  * several ways.  The methods pin() and unpin() can be used to set
  36  * whether the contained reference is strong or weak (it is weak upon
  37  * construction).  The hashCode() and equals() methods are overridden so
  38  * that WeakRef objects hash and compare to each other according to the
  39  * object identity of their referents.
  40  *
  41  * @author  Ann Wollrath
  42  * @author  Peter Jones
  43  */
  44 class WeakRef extends WeakReference<Object> {
  45 
  46     /** value of the referent's "identity" hash code */
  47     private int hashValue;
  48 
  49     /** strong reference to the referent, for when this WeakRef is "pinned" */
  50     private Object strongRef = null;
  51 
  52     /**
  53      * Create a new WeakRef to the given object.
  54      */
  55     public WeakRef(Object obj) {
  56         super(obj);
  57         setHashValue(obj);      // cache object's "identity" hash code
  58     }
  59 
  60     /**
  61      * Create a new WeakRef to the given object, registered with a queue.
  62      */
  63     public WeakRef(Object obj, ReferenceQueue<Object> q) {
  64         super(obj, q);
  65         setHashValue(obj);      // cache object's "identity" hash code
  66     }
  67 
  68     /**
  69      * Pin the contained reference (make this a strong reference).
  70      */
  71     public synchronized void pin() {
  72         if (strongRef == null) {
  73             strongRef = get();
  74 
  75             if (DGCImpl.dgcLog.isLoggable(Log.VERBOSE)) {
  76                 DGCImpl.dgcLog.log(Log.VERBOSE,
  77                                    "strongRef = " + strongRef);
  78             }
  79         }
  80     }
  81 
  82     /**
  83      * Unpin the contained reference (make this a weak reference).