Package org.elasticsearch.nio
Class NioSelector
java.lang.Object
org.elasticsearch.nio.NioSelector
- All Implemented Interfaces:
Closeable,AutoCloseable
This is a nio selector implementation. This selector wraps a raw nio
Selector. When you call
runLoop(), the selector will run until close() is called. This instance handles closing
of channels. Users should call queueChannelClose(NioChannel) to schedule a channel for close by
this selector.-
Constructor Summary
ConstructorsConstructorDescriptionNioSelector(EventHandler eventHandler) NioSelector(EventHandler eventHandler, Selector selector) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidclose()<V> voidexecuteFailedListener(BiConsumer<V, Exception> listener, Exception exception) Executes a failed listener with consistent exception handling.<V> voidexecuteListener(BiConsumer<V, Exception> listener, V value) Executes a success listener with consistent exception handling.Returns a cached direct byte buffer for network operations.booleanbooleanisOpen()booleanvoidqueueChannelClose(NioChannel channel) voidqueueWrite(WriteOperation writeOperation) Queues a write operation to be handled by the event loop.voidrunLoop()Starts this selector.voidscheduleForRegistration(NioChannel channel) Schedules a NioChannel to be registered with this selector.
-
Constructor Details
-
NioSelector
- Throws:
IOException
-
NioSelector
-
-
Method Details
-
getIoBuffer
Returns a cached direct byte buffer for network operations. It is cleared on every get call.- Returns:
- the byte buffer
-
getTaskScheduler
-
rawSelector
-
isOpen
public boolean isOpen() -
isRunning
public boolean isRunning() -
isOnCurrentThread
public boolean isOnCurrentThread() -
assertOnSelectorThread
public void assertOnSelectorThread() -
runLoop
public void runLoop()Starts this selector. The selector will run untilclose()is called. -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
queueWrite
Queues a write operation to be handled by the event loop. This can be called by any thread and is the api available for non-selector threads to schedule writes. When invoked from the selector thread the write will be executed right away.- Parameters:
writeOperation- to be queued
-
queueChannelClose
-
scheduleForRegistration
Schedules a NioChannel to be registered with this selector. The channel will by queued and eventually registered next time through the event loop.- Parameters:
channel- to register
-
executeListener
Executes a success listener with consistent exception handling. This can only be called from current selector thread.- Parameters:
listener- to be executedvalue- to provide to listener
-
executeFailedListener
Executes a failed listener with consistent exception handling. This can only be called from current selector thread.- Parameters:
listener- to be executedexception- to provide to listener
-