Package jadex.commons.collection
Class ActionReferenceQueue
- java.lang.Object
-
- java.lang.ref.ReferenceQueue
-
- jadex.commons.collection.ActionReferenceQueue
-
public class ActionReferenceQueue extends java.lang.ref.ReferenceQueueThe 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.ListentriesThe list of elements.
-
Constructor Summary
Constructors Constructor Description ActionReferenceQueue()Create a new list.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddEntry(java.lang.Object o, java.lang.Runnable action)Add an object with an associated value.intgetEntriesSize()Get the size of the entries (existing objects).java.lang.ref.Referencepoll()Poll a stale entry.java.lang.ref.Referenceremove()Remove an element from the queue.java.lang.ref.Referenceremove(long timeout)Remove an element from the queue.java.lang.RunnableremoveEntry(java.lang.Object obj)Remove an entry.java.lang.StringtoString()Get the string representation.
-
-
-
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.InterruptedExceptionRemove an element from the queue.- Overrides:
removein classjava.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.InterruptedExceptionRemove an element from the queue.- Overrides:
removein classjava.lang.ref.ReferenceQueue- Returns:
- A weak entry.
- Throws:
java.lang.IllegalArgumentExceptionjava.lang.InterruptedException
-
poll
public java.lang.ref.Reference poll()
Poll a stale entry.- Overrides:
pollin classjava.lang.ref.ReferenceQueue- Returns:
- A weak entry or null (if none is stale).
-
toString
public java.lang.String toString()
Get the string representation.- Overrides:
toStringin classjava.lang.Object
-
-