public class IOHub extends Object implements Executor, Closeable, Runnable, ByteBufferPool
| Modifier and Type | Method and Description |
|---|---|
ByteBuffer |
acquire(int size)
Borrow a buffer from the pool.
|
void |
addInterestAccept(SelectionKey key)
Reregister the provided key as interested in accepting connections.
|
void |
addInterestConnect(SelectionKey key)
Reregister the provided key as interested in the connection with a server being established.
|
void |
addInterestRead(SelectionKey key)
Reregister the provided key as interested in reading data.
|
void |
addInterestWrite(SelectionKey key)
Reregister the provided key as interested in writing data.
|
void |
close() |
static IOHub |
create(Executor executor)
Creates and starts a new
IOHub instance. |
boolean |
equals(Object o) |
void |
execute(Runnable task) |
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.
|
Selector |
getSelector()
Returns the
Selector. |
int |
hashCode() |
boolean |
isOpen()
Check if the hub is open.
|
Future<SelectionKey> |
register(SelectableChannel channel,
IOHubReadyListener listener,
boolean accept,
boolean connect,
boolean read,
boolean write)
Register the
SelectableChannel for the requested operations using the supplied
IOHubReadyListener. |
void |
register(SelectableChannel channel,
IOHubReadyListener listener,
boolean accept,
boolean connect,
boolean read,
boolean write,
IOHubRegistrationCallback callback)
Register the
SelectableChannel for the requested operations using the supplied
IOHubReadyListener, when the registration is complete the IOHubRegistrationCallback will be
invoked. |
void |
release(ByteBuffer buffer)
Returns a buffer to the pool.
|
void |
removeInterestAccept(SelectionKey key)
Reregister the provided key as no longer interested in accepting connections.
|
void |
removeInterestConnect(SelectionKey key)
Reregister the provided key as no longer interested in the connection with a server being established.
|
void |
removeInterestRead(SelectionKey key)
Reregister the provided key as no longer interested in reading data.
|
void |
removeInterestWrite(SelectionKey key)
Reregister the provided key as no longer interested in writing data.
|
void |
run() |
String |
toString() |
void |
unregister(SelectableChannel channel)
Removes the
SelectableChannel from the hub's Selector. |
public static IOHub create(Executor executor) throws IOException
IOHub instance.executor - the Executor to use for running tasks.IOException - if the hub's Selector cannot be opened.public ByteBuffer acquire(int size)
acquire in interface ByteBufferPoolsize - The minimum size and initial limit of the buffer.public void release(ByteBuffer buffer)
release in interface ByteBufferPoolbuffer - the buffer.@Nonnull public final Selector getSelector()
Selector.Selector@OverridingMethodsMustInvokeSuper public void execute(Runnable task)
@OverridingMethodsMustInvokeSuper public void executeOnSelector(Runnable task)
task - the runnable taskRejectedExecutionException - if this task cannot be accepted for executionNullPointerException - if task is null@OverridingMethodsMustInvokeSuper public Future<?> executeLater(Runnable task, long delay, TimeUnit units)
task - the task.delay - the delay.units - the time units for the delay.Future that completes when the task has run and can be used to cancel the execution.RejectedExecutionException - if this task cannot be accepted for executionNullPointerException - if task is null@OverridingMethodsMustInvokeSuper public boolean isOpen()
true if the hub is open.@OverridingMethodsMustInvokeSuper public void close() throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic final void addInterestAccept(SelectionKey key)
key - the key.public final void removeInterestAccept(SelectionKey key)
key - the key.public final void addInterestConnect(SelectionKey key)
key - the key.public final void removeInterestConnect(SelectionKey key)
key - the key.public final void addInterestRead(SelectionKey key)
key - the key.public final void removeInterestRead(SelectionKey key)
key - the key.public final void addInterestWrite(SelectionKey key)
key - the key.public final void removeInterestWrite(SelectionKey key)
key - the key.public final void register(SelectableChannel channel, IOHubReadyListener listener, boolean accept, boolean connect, boolean read, boolean write, IOHubRegistrationCallback callback)
SelectableChannel for the requested operations using the supplied
IOHubReadyListener, when the registration is complete the IOHubRegistrationCallback will be
invoked.channel - the SelectableChannel to register.listener - the IOHubReadyListener 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 - the IOHubRegistrationCallback to notify on registration.public final Future<SelectionKey> register(SelectableChannel channel, IOHubReadyListener listener, boolean accept, boolean connect, boolean read, boolean write)
SelectableChannel for the requested operations using the supplied
IOHubReadyListener.channel - the SelectableChannel to register.listener - the IOHubReadyListener 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.Future for the SelectionKey.public final void unregister(SelectableChannel channel)
SelectableChannel from the hub's Selector.channel - the SelectableChannel to remove.@Restricted(value=org.kohsuke.accmod.restrictions.NoExternalUse.class) public final void run()
Copyright © 2004–2020. All rights reserved.