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
Channel
s 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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Shuts down the selector thread and aborts allvoid
Verifies that the selector thread is running and this hub is active.newChannelBuilder
(String name, ExecutorService es) Returns aChannelBuilder
that will add a channel to this hub.protected void
onSelected
(SelectionKey key) Called when the unknown key registered to the selector is selected.void
run()
Attend to channels in the hub.void
setFrameSize
(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 aChannelBuilder
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
Shuts down the selector thread and aborts all- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in 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
-