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() |
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.
|
int |
getSize() |
boolean |
isConsumed()
Returns
true if no more items are available or if the consumer was closed. |
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 IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic int getSize()
getSize in interface org.mule.runtime.api.streaming.HasSizeCopyright © 2003–2017 MuleSoft, Inc.. All rights reserved.