Package org.jenkinsci.remoting.nio
Class NioChannelHub
java.lang.Object
org.jenkinsci.remoting.nio.NioChannelHub
- All Implemented Interfaces:
Closeable,AutoCloseable,Runnable
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.
- Since:
- 2.38
- Author:
- Kohsuke Kawaguchi
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Shuts down the selector thread and aborts allvoidVerifies that the selector thread is running and this hub is active.newChannelBuilder(String name, ExecutorService es) Returns aChannelBuilderthat will add a channel to this hub.protected voidonSelected(SelectionKey key) Called when the unknown key registered to the selector is selected.voidrun()Attend to channels in the hub.voidsetFrameSize(int sz)
-
Constructor Details
-
NioChannelHub
- Parameters:
commandProcessor- Executor pool that delivers received command packets toAbstractByteArrayCommandTransport.ByteArrayReceiver. This pool will handle the deserialization (which may block due to classloading from the other side).- Throws:
IOException
-
-
Method Details
-
setFrameSize
public void setFrameSize(int sz) -
newChannelBuilder
Returns aChannelBuilderthat will add a channel to this hub.If the way the channel is built doesn't support NIO, the resulting
Channelwill use a separate thread to service its I/O. -
close
Shuts down the selector thread and aborts all- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
run
public void run()Attend to channels in the hub. This method returns whenclose()is called and the selector is shut down. -
onSelected
Called when the unknown key registered to the selector is selected. -
getSelector
-
ensureValid
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.- Throws:
IOException
-