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 exceptionsConstructor 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
null
null
NoSuchElementException
protected 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
otherwiseNoSuchElementException
public 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 Closeable
MuleException
- if an exception occurs closing the resourcepublic int size()
size
in interface ProvidesTotalHint
Copyright © 2003–2016 MuleSoft, Inc.. All rights reserved.