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

public interface BeanChannel<T> extends BeanSupplier<T>, BeanConsumer<T>
A lifecycle-aware round-trip interface that combines both BeanSupplier (for serialization) and BeanConsumer (for parsing) on the same property or class.

Use this interface when the same object needs to:

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():

The framework drives the lifecycle:

  1. Calls begin() before the first data operation
  2. Reads via Iterable.iterator() (serializer) or writes via ThrowingConsumer.acceptThrows(Object) (parser)
  3. If an exception occurs, calls onError(Exception)
  4. Always calls complete() at the end (like finally)

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):

@Marshalled(factory=ItemChannelFactory.class) public class ItemChannel implements BeanChannel<Item> { private Connection conn; private boolean writeMode; @Override public void begin() throws Exception { conn = ds.getConnection(); conn.setAutoCommit(false); } // Serializer calls iterator() — read mode @Override public Iterator<Item> iterator() { return new ResultSetIterator<>(...); } // Parser calls acceptThrows() — write mode @Override public void acceptThrows(Item item) throws Exception { writeMode = true; // insert item... } @Override public void onError(Exception e) throws Exception { if (writeMode) conn.rollback(); throw e; } @Override public void complete() throws Exception { if (writeMode) conn.commit(); conn.close(); } }

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Called before iteration starts.
    default void
    Always called after iteration ends (like finally).
    default void
    Called when an exception occurs during iteration.

    Methods inherited from interface java.util.function.Consumer

    andThen

    Methods inherited from interface java.lang.Iterable

    forEach, iterator, spliterator

    Methods inherited from interface org.apache.juneau.commons.function.ThrowingConsumer

    accept, acceptThrows