Interface BeanChannel<T>
- Type Parameters:
T- The type of bean read and written by this channel.
- All Superinterfaces:
BeanConsumer<T>,BeanSupplier<T>,Consumer<T>,Iterable<T>,ThrowingConsumer<T>
- All Known Implementing Classes:
ListBeanChannel
BeanSupplier (for serialization)
and BeanConsumer (for parsing) on the same property or class.
Use this interface when the same object needs to:
- Provide beans to a serializer (via
Iterable.iterator()) - Receive beans from a parser (via
ThrowingConsumer.acceptThrows(Object))
The lifecycle methods (begin(), complete(), onError(Exception)) are
shared across both directions. The implementation implicitly knows its direction from which data
method is called first after begin():
Iterable.iterator()called first → read mode (serialization)ThrowingConsumer.acceptThrows(Object)called first → write mode (parsing)
The framework drives the lifecycle:
- Calls
begin()before the first data operation - Reads via
Iterable.iterator()(serializer) or writes viaThrowingConsumer.acceptThrows(Object)(parser) - If an exception occurs, calls
onError(Exception) - Always calls
complete()at the end (likefinally)
Since BeanChannel extends BeanConsumer, a BeanChannel instance passes
the parser's instanceof BeanConsumer check. Since it extends BeanSupplier, it
also passes the serializer's instanceof BeanSupplier check — both directions work.
Example (DB-backed round-trip channel):
See Also:
BeanConsumer- Parse-only lifecycle interfaceBeanSupplier- Serialize-only lifecycle interfaceBeanFactory- Universal factory for DI framework integrationListBeanChannel- Simple in-memory implementation- Marshalling
-
Method Summary
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliteratorMethods inherited from interface org.apache.juneau.commons.function.ThrowingConsumer
accept, acceptThrows
-
Method Details
-
begin
Description copied from interface:BeanSupplierCalled before iteration starts.Use this to open database connections, execute queries, or perform other setup.
- Specified by:
beginin interfaceBeanConsumer<T>- Specified by:
beginin interfaceBeanSupplier<T>- Throws:
Exception- If setup fails.
-
complete
Description copied from interface:BeanSupplierAlways called after iteration ends (likefinally).Use this to close database cursors, connections, or release other resources. This method is called whether serialization succeeded or
BeanSupplier.onError(Exception)rethrew.- Specified by:
completein interfaceBeanConsumer<T>- Specified by:
completein interfaceBeanSupplier<T>- Throws:
Exception- If cleanup fails.
-
onError
Description copied from interface:BeanSupplierCalled when an exception occurs during iteration.The default implementation rethrows the exception, stopping serialization immediately. Note that
BeanSupplier.complete()is always called afterward regardless.- Specified by:
onErrorin interfaceBeanConsumer<T>- Specified by:
onErrorin interfaceBeanSupplier<T>- Parameters:
e- The exception that occurred during iteration.- Throws:
Exception- If the error cannot be recovered from. Rethroweto stop serialization.
-