|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface BatchSynchQueue<E>
BatchSynchQueue is an abstraction of the classic producer/consumer buffer pattern for thread interaction. In this pattern threads can deposit data onto a buffer whilst other threads take data from the buffer and perform usefull work with it. A BatchSynchQueue adds to this the possibility that producers can be blocked until their data is consumed or until a consumer chooses to release the producer some time after consuming the data from the queue.
There are a number of possible advantages to using this technique when compared with having the producers processing their own data:
SynchRecord
interface.
The BlockingQueue.take()
, BlockingQueue.drainTo(java.util.Collection super E>)
and
BlockingQueue.drainTo(java.util.Collection super E>, int)
methods from BlockingQueue
should behave as if they
have been called with unblock set to false. That is they take elements from the queue but leave the producers
blocked. These methods do not return collections of SynchRecord
s so they do not supply an interface through
which errors or re-queuings can be applied. If these methods are used then the consumer must succesfully process
all the records it takes.
The BlockingQueue.put(E)
method should silently swallow any exceptions that consumers attempt to return to the caller.
In order to handle exceptions the tryPut(E)
method must be used.
Responsibilities | Collaborations |
---|---|
Handle synchronous puts, with possible exceptions. | |
Allow consumers to take many records from a queue in a batch. | |
Allow consumers to decide when to unblock synchronous producers. |
Method Summary | |
---|---|
SynchRef |
drainTo(Collection<SynchRecord<E>> c,
boolean unblock)
Takes all available data items from the queue or blocks until some become available. |
SynchRef |
drainTo(Collection<SynchRecord<E>> c,
int maxElements,
boolean unblock)
Takes up to maxElements available data items from the queue or blocks until some become available. |
void |
tryPut(E e)
Tries a synchronous put into the queue. |
Methods inherited from interface java.util.concurrent.BlockingQueue |
---|
add, contains, drainTo, drainTo, offer, offer, poll, put, remainingCapacity, remove, take |
Methods inherited from interface java.util.Queue |
---|
element, peek, poll, remove |
Methods inherited from interface java.util.Collection |
---|
addAll, clear, containsAll, equals, hashCode, isEmpty, iterator, removeAll, retainAll, size, toArray, toArray |
Method Detail |
---|
void tryPut(E e) throws InterruptedException, SynchException
SynchException
.
e
- The data element to put into the queue.
InterruptedException
- If the thread is interrupted whilst waiting to write to the queue or whilst waiting
on its entry in the queue being consumed.
SynchException
- If a consumer encounters an error whilst processing the data element.SynchRef drainTo(Collection<SynchRecord<E>> c, boolean unblock)
SynchRecord
which provides an interface to requeue them or send errors to their
producers, where the producers are still blocked.
c
- The collection to drain the data items into.unblock
- If set to true the producers for the taken items will be immediately unblocked.
SynchRef drainTo(Collection<SynchRecord<E>> c, int maxElements, boolean unblock)
SynchRecord
which provides an interface to requeue them or send errors to their
producers, where the producers are still blocked.
c
- The collection to drain the data items into.maxElements
- The maximum number of elements to drain.unblock
- If set to true the producers for the taken items will be immediately unblocked.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |