org.hypergraphdb.handle
Class PhantomHandle

java.lang.Object
  extended by java.lang.ref.Reference<T>
      extended by java.lang.ref.PhantomReference<java.lang.Object>
          extended by org.hypergraphdb.handle.PhantomHandle
All Implemented Interfaces:
java.lang.Comparable<HGHandle>, HGLiveHandle, HGHandle
Direct Known Subclasses:
PhantomManagedHandle

public class PhantomHandle
extends java.lang.ref.PhantomReference<java.lang.Object>
implements HGLiveHandle, java.lang.Comparable<HGHandle>

An implementation of a live handle that tracks garbage collection activity by extending PhantomReference.

Author:
Borislav Iordanov

Field Summary
static java.lang.ThreadLocal<java.lang.Boolean> returnEnqueued
          This is for internal use ONLY.
 
Constructor Summary
PhantomHandle(java.lang.Object ref, HGPersistentHandle persistentHandle, byte flags, java.lang.ref.ReferenceQueue<java.lang.Object> refQueue)
           
 
Method Summary
 void accessed()
           
 int compareTo(HGHandle h)
           
 boolean equals(java.lang.Object other)
           
 java.lang.Object fetchRef()
           A getter of the referent that uses reflection to access the field directly.
 byte getFlags()
           
 HGPersistentHandle getPersistentHandle()
           
 java.lang.Object getRef()
           
 int hashCode()
           
 void storeRef(java.lang.Object ref)
           A setter of the referent.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.ref.PhantomReference
get
 
Methods inherited from class java.lang.ref.Reference
clear, enqueue, isEnqueued
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

returnEnqueued

public static java.lang.ThreadLocal<java.lang.Boolean> returnEnqueued
This is for internal use ONLY.

See comments in 'getRef' for information about this variable.

Constructor Detail

PhantomHandle

public PhantomHandle(java.lang.Object ref,
                     HGPersistentHandle persistentHandle,
                     byte flags,
                     java.lang.ref.ReferenceQueue<java.lang.Object> refQueue)
Method Detail

getFlags

public byte getFlags()
Specified by:
getFlags in interface HGLiveHandle

getPersistentHandle

public HGPersistentHandle getPersistentHandle()
Specified by:
getPersistentHandle in interface HGLiveHandle

fetchRef

public java.lang.Object fetchRef()

A getter of the referent that uses reflection to access the field directly. Thus, the field is available even after it's finalized. Therefore, this method should only be called if it doesn't result in the referent becoming strongly reachable again.


storeRef

public void storeRef(java.lang.Object ref)

A setter of the referent. This setter will block the current Thread while the reference is being enqueued by the grabage collector.

Parameters:
ref -

getRef

public java.lang.Object getRef()
Specified by:
getRef in interface HGLiveHandle

accessed

public void accessed()

hashCode

public final int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public final boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

compareTo

public int compareTo(HGHandle h)
Specified by:
compareTo in interface java.lang.Comparable<HGHandle>