Package com.usatiuk.utils
Class HashSetDelayedBlockingQueue<T>
java.lang.Object
com.usatiuk.utils.HashSetDelayedBlockingQueue<T>
- Type Parameters:
T
- the type of the objects in the queue
Blocking queue that delays the objects for a given time, and deduplicates them.
-
Constructor Summary
ConstructorsConstructorDescriptionHashSetDelayedBlockingQueue
(long delay) Creates a new HashSetDelayedBlockingQueue with the specified delay. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds the object to the queue if it doesn't exist.addNoDelay
(T el) Adds the object to the queue with no delay.close()
Closes the queue and returns all objects in it.get()
Gets the object from the queue, waiting for it if necessary.get
(long timeout) Gets the object from the queue, waiting for it if necessary.getAll()
Gets all objects from the queue that are ready to be processed.Gets all objects from the queue, waiting for them if necessary.getAllWait
(int max) Gets all objects from the queue, waiting for them if necessary.getAllWait
(int max, long timeout) Gets all objects from the queue, waiting for them if necessary.long
getDelay()
boolean
Checks if the queue has an object that is ready to be processed.Merges the object with the old one.Adds the object to the queue, if it exists re-adds it with a new delayRemoves the object from the queue.void
setDelay
(long delay) Sets the delay for the queue.tryGet()
Tries to get the object from the queue without waiting.
-
Constructor Details
-
HashSetDelayedBlockingQueue
public HashSetDelayedBlockingQueue(long delay) Creates a new HashSetDelayedBlockingQueue with the specified delay.- Parameters:
delay
- the delay in milliseconds
-
-
Method Details
-
getDelay
public long getDelay()- Returns:
- the delay in milliseconds
-
setDelay
public void setDelay(long delay) Sets the delay for the queue.- Parameters:
delay
- the delay in milliseconds
-
add
Adds the object to the queue if it doesn't exist.- Parameters:
el
- the object to add- Returns:
- true if the object was added, false if it already exists
-
addNoDelay
Adds the object to the queue with no delay.- Parameters:
el
- the object to add- Returns:
- the old object if it existed, null otherwise
-
readd
Adds the object to the queue, if it exists re-adds it with a new delay- Parameters:
el
- the object to add- Returns:
- the old object if it existed, null otherwise
-
merge
Merges the object with the old one.- Parameters:
el
- the object to mergetransformer
- the function to transform the old object- Returns:
- the old object if it existed, null otherwise
-
remove
Removes the object from the queue.- Parameters:
el
- the object to remove- Returns:
- the removed object, or null if it didn't exist
-
get
Gets the object from the queue, waiting for it if necessary.- Parameters:
timeout
- the timeout in milliseconds, or -1 for no timeout- Returns:
- the object, or null if it timed out
- Throws:
InterruptedException
- if the thread is interrupted
-
get
Gets the object from the queue, waiting for it if necessary.- Returns:
- the object
- Throws:
InterruptedException
- if the thread is interrupted
-
hasImmediate
public boolean hasImmediate()Checks if the queue has an object that is ready to be processed.- Returns:
- true if there is an object ready, false otherwise
-
tryGet
Tries to get the object from the queue without waiting.- Returns:
- the object, or null if it doesn't exist
-
getAll
Gets all objects from the queue that are ready to be processed.- Returns:
- a collection of objects
-
close
Closes the queue and returns all objects in it.- Returns:
- a collection of objects
-
getAllWait
Gets all objects from the queue, waiting for them if necessary.- Returns:
- a collection of objects
- Throws:
InterruptedException
- if the thread is interrupted
-
getAllWait
Gets all objects from the queue, waiting for them if necessary.- Parameters:
max
- the maximum number of objects to get- Returns:
- a collection of objects
- Throws:
InterruptedException
- if the thread is interrupted
-
getAllWait
Gets all objects from the queue, waiting for them if necessary.- Parameters:
max
- the maximum number of objects to gettimeout
- the timeout in milliseconds, or -1 for no timeout- Returns:
- a collection of objects
- Throws:
InterruptedException
- if the thread is interrupted
-