public interface IOSubchannel extends Channel, Associator
Represents an I/O subchannel. Subchannels delegate the invocations of a
Channel
’s methods to their respective main channel. Events fired on a
subchannel are therefore handled by the framework as if they were fired on
the main channel. Firing events on a subchannel instance instead of on the
main channel is a means to group related events. In particular, I/O
subchannels are used to group events that relate to an I/O resource such as
an opened file or a network connection.
A subchannel has an initiator that creates and manages the subchannel. Events fired by the initiator are said to flow downstream on the channel. Events fired by components in response are said to flow upstream.
Upstream and downstream events are usually handled by two different pipelines
managed by the initiator. One pipeline, accessible only to the initiator,
handles the downstream events. The other, made available as a property of the
I/O subchannel (see responsePipeline()
and respond(Event)
),
handles the upstream events. Of course, any pipeline can be
used to send events upstream to the initiator component. However, using
arbitrary pipelines holds the risk that events aren’t delivered in the
intended order.
An I/O subchannel also provides associated buffer pools for byte buffers and character buffers. Buffers used in responses (upstream events) should be acquired from these pools only. The initiator should initialize the pools in such a way that it suits its needs.
Modifier and Type | Interface and Description |
---|---|
static class |
IOSubchannel.DefaultSubchannel
A simple implementation of
IOSubchannel . |
Channel.Default
Modifier and Type | Method and Description |
---|---|
ManagedBufferPool<ManagedBuffer<ByteBuffer>,ByteBuffer> |
byteBufferPool()
Get the subchannel’s byte buffer pool.
|
ManagedBufferPool<ManagedBuffer<CharBuffer>,CharBuffer> |
charBufferPool()
Get the subchannel’s char buffer pool.
|
static IOSubchannel |
create(Component component,
EventPipeline responsePipeline)
Creates a new subchannel of the given component’s channel with the
given event pipeline and a buffer pool with two buffers sized 4096.
|
default Object |
defaultCriterion()
Returns the main channel’s match value.
|
default boolean |
isEligibleFor(Object value)
Delegates to main channel.
|
Channel |
mainChannel()
Returns the main channel.
|
default <T extends Event<?>> |
respond(T event)
Fires the given event on this subchannel using the subchannel’s response
pipeline.
|
EventPipeline |
responsePipeline()
Gets the
EventPipeline that can be used for events going back to
the initiator of this connection. |
static String |
toString(IOSubchannel subchannel)
Returns a string representation of the channel.
|
criterionToString, toString, toString
associated, associated, associated, associated, setAssociated
Channel mainChannel()
Returns the main channel.
default Object defaultCriterion()
Returns the main channel’s match value.
defaultCriterion
in interface Eligible
Eligible.defaultCriterion()
default boolean isEligibleFor(Object value)
Delegates to main channel.
isEligibleFor
in interface Eligible
value
- the criteriontrue
if this meets the criterionEligible.isEligibleFor(Object)
EventPipeline responsePipeline()
Gets the EventPipeline
that can be used for events going back to
the initiator of this connection. Consistently using this event pipeline
for response events ensures that the events are written in proper
sequence.
ManagedBufferPool<ManagedBuffer<ByteBuffer>,ByteBuffer> byteBufferPool()
Get the subchannel’s byte buffer pool.
ManagedBufferPool<ManagedBuffer<CharBuffer>,CharBuffer> charBufferPool()
Get the subchannel’s char buffer pool.
default <T extends Event<?>> T respond(T event)
Fires the given event on this subchannel using the subchannel’s response
pipeline. Effectively, fire(someEvent)
is a shortcut for
getResponsePipeline.add(someEvent, this)
.
T
- the event’s typeevent
- the event to firestatic String toString(IOSubchannel subchannel)
Returns a string representation of the channel.
subchannel
- the subchannelstatic IOSubchannel create(Component component, EventPipeline responsePipeline)
Creates a new subchannel of the given component’s channel with the given event pipeline and a buffer pool with two buffers sized 4096.
component
- the component used to get the main channelresponsePipeline
- the response pipeline