Package com.complexible.common.collect
Class SingletonQueue<T>
java.lang.Object
com.complexible.common.collect.SingletonQueue<T>
A simple queue that can hold at most one element while in addition provides a function to
close() the queue.
The queue is either empty (take() calls will block) or full (calls will block.A closed
queue will not block on any put call but will silently ignore the value. Calling take() on a
closed queue will always return the special end element.- Since:
- 2.0
- Version:
- 2.0
- Author:
- Evren Sirin
-
Constructor Summary
ConstructorsConstructorDescriptionSingletonQueue(T eoq) Creates a new queue with the specific End-Of-Queue element. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the queue causing all blocked threads to be unblocked.getEOQ()Returns the special end of queue (EOQ) value.booleanisEmpty()booleanisFull()voidPuts a value to the queue waiting indefinitely if the queue is full.take()Take a value from the queue waiting indefinitely if it is empty.
-
Constructor Details
-
SingletonQueue
Creates a new queue with the specific End-Of-Queue element.
-
-
Method Details
-
isFull
public boolean isFull() -
isEmpty
public boolean isEmpty() -
getEOQ
Returns the special end of queue (EOQ) value. -
put
Puts a value to the queue waiting indefinitely if the queue is full. If another thread closes the queue, this function will immediately return and the value will be ignored.- Throws:
InterruptedException
-
take
Take a value from the queue waiting indefinitely if it is empty. If another thread closes the queue, this function will immediately return theend element.- Throws:
InterruptedException
-
close
Closes the queue causing all blocked threads to be unblocked. All valuesput(Object)after this call will be ignored.- Throws:
InterruptedException
-