Package jadex.commons.collection
Class ActionReferenceQueue
- java.lang.Object
-
- java.lang.ref.ReferenceQueue
-
- jadex.commons.collection.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.
-
Constructor Summary
Constructors Constructor Description ActionReferenceQueue()
Create a new list.
-
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.
-
-
-
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 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.InterruptedException
Remove an element from the queue.- Overrides:
remove
in classjava.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 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:
toString
in classjava.lang.Object
-
-