Class ActionReferenceQueue


  • public class ActionReferenceQueue
    extends java.lang.ref.ReferenceQueue
    The extended reference queue allows for adding (weak) object with an associated action. Whenever the object becomes unreferenced its corresponding weak entry can be fetched from the queue and when this is done the associated action will automatically be executed.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.List entries
      The list of elements.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean addEntry​(java.lang.Object o, java.lang.Runnable action)
      Add an object with an associated value.
      int getEntriesSize()
      Get the size of the entries (existing objects).
      java.lang.ref.Reference poll()
      Poll a stale entry.
      java.lang.ref.Reference remove()
      Remove an element from the queue.
      java.lang.ref.Reference remove​(long timeout)
      Remove an element from the queue.
      java.lang.Runnable removeEntry​(java.lang.Object obj)
      Remove an entry.
      java.lang.String toString()
      Get the string representation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • entries

        protected transient java.util.List entries
        The list of elements.
    • Constructor Detail

      • ActionReferenceQueue

        public ActionReferenceQueue()
        Create a new list.
    • Method Detail

      • addEntry

        public boolean addEntry​(java.lang.Object o,
                                java.lang.Runnable action)
        Add an object with an associated value.
        Parameters:
        o - The object (becomes weak reference).
        val - The value.
      • removeEntry

        public java.lang.Runnable removeEntry​(java.lang.Object obj)
        Remove an entry.
      • getEntriesSize

        public int getEntriesSize()
        Get the size of the entries (existing objects). Does not expunge stale entries.
        Returns:
        The number of existing entries.
      • remove

        public java.lang.ref.Reference remove()
                                       throws java.lang.InterruptedException
        Remove an element from the queue.
        Overrides:
        remove in class java.lang.ref.ReferenceQueue
        Returns:
        A weak entry.
        Throws:
        java.lang.InterruptedException
      • remove

        public java.lang.ref.Reference remove​(long timeout)
                                       throws java.lang.IllegalArgumentException,
                                              java.lang.InterruptedException
        Remove an element from the queue.
        Overrides:
        remove in class java.lang.ref.ReferenceQueue
        Returns:
        A weak entry.
        Throws:
        java.lang.IllegalArgumentException
        java.lang.InterruptedException
      • poll

        public java.lang.ref.Reference poll()
        Poll a stale entry.
        Overrides:
        poll in class java.lang.ref.ReferenceQueue
        Returns:
        A weak entry or null (if none is stale).
      • toString

        public java.lang.String toString()
        Get the string representation.
        Overrides:
        toString in class java.lang.Object