Package org.jenkinsci.remoting.nio
Class NioChannelHub
- java.lang.Object
-
- org.jenkinsci.remoting.nio.NioChannelHub
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Runnable
public class NioChannelHub extends Object implements Runnable, Closeable
Switch board of multipleChannel
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. Therun()
method will block until the hub gets closed.- Since:
- 2.38
- Author:
- Kohsuke Kawaguchi
-
-
Constructor Summary
Constructors Constructor Description NioChannelHub(ExecutorService commandProcessor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Shuts down the selector thread and aborts allvoid
ensureValid()
Verifies that the selector thread is running and this hub is active.Selector
getSelector()
NioChannelBuilder
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 Detail
-
NioChannelHub
public NioChannelHub(ExecutorService commandProcessor) throws IOException
- 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 Detail
-
setFrameSize
public void setFrameSize(int sz)
-
newChannelBuilder
public NioChannelBuilder newChannelBuilder(String name, ExecutorService es)
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
public void close() throws IOException
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
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.- Throws:
IOException
-
-