Package com.db4o.foundation
Class BlockingQueue<T>
- java.lang.Object
-
- com.db4o.foundation.BlockingQueue<T>
-
- All Implemented Interfaces:
BlockingQueue4<T>
,Queue4<T>
- Direct Known Subclasses:
PausableBlockingQueue
public class BlockingQueue<T> extends java.lang.Object implements BlockingQueue4<T>
-
-
Constructor Summary
Constructors Constructor Description BlockingQueue()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(T obj)
int
drainTo(Collection4<T> target)
Removes all the available elements in the queue to the colletion passed as argument.boolean
hasNext()
Iterator4<T>
iterator()
T
next()
T
next(long timeout)
Returns the next queued item or waits for it to be available for the maximum oftimeout
miliseconds.T
nextMatching(Predicate4<T> condition)
Returns the next object in the queue that matches the specified condition.void
stop()
protected void
unsafeWaitForNext()
protected boolean
unsafeWaitForNext(long timeout)
void
waitForNext()
boolean
waitForNext(long timeout)
-
-
-
Field Detail
-
_queue
protected NonblockingQueue<T> _queue
-
_lock
protected Lock4 _lock
-
_stopped
protected boolean _stopped
-
-
Method Detail
-
next
public T next(long timeout) throws BlockingQueueStoppedException
Description copied from interface:BlockingQueue4
Returns the next queued item or waits for it to be available for the maximum of
timeout
miliseconds.- Specified by:
next
in interfaceBlockingQueue4<T>
- Parameters:
timeout
- maximum time to wait for the next avilable item in miliseconds- Returns:
- the next item or
null
iftimeout
is reached - Throws:
BlockingQueueStoppedException
- if theBlockingQueue4.stop()
is called.
-
drainTo
public int drainTo(Collection4<T> target)
Description copied from interface:BlockingQueue4
Removes all the available elements in the queue to the colletion passed as argument.
It will block until at least one element is available.
- Specified by:
drainTo
in interfaceBlockingQueue4<T>
- Returns:
- the number of elements added to the list.
-
waitForNext
public boolean waitForNext(long timeout) throws BlockingQueueStoppedException
- Throws:
BlockingQueueStoppedException
-
next
public T next() throws BlockingQueueStoppedException
- Specified by:
next
in interfaceQueue4<T>
- Throws:
BlockingQueueStoppedException
-
stop
public void stop()
- Specified by:
stop
in interfaceBlockingQueue4<T>
-
nextMatching
public T nextMatching(Predicate4<T> condition)
Description copied from interface:Queue4
Returns the next object in the queue that matches the specified condition. The operation is always NON-BLOCKING.- Specified by:
nextMatching
in interfaceQueue4<T>
- Parameters:
condition
- the object must satisfy to be returned- Returns:
- the object satisfying the condition or null if none does
-
waitForNext
public void waitForNext() throws BlockingQueueStoppedException
- Throws:
BlockingQueueStoppedException
-
unsafeWaitForNext
protected void unsafeWaitForNext() throws BlockingQueueStoppedException
- Throws:
BlockingQueueStoppedException
-
unsafeWaitForNext
protected boolean unsafeWaitForNext(long timeout) throws BlockingQueueStoppedException
- Throws:
BlockingQueueStoppedException
-
-