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 void
Reregister the provided key as interested in accepting connections.final void
Reregister the provided key as interested in the connection with a server being established.final void
Reregister the provided key as interested in reading data.final void
Reregister the provided key as interested in writing data.void
close()
static IOHub
Creates and starts a newIOHub
instance.boolean
void
Future<?>
executeLater
(Runnable task, long delay, TimeUnit units) Executes a task at a future point in time.void
executeOnSelector
(Runnable task) Executes the given task at some time in the future.final Selector
Returns theSelector
.int
hashCode()
boolean
isOpen()
Check if the hub is open.final Future<SelectionKey>
register
(SelectableChannel channel, IOHubReadyListener listener, boolean accept, boolean connect, boolean read, boolean write) Register theSelectableChannel
for the requested operations using the suppliedIOHubReadyListener
.final void
register
(SelectableChannel channel, IOHubReadyListener listener, boolean accept, boolean connect, boolean read, boolean write, IOHubRegistrationCallback callback) Register theSelectableChannel
for the requested operations using the suppliedIOHubReadyListener
, when the registration is complete theIOHubRegistrationCallback
will be invoked.void
release
(ByteBuffer buffer) Returns a buffer to the pool.final void
Reregister the provided key as no longer interested in accepting connections.final void
Reregister the provided key as no longer interested in the connection with a server being established.final void
Reregister the provided key as no longer interested in reading data.final void
Reregister the provided key as no longer interested in writing data.final void
run()
toString()
final void
unregister
(SelectableChannel channel) Removes theSelectableChannel
from the hub'sSelector
.
-
Method Details
-
create
Creates and starts a newIOHub
instance.- Parameters:
executor
- theExecutor
to use for running tasks.- Returns:
- the new hub.
- Throws:
IOException
- if the hub'sSelector
cannot be opened.
-
acquire
Borrow a buffer from the pool.- Specified by:
acquire
in interfaceByteBufferPool
- Parameters:
size
- The minimum size and initial limit of the buffer.- Returns:
- the buffer.
-
release
Returns a buffer to the pool.- Specified by:
release
in 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
Future
that 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:
true
if the hub is open.
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in 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 theSelectableChannel
for the requested operations using the suppliedIOHubReadyListener
, when the registration is complete theIOHubRegistrationCallback
will be invoked.- Parameters:
channel
- theSelectableChannel
to register.listener
- theIOHubReadyListener
to call when the requested operations are available.accept
-true
to initially register for accepting connections from clients.connect
-true
to initially register for connection established with server.read
-true
to initially register for reading data.write
-true
to initially register for writing data.callback
- theIOHubRegistrationCallback
to notify on registration.
-
register
public final Future<SelectionKey> register(SelectableChannel channel, IOHubReadyListener listener, boolean accept, boolean connect, boolean read, boolean write) Register theSelectableChannel
for the requested operations using the suppliedIOHubReadyListener
.- Parameters:
channel
- theSelectableChannel
to register.listener
- theIOHubReadyListener
to call when the requested operations are available.accept
-true
to initially register for accepting connections from clients.connect
-true
to initially register for connection established with server.read
-true
to initially register for reading data.write
-true
to initially register for writing data.- Returns:
- the
Future
for theSelectionKey
.
-
unregister
Removes theSelectableChannel
from the hub'sSelector
.- Parameters:
channel
- theSelectableChannel
to remove.
-
run
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public final void run() -
equals
-
hashCode
public int hashCode() -
toString
-