T - the type that the consumer will returnP - the type that the producer generatespublic abstract class AbstractConsumer<T,P> extends Object implements Consumer<T>
Consumer. This template class takes care of the
contract's subtleties like returning fast when closed and throwing the correct
types of exceptions| Constructor and Description |
|---|
AbstractConsumer(Producer<P> producer) |
| Modifier and Type | Method and Description |
|---|---|
protected abstract boolean |
checkConsumed()
Implement this method to actualy check for the
Producer being fully
consumed without worrying about it being closed or throwing any exceptions |
void |
close()
Closes the resource.
|
T |
consume()
Retrieves the next available item.
|
protected abstract T |
doConsume()
Implement this method to actually consume the producer without worrying about
exception types or checking fo this consumer to be closed.
|
boolean |
isConsumed()
Returns
true if no more items are available or if the consumer
was closed. |
int |
size()
returns the total amount of items available for storage/processing.
|
protected abstract T doConsume() throws NoSuchElementException
nullnullNoSuchElementExceptionprotected abstract boolean checkConsumed()
Producer being fully
consumed without worrying about it being closed or throwing any exceptionsProducer has been consumed or notpublic final T consume() throws NoSuchElementException
consume in interface Consumer<T>null otherwiseNoSuchElementExceptionpublic final boolean isConsumed()
true if no more items are available or if the consumer
was closed. When this method returns true, implementors of this
class are require to invoke the Closeable.close() method before
returning in order to release resources as quickly as possible. Users of this
component who no longer need this require before it is fully consumed are also
required to close it.isConsumed in interface Consumer<T>true if no more items are available. false
otherwisepublic void close()
throws MuleException
close in interface CloseableMuleException - if an exception occurs closing the resourcepublic int size()
size in interface ProvidesTotalHintCopyright © 2003–2015 MuleSoft, Inc.. All rights reserved.