Class ChannelGroup


  • public abstract class ChannelGroup
    extends java.lang.Object
    A grouping of channels for the purpose of resource sharing.

    A channel group encapsulates the mechanics required to handle the completion of I/O operations initiated by channels that are bound to the group. A group has an associated thread pool which polls IO events sent by the OS.

    • Constructor Detail

      • ChannelGroup

        public ChannelGroup()
    • Method Detail

      • withFixedThreadPool

        public static ChannelGroup withFixedThreadPool​(int nThreads,
                                                       java.util.concurrent.ThreadFactory threadFactory)
                                                throws java.io.IOException
        Creates a channel group with a fixed thread pool.

        The resulting channel group reuses a fixed number of threads. At any point, at most nThreads threads will be active processing tasks that are submitted to handle I/O events and dispatch completion results for operations initiated on channels in the group.

        Parameters:
        nThreads - The number of threads in the pool
        threadFactory - The factory to use when creating new threads
        Returns:
        A new asynchronous channel group
        Throws:
        java.lang.IllegalArgumentException - If nThreads <= 0
        java.io.IOException - If an I/O error occurs
      • withThreadPool

        public static ChannelGroup withThreadPool​(java.util.concurrent.ExecutorService executor)
                                           throws java.io.IOException
        Creates a channel group with a given thread pool.
        Parameters:
        executor - The thread pool for the resulting group
        Returns:
        A new asynchronous channel group
        Throws:
        java.io.IOException
      • shutdown

        public abstract void shutdown()
        Shutdown the channel group.