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 voidadd(T obj)intdrainTo(Collection4<T> target)Removes all the available elements in the queue to the colletion passed as argument.booleanhasNext()Iterator4<T>iterator()Tnext()Tnext(long timeout)Returns the next queued item or waits for it to be available for the maximum oftimeoutmiliseconds.TnextMatching(Predicate4<T> condition)Returns the next object in the queue that matches the specified condition.voidstop()protected voidunsafeWaitForNext()protected booleanunsafeWaitForNext(long timeout)voidwaitForNext()booleanwaitForNext(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:BlockingQueue4Returns the next queued item or waits for it to be available for the maximum of
timeoutmiliseconds.- Specified by:
nextin interfaceBlockingQueue4<T>- Parameters:
timeout- maximum time to wait for the next avilable item in miliseconds- Returns:
- the next item or
nulliftimeoutis reached - Throws:
BlockingQueueStoppedException- if theBlockingQueue4.stop()is called.
-
drainTo
public int drainTo(Collection4<T> target)
Description copied from interface:BlockingQueue4Removes 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:
drainToin 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:
nextin interfaceQueue4<T>- Throws:
BlockingQueueStoppedException
-
stop
public void stop()
- Specified by:
stopin interfaceBlockingQueue4<T>
-
nextMatching
public T nextMatching(Predicate4<T> condition)
Description copied from interface:Queue4Returns the next object in the queue that matches the specified condition. The operation is always NON-BLOCKING.- Specified by:
nextMatchingin 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
-
-