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
  • Constructor Details

  • Method Details

    • setFrameSize

      public void setFrameSize(int sz)
    • newChannelBuilder

      public NioChannelBuilder newChannelBuilder(String name, ExecutorService es)
      Returns a ChannelBuilder that will add a channel to this hub.

      If the way the channel is built doesn't support NIO, the resulting Channel will use a separate thread to service its I/O.

    • close

      public void close() throws IOException
      Shuts down the selector thread and aborts all
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • 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.