Package io.bytestreams.exchange.core
Class AbstractChannel<OUT,IN>
java.lang.Object
io.bytestreams.exchange.core.AbstractChannel<OUT,IN>
- Type Parameters:
OUT- the outbound (written) message typeIN- the inbound (read) message type
- All Implemented Interfaces:
Channel
- Direct Known Subclasses:
MultiplexedChannel,PipelinedChannel,ServerChannel
Base class for
Transport-backed channels with managed I/O loops.
Provides write queue, read/write virtual threads, OTel channel span and metrics, graceful
close semantics, and error handling. Subclasses implement onInbound(IN), hasPending(), stopOnInboundError(java.lang.Exception, IN), and stopOnOutboundError(java.lang.Exception, OUT).
Lifecycle: construct → start() → close(). The channel is not usable until
start() is called, which starts the reader and writer virtual threads.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final io.opentelemetry.api.trace.Spanprotected final CompletableFuture<Void> static final longprotected final Durationprotected final io.opentelemetry.api.common.Attributesprotected final CompletableFuture<Void> protected final io.opentelemetry.api.metrics.LongUpDownCounterprotected final io.opentelemetry.api.metrics.DoubleHistogramprotected final io.opentelemetry.api.metrics.LongCounterprotected final io.opentelemetry.api.metrics.LongCounterprotected static final Set<ChannelStatus> protected final AtomicReference<ChannelStatus> protected final Transportprotected final LinkedBlockingQueue<OUT> protected final io.opentelemetry.api.metrics.LongUpDownCounter -
Method Summary
Modifier and TypeMethodDescriptionprotected io.opentelemetry.api.common.AttributesbuildMessageAttributes(Object message) Returns metric attributes for a message, includingmessage_typeset to the simple class name of the given message.close()Closes this channel gracefully.Returns a defensive copy of the close future.protected abstract booleanid()Returns a stable identifier for this channel.protected voidInterrupts the reader thread if the channel is shutting down and no work remains.protected abstract voidvoidstart()Starts the channel's I/O loops.status()Returns the current lifecycle status of this channel.
-
Field Details
-
DEFAULT_ERROR_BACKOFF_NANOS
public static final long DEFAULT_ERROR_BACKOFF_NANOS -
SHUTTING_DOWN
-
writeQueue
-
writeQueueSize
protected final io.opentelemetry.api.metrics.LongUpDownCounter writeQueueSize -
transport
-
readFuture
-
requestActive
protected final io.opentelemetry.api.metrics.LongUpDownCounter requestActive -
requestTotal
protected final io.opentelemetry.api.metrics.LongCounter requestTotal -
requestErrors
protected final io.opentelemetry.api.metrics.LongCounter requestErrors -
requestDuration
protected final io.opentelemetry.api.metrics.DoubleHistogram requestDuration -
channelSpan
protected final io.opentelemetry.api.trace.Span channelSpan -
status
-
closeFuture
-
defaultTimeout
-
meterAttributes
protected final io.opentelemetry.api.common.Attributes meterAttributes
-
-
Method Details
-
id
Description copied from interface:ChannelReturns a stable identifier for this channel. -
status
Description copied from interface:ChannelReturns the current lifecycle status of this channel. -
start
public void start()Description copied from interface:ChannelStarts the channel's I/O loops. Must be called exactly once after construction. -
closeFuture
Returns a defensive copy of the close future. Each call returns a new instance; all copies complete when the channel finishes shutting down.- Specified by:
closeFuturein interfaceChannel- Returns:
- a read-only view of the close future
-
close
Description copied from interface:ChannelCloses this channel gracefully. -
interruptIfDrained
protected void interruptIfDrained()Interrupts the reader thread if the channel is shutting down and no work remains. -
buildMessageAttributes
Returns metric attributes for a message, includingmessage_typeset to the simple class name of the given message. Subclasses use this to build request-scoped metric attributes. -
hasPending
protected abstract boolean hasPending() -
onInbound
-