ChannelHandlerContext

public final class ChannelHandlerContext : ChannelInvoker

Every ChannelHandler has – when added to a ChannelPipeline – a corresponding ChannelHandlerContext which is the way ChannelHandlers can interact with other ChannelHandlers in the pipeline.

Most ChannelHandlers need to send events through the ChannelPipeline which they do by calling the respective method on their ChannelHandlerContext. In fact all the ChannelHandler default implementations just forward the event using the ChannelHandlerContext.

Many events are instrumental for a ChannelHandler‘s life-cycle and it is therefore very important to send them at the right point in time. Often, the right behaviour is to react to an event and then forward it to the next ChannelHandler.

  • Undocumented

    Declaration

    Swift

    public let pipeline: ChannelPipeline
  • Undocumented

    Declaration

    Swift

    public var channel: Channel { get }
  • Undocumented

    Declaration

    Swift

    public var handler: ChannelHandler { get }
  • Undocumented

    Declaration

    Swift

    public var remoteAddress: SocketAddress? { get }
  • Undocumented

    Declaration

    Swift

    public var localAddress: SocketAddress? { get }
  • Declaration

    Swift

    public var eventLoop: EventLoop { get }
  • Undocumented

    Declaration

    Swift

    public let name: String
  • Send a channelRegistered event to the next (inbound) ChannelHandler in the ChannelPipeline.

    Note

    For correct operation it is very important to forward any channelRegistered event using this method at the right point in time, that is usually when received.

    Declaration

    Swift

    public func fireChannelRegistered()
  • Send a channelUnregistered event to the next (inbound) ChannelHandler in the ChannelPipeline.

    Note

    For correct operation it is very important to forward any channelUnregistered event using this method at the right point in time, that is usually when received.

    Declaration

    Swift

    public func fireChannelUnregistered()
  • Send a channelActive event to the next (inbound) ChannelHandler in the ChannelPipeline.

    Note

    For correct operation it is very important to forward any channelActive event using this method at the right point in time, that is often when received.

    Declaration

    Swift

    public func fireChannelActive()
  • Send a channelInactive event to the next (inbound) ChannelHandler in the ChannelPipeline.

    Note

    For correct operation it is very important to forward any channelInactive event using this method at the right point in time, that is often when received.

    Declaration

    Swift

    public func fireChannelInactive()
  • Send data to the next inbound ChannelHandler. The data should be of type ChannelInboundHandler.InboundOut.

    Declaration

    Swift

    public func fireChannelRead(_ data: NIOAny)
  • Signal to the next ChannelHandler that a read burst has finished.

    Declaration

    Swift

    public func fireChannelReadComplete()
  • Send a writabilityChanged event to the next (inbound) ChannelHandler in the ChannelPipeline.

    Note

    For correct operation it is very important to forward any writabilityChanged event using this method at the right point in time, that is usually when received.

    Declaration

    Swift

    public func fireChannelWritabilityChanged()
  • Send an error to the next inbound ChannelHandler.

    Declaration

    Swift

    public func fireErrorCaught(_ error: Error)
  • Send a user event to the next inbound ChannelHandler.

    Declaration

    Swift

    public func fireUserInboundEventTriggered(_ event: Any)
  • Send a register event to the next (outbound) ChannelHandler in the ChannelPipeline.

    Note

    For correct operation it is very important to forward any register event using this method at the right point in time, that is usually when received.

    Declaration

    Swift

    public func register(promise: EventLoopPromise<Void>?)
  • Send a bind event to the next outbound ChannelHandler in the ChannelPipeline. When the bind event reaches the HeadChannelHandler a ServerSocketChannel will be bound.

    Declaration

    Swift

    public func bind(to address: SocketAddress, promise: EventLoopPromise<Void>?)

    Parameters

    address

    The address to bind to.

    promise

    The promise fulfilled when the socket is bound or failed if it cannot be bound.

  • Send a connect event to the next outbound ChannelHandler in the ChannelPipeline. When the connect event reaches the HeadChannelHandler a SocketChannel will be connected.

    Declaration

    Swift

    public func connect(to address: SocketAddress, promise: EventLoopPromise<Void>?)

    Parameters

    address

    The address to connect to.

    promise

    The promise fulfilled when the socket is connected or failed if it cannot be connected.

  • Send a write event to the next outbound ChannelHandler in the ChannelPipeline. When the write event reaches the HeadChannelHandler the data will be enqueued to be written on the next flush event.

    Declaration

    Swift

    public func write(_ data: NIOAny, promise: EventLoopPromise<Void>?)

    Parameters

    data

    The data to write, should be of type ChannelOutboundHandler.OutboundOut.

    promise

    The promise fulfilled when the data has been written or failed if it cannot be written.

  • Send a flush event to the next outbound ChannelHandler in the ChannelPipeline. When the flush event reaches the HeadChannelHandler the data previously enqueued will be attempted to be written to the socket.

    Declaration

    Swift

    public func flush()

    Parameters

    promise

    The promise fulfilled when the previously written data been flushed or failed if it cannot be flushed.

  • Send a write event followed by a flush event to the next outbound ChannelHandler in the ChannelPipeline. When the write event reaches the HeadChannelHandler the data will be enqueued to be written when the flush also reaches the HeadChannelHandler.

    Declaration

    Swift

    public func writeAndFlush(_ data: NIOAny, promise: EventLoopPromise<Void>?)

    Parameters

    data

    The data to write, should be of type ChannelOutboundHandler.OutboundOut.

    promise

    The promise fulfilled when the previously written data been written and flushed or if that failed.

  • Send a read event to the next outbound ChannelHandler in the ChannelPipeline. When the read event reaches the HeadChannelHandler the interest to read data will be signalled to the Selector. This will subsequently – when data becomes readable – cause channelRead events containing the data being sent through the ChannelPipeline.

    Declaration

    Swift

    public func read()
  • Send a close event to the next outbound ChannelHandler in the ChannelPipeline. When the close event reaches the HeadChannelHandler the socket will be closed.

    Declaration

    Swift

    public func close(mode: CloseMode = .all, promise: EventLoopPromise<Void>?)

    Parameters

    mode

    The CloseMode to use.

    promise

    The promise fulfilled when the Channel has been closed or failed if it the closing failed.

  • Send a user event to the next outbound ChannelHandler in the ChannelPipeline.

    Declaration

    Swift

    public func triggerUserOutboundEvent(_ event: Any, promise: EventLoopPromise<Void>?)

    Parameters

    event

    The user event to send.

    promise

    The promise fulfilled when the user event has been sent or failed if it couldn’t be sent.