Package reactor.netty

Interface Connection

All Superinterfaces:
Disposable, DisposableChannel
All Known Subinterfaces:
QuicConnection
All Known Implementing Classes:
ChannelOperations, HttpOperations
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Connection extends DisposableChannel
Hold contextual information for the underlying Channel.
Since:
0.8
Author:
Stephane Maldini
  • Method Details

    • from

      static Connection from(Channel channel)
      Return an existing Connection wrapper or create a simple new one.
      Parameters:
      channel - channel to retrieve the connection reference from
      Returns:
      an existing Connection wrapper or create a simple new one
    • as

      default <T extends Connection> @Nullable T as(Class<T> clazz)
      Return an existing Connection that must match the given type wrapper or null.
      Parameters:
      clazz - connection type to match to
      Returns:
      a matching Connection reference or null
    • addHandler

      @Deprecated default Connection addHandler(ChannelHandler handler)
      Deprecated.
      as of 1.0.17. Use addHandlerFirst(ChannelHandler) or addHandlerLast(ChannelHandler). This method will be removed in version 1.2.0.
      Add a ChannelHandler with addHandlerFirst(io.netty.channel.ChannelHandler) if of type of ChannelOutboundHandler otherwise with addHandlerLast(io.netty.channel.ChannelHandler). Implementation may add more auto handling in particular HTTP based context will prepend an HttpContent body extractor.

      [ [reactor codecs], [<- user FIRST HANDLERS added here, user LAST HANDLERS added here ->], [reactor handlers] ]

      If effectively added, the handler will be safely removed when the channel is made inactive (pool release). As the Connection object is available once the channel is in active state, events prior this state will not be available (i.e. channelRegistered, initChannel, channelActive, etc.)

      Parameters:
      handler - handler instance
      Returns:
      this Connection
    • addHandler

      @Deprecated default Connection addHandler(String name, ChannelHandler handler)
      Deprecated.
      as of 1.0.17. Use addHandlerFirst(String, ChannelHandler) or addHandlerLast(String, ChannelHandler). This method will be removed in version 1.2.0.
      Add a ChannelHandler with addHandlerFirst(io.netty.channel.ChannelHandler) if of type of ChannelOutboundHandler otherwise with addHandlerLast(io.netty.channel.ChannelHandler). Implementation may add more auto handling in particular HTTP based context will prepend an HttpContent body extractor.

      [ [reactor codecs], [<- user FIRST HANDLERS added here, user LAST HANDLERS added here ->], [reactor handlers] ]

      If effectively added, the handler will be safely removed when the channel is made inactive (pool release). As the Connection object is available once the channel is in active state, events prior this state will not be available (i.e. channelRegistered, initChannel, channelActive, etc.)

      Parameters:
      name - handler name
      handler - handler instance
      Returns:
      this Connection
    • addHandlerLast

      default Connection addHandlerLast(ChannelHandler handler)
      Add a ChannelHandler to the end of the "user" ChannelPipeline, that is just before the reactor-added handlers like NettyPipeline.ReactiveBridge. If a handler with a similar name already exists, this operation is skipped.

      [ [reactor codecs], [<- user FIRST HANDLERS added here, user LAST HANDLERS added here ->], [reactor handlers] ]

      If effectively added, the handler will be safely removed when the channel is made inactive (pool release). As the Connection object is available once the channel is in active state, events prior this state will not be available (i.e. channelRegistered, initChannel, channelActive, etc.)

      Parameters:
      handler - handler instance
      Returns:
      this Connection
    • addHandlerLast

      default Connection addHandlerLast(String name, ChannelHandler handler)
      Add a ChannelHandler to the end of the "user" ChannelPipeline, that is just before the reactor-added handlers like NettyPipeline.ReactiveBridge. If a handler with a similar name already exists, this operation is skipped.

      [ [reactor codecs], [<- user FIRST HANDLERS added here, user LAST HANDLERS added here ->], [reactor handlers] ]

      If effectively added, the handler will be safely removed when the channel is made inactive (pool release). As the Connection object is available once the channel is in active state, events prior this state will not be available (i.e. channelRegistered, initChannel, channelActive, etc.)

      Parameters:
      name - handler name
      handler - handler instance
      Returns:
      this Connection
    • addHandlerFirst

      default Connection addHandlerFirst(ChannelHandler handler)
      Add a ChannelHandler to the beginning of the "user" ChannelPipeline, that is just after the reactor-added codecs. If a handler with a similar name already exists, this operation is skipped.

      [ [reactor codecs], [<- user FIRST HANDLERS added here, user LAST HANDLERS added here ->], [reactor handlers] ].

      If effectively added, the handler will be safely removed when the channel is made inactive (pool release). As the Connection object is available once the channel is in active state, events prior this state will not be available (i.e. channelRegistered, initChannel, channelActive, etc.)

      Parameters:
      handler - handler instance
      Returns:
      this Connection
    • addHandlerFirst

      default Connection addHandlerFirst(String name, ChannelHandler handler)
      Add a ChannelHandler to the beginning of the "user" ChannelPipeline, that is just after the reactor-added codecs. If a handler with a similar name already exists, this operation is skipped.

      [ [reactor codecs], [<- user FIRST HANDLERS added here, user LAST HANDLERS added here ->], [reactor handlers] ]

      If effectively added, the handler will be safely removed when the channel is made inactive (pool release). As the Connection object is available once the channel is in active state, events prior this state will not be available (i.e. channelRegistered, initChannel, channelActive, etc.)

      Parameters:
      name - handler name
      handler - handler instance
      Returns:
      this Connection
    • bind

      default Connection bind()
      Bind the Connection to the channel scope via an attribute. Can be retrieved later by from(io.netty.channel.Channel). If a previous reference Connection was bound, this instance will take precedence.
      Returns:
      this Connection.
    • inbound

      default NettyInbound inbound()
      Return the NettyInbound read API from this connection. If Connection has not been configured with a supporting bridge, receive operations will be unavailable.
      Returns:
      the NettyInbound read API from this connection.
    • isPersistent

      default boolean isPersistent()
      Return false if it will force a close on terminal protocol events thus defeating any pooling strategy Return true (default) if it will release on terminal protocol events thus keeping alive the channel if possible.
      Returns:
      whether the underlying Connection will be disposed on terminal handler event
    • markPersistent

      default Connection markPersistent(boolean persist)
      Mark the underlying channel as persistent or not. If false, it will force a close on terminal protocol events thus defeating any pooling strategy if true (default), it will release on terminal protocol events thus keeping alive the channel if possible.
      Parameters:
      persist - the boolean flag to mark the Channel as fully disposable or reusable when a user handler has terminated
      Returns:
      this Connection
    • onDispose

      default Connection onDispose(Disposable onDispose)
      Description copied from interface: DisposableChannel
      Assigns a Disposable to be invoked when the channel is closed.
      Specified by:
      onDispose in interface DisposableChannel
      Parameters:
      onDispose - the close event handler
      Returns:
      this
    • onReadIdle

      default Connection onReadIdle(long idleTimeout, Runnable onReadIdle)
      Assign a Runnable to be invoked when reads have become idle for the given timeout. This replaces any previously set idle callback.
      Parameters:
      idleTimeout - the idle timeout
      onReadIdle - the idle timeout handler
      Returns:
      this
    • onTerminate

      default Mono<Void> onTerminate()
      Return a Mono succeeding when a Connection is not used anymore by any current operations. A typical example is when a pooled connection is released or an operations bridge has terminated.
      Returns:
      a Mono succeeding when a Connection has been terminated
    • onWriteIdle

      default Connection onWriteIdle(long idleTimeout, Runnable onWriteIdle)
      Assign a Runnable to be invoked when writes have become idle for the given timeout. This replaces any previously set idle callback.
      Parameters:
      idleTimeout - the idle timeout
      onWriteIdle - the idle timeout handler
      Returns:
      this
    • outbound

      default NettyOutbound outbound()
      Return the NettyOutbound write API from this connection. If Connection has not been configured with a supporting bridge, send operations will be unavailable.
      Returns:
      the NettyOutbound read API from this connection.
    • rebind

      default boolean rebind(@Nullable Connection connection)
      Bind a new Connection reference or null to the channel attributes only if this instance is currently bound.
      Parameters:
      connection - a new connection reference
      Returns:
      true if bound
      See Also:
    • removeHandler

      default Connection removeHandler(String name)
      Remove a named handler if present and return this context.
      Parameters:
      name - handler name
      Returns:
      this Connection
    • replaceHandler

      default Connection replaceHandler(String name, ChannelHandler handler)
      Replace a named handler if present and return this context. If handler wasn't present, an RuntimeException will be thrown.

      Note: if the new handler is of different type, dependent handling like the "extractor" introduced via HTTP-based addHandler(io.netty.channel.ChannelHandler) might not expect/support the new messages type.

      Parameters:
      name - handler name
      Returns:
      this Connection