Class ChannelSet

java.lang.Object
io.servicetalk.transport.netty.internal.ChannelSet
All Implemented Interfaces:
AsyncCloseable, ListenableAsyncCloseable

public final class ChannelSet extends Object implements ListenableAsyncCloseable
Manages a set of Channels to provide a mechanism for closing all of them.

Channels are removed from the set when they are closed.

  • Field Details

    • CHANNEL_CLOSEABLE_KEY

      public static final io.netty.util.AttributeKey<io.servicetalk.transport.netty.internal.PrivilegedListenableAsyncCloseable> CHANNEL_CLOSEABLE_KEY
  • Constructor Details

    • ChannelSet

      public ChannelSet(Executor offloadingExecutor)
      New instance.
      Parameters:
      offloadingExecutor - Executor to use for offloading close signals or Executors.immediate() if close will not be offloaded.
  • Method Details

    • addIfAbsent

      public boolean addIfAbsent(io.netty.channel.Channel channel)
      Add a Channel to this ChannelSet, if it is not already present. Channel.id() is used to check uniqueness.
      Parameters:
      channel - The Channel to add.
      Returns:
      true if the channel was added successfully, false otherwise.
    • closeAsync

      public Completable closeAsync()
      Description copied from interface: AsyncCloseable
      Used to close/shutdown a resource.
      Specified by:
      closeAsync in interface AsyncCloseable
      Returns:
      A Completable that is notified once the close is complete.
    • closeAsyncGracefully

      public Completable closeAsyncGracefully()
      Description copied from interface: AsyncCloseable
      Used to close/shutdown a resource, similar to AsyncCloseable.closeAsync(), but attempts to cleanup state before abruptly closing. This provides a hint that implementations can use to stop accepting new work and finish in flight work. This method is implemented on a "best effort" basis and may be equivalent to AsyncCloseable.closeAsync().

      Note: Implementations may or may not apply a timeout for this operation to complete, if a caller does not want to wait indefinitely, and are unsure if the implementation applies a timeout, it is advisable to apply a timeout and force a call to AsyncCloseable.closeAsync().

      Specified by:
      closeAsyncGracefully in interface AsyncCloseable
      Returns:
      A Completable that is notified once the close is complete.
    • onClose

      public Completable onClose()
      Description copied from interface: ListenableAsyncCloseable
      Returns a Completable that is notified once the ListenableAsyncCloseable was closed.
      Specified by:
      onClose in interface ListenableAsyncCloseable
      Returns:
      the Completable that is notified on close.
    • onClosing

      public Completable onClosing()
      Description copied from interface: ListenableAsyncCloseable
      Returns a Completable that is notified when closing begins.

      Closing begin might be when a close operation is initiated locally (e.g. subscribing to AsyncCloseable.closeAsync()) or it could also be a transport event received from a remote peer (e.g. read a connection: close header).

      For backwards compatibility this method maybe functionally equivalent to ListenableAsyncCloseable.onClose(). Therefore, provides a best-effort leading edge notification of closing, but may fall back to notification on trailing edge.

      The goal of this method is often to notify asap when closing so this method may not be offloaded and care must be taken to avoid blocking if subscribing to the return Completable.

      Specified by:
      onClosing in interface ListenableAsyncCloseable
      Returns:
      a Completable that is notified when closing begins.