Interface IOSubchannel

All Superinterfaces:
Associator, Channel, Eligible, Subchannel
All Known Subinterfaces:
SocketIOChannel
All Known Implementing Classes:
IOSubchannel.DefaultIOSubchannel, LinkedIOSubchannel, ProcessManager.ProcessChannel, SocketConnectionManager.SocketChannelImpl

public interface IOSubchannel extends Subchannel
Represents a subchannel for grouping input and output events related to an I/O resource such as an opened file or a network connection.

An I/O 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.

  • Method Details

    • 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.

      Returns:
      the event pipeline
    • byteBufferPool

      Get the subchannel’s byte buffer pool.
      Returns:
      the buffer pool
    • charBufferPool

      Get the subchannel’s char buffer pool.
      Returns:
      the buffer pool
    • respond

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

      Type Parameters:
      T - the event’s type
      Parameters:
      event - the event to fire
      Returns:
      the event (for easy chaining)
    • create

      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.
      Parameters:
      component - the component used to get the main channel
      responsePipeline - the response pipeline
      Returns:
      the subchannel