Package org.jenkinsci.remoting.protocol
Class IOHub
java.lang.Object
org.jenkinsci.remoting.protocol.IOHub
- All Implemented Interfaces:
Closeable,AutoCloseable,Runnable,Executor,ByteBufferPool
A hub for performing I/O. The hub has a selector thread and an executor service.
- Since:
- 3.0
-
Method Summary
Modifier and TypeMethodDescriptionacquire(int size) Borrow a buffer from the pool.final voidReregister the provided key as interested in accepting connections.final voidReregister the provided key as interested in the connection with a server being established.final voidReregister the provided key as interested in reading data.final voidReregister the provided key as interested in writing data.voidclose()static IOHubCreates and starts a newIOHubinstance.booleanvoidFuture<?>executeLater(Runnable task, long delay, TimeUnit units) Executes a task at a future point in time.voidexecuteOnSelector(Runnable task) Executes the given task at some time in the future.final SelectorReturns theSelector.inthashCode()booleanisOpen()Check if the hub is open.final Future<SelectionKey>register(SelectableChannel channel, IOHubReadyListener listener, boolean accept, boolean connect, boolean read, boolean write) Register theSelectableChannelfor the requested operations using the suppliedIOHubReadyListener.final voidregister(SelectableChannel channel, IOHubReadyListener listener, boolean accept, boolean connect, boolean read, boolean write, IOHubRegistrationCallback callback) Register theSelectableChannelfor the requested operations using the suppliedIOHubReadyListener, when the registration is complete theIOHubRegistrationCallbackwill be invoked.voidrelease(ByteBuffer buffer) Returns a buffer to the pool.final voidReregister the provided key as no longer interested in accepting connections.final voidReregister the provided key as no longer interested in the connection with a server being established.final voidReregister the provided key as no longer interested in reading data.final voidReregister the provided key as no longer interested in writing data.final voidrun()toString()final voidunregister(SelectableChannel channel) Removes theSelectableChannelfrom the hub'sSelector.
-
Method Details
-
create
Creates and starts a newIOHubinstance.- Parameters:
executor- theExecutorto use for running tasks.- Returns:
- the new hub.
- Throws:
IOException- if the hub'sSelectorcannot be opened.
-
acquire
Borrow a buffer from the pool.- Specified by:
acquirein interfaceByteBufferPool- Parameters:
size- The minimum size and initial limit of the buffer.- Returns:
- the buffer.
-
release
Returns a buffer to the pool.- Specified by:
releasein interfaceByteBufferPool- Parameters:
buffer- the buffer.
-
getSelector
Returns theSelector.- Returns:
- the
Selector
-
execute
-
executeOnSelector
Executes the given task at some time in the future. The task will execute in the selector thread.- Parameters:
task- the runnable task- Throws:
RejectedExecutionException- if this task cannot be accepted for executionNullPointerException- if task is null
-
executeLater
Executes a task at a future point in time. The scheduling is handled by the selector thread, and as such this method should not be used for timing critical scheduling, rather it is intended to be used for things such as protocol timeouts.- Parameters:
task- the task.delay- the delay.units- the time units for the delay.- Returns:
- a
Futurethat completes when the task has run and can be used to cancel the execution. - Throws:
RejectedExecutionException- if this task cannot be accepted for executionNullPointerException- if task is null
-
isOpen
@OverrideMustInvoke public boolean isOpen()Check if the hub is open.- Returns:
trueif the hub is open.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
addInterestAccept
Reregister the provided key as interested in accepting connections.- Parameters:
key- the key.
-
removeInterestAccept
Reregister the provided key as no longer interested in accepting connections.- Parameters:
key- the key.
-
addInterestConnect
Reregister the provided key as interested in the connection with a server being established.- Parameters:
key- the key.
-
removeInterestConnect
Reregister the provided key as no longer interested in the connection with a server being established.- Parameters:
key- the key.
-
addInterestRead
Reregister the provided key as interested in reading data.- Parameters:
key- the key.
-
removeInterestRead
Reregister the provided key as no longer interested in reading data.- Parameters:
key- the key.
-
addInterestWrite
Reregister the provided key as interested in writing data.- Parameters:
key- the key.
-
removeInterestWrite
Reregister the provided key as no longer interested in writing data.- Parameters:
key- the key.
-
register
public final void register(SelectableChannel channel, IOHubReadyListener listener, boolean accept, boolean connect, boolean read, boolean write, IOHubRegistrationCallback callback) Register theSelectableChannelfor the requested operations using the suppliedIOHubReadyListener, when the registration is complete theIOHubRegistrationCallbackwill be invoked.- Parameters:
channel- theSelectableChannelto register.listener- theIOHubReadyListenerto call when the requested operations are available.accept-trueto initially register for accepting connections from clients.connect-trueto initially register for connection established with server.read-trueto initially register for reading data.write-trueto initially register for writing data.callback- theIOHubRegistrationCallbackto notify on registration.
-
register
public final Future<SelectionKey> register(SelectableChannel channel, IOHubReadyListener listener, boolean accept, boolean connect, boolean read, boolean write) Register theSelectableChannelfor the requested operations using the suppliedIOHubReadyListener.- Parameters:
channel- theSelectableChannelto register.listener- theIOHubReadyListenerto call when the requested operations are available.accept-trueto initially register for accepting connections from clients.connect-trueto initially register for connection established with server.read-trueto initially register for reading data.write-trueto initially register for writing data.- Returns:
- the
Futurefor theSelectionKey.
-
unregister
Removes theSelectableChannelfrom the hub'sSelector.- Parameters:
channel- theSelectableChannelto remove.
-
run
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public final void run() -
equals
-
hashCode
public int hashCode() -
toString
-