Class NioChannelHub

  • All Implemented Interfaces:
    Closeable, AutoCloseable, Runnable

    public class NioChannelHub
    extends Object
    implements Runnable, Closeable
    Switch board of multiple Channels through NIO select. Through this hub, N threads can attend to M channels with a help of one selector thread.

    To get the selector thread going, call the run() method from a thread after you instantiate this object. The run() method will block until the hub gets closed.

    Kohsuke Kawaguchi
    • Method Detail

      • setFrameSize

        public void setFrameSize​(int sz)
      • run

        public void run()
        Attend to channels in the hub. This method returns when close() is called and the selector is shut down.
        Specified by:
        run in interface Runnable
      • onSelected

        protected void onSelected​(SelectionKey key)
        Called when the unknown key registered to the selector is selected.
      • getSelector

        public Selector getSelector()
      • ensureValid

        public void ensureValid()
                         throws IOException
        Verifies that the selector thread is running and this hub is active. Several bugs have been reported (such as JENKINS-24050) that causes the selector thread to die, and several more bugs have been reported (such as JENKINS-24155 and JENKINS-24201) that are suspected to be caused by the death of NIO selector thread. This check makes it easier to find this problem and report why the selector thread has died.