Package org.elasticsearch.nio
Class ChannelContext<S extends SelectableChannel & NetworkChannel>
java.lang.Object
org.elasticsearch.nio.ChannelContext<S>
- Type Parameters:
S- the type of channel
- Direct Known Subclasses:
ServerChannelContext,SocketChannelContext
Implements the logic related to interacting with a java.nio channel. For example: registering with a
selector, managing the selection key, closing, etc is implemented by this class or its subclasses.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCloseListener(BiConsumer<Void, Exception> listener) Add a listener that will be called when the channel is closed.protected voidabstract voidSchedules a channel to be closed by the selector event loop with which it is registered.voidThis method cleans up any context resources that need to be released when a channel is closed.abstract NioChannelprotected SelectionKeyabstract NioSelectorprotected voidbooleanisOpen()protected voidregister()voidsetSelectionKey(SelectionKey selectionKey)
-
Field Details
-
rawChannel
-
-
Method Details
-
register
- Throws:
IOException
-
channelActive
- Throws:
IOException
-
getSelectionKey
-
setSelectionKey
-
closeFromSelector
This method cleans up any context resources that need to be released when a channel is closed. It should only be called by the selector thread.- Throws:
IOException- during channel / context close
-
addCloseListener
Add a listener that will be called when the channel is closed.- Parameters:
listener- to be called
-
isOpen
public boolean isOpen() -
handleException
-
closeChannel
public abstract void closeChannel()Schedules a channel to be closed by the selector event loop with which it is registered. If the channel is open and the state can be transitioned to closed, the close operation will be scheduled with the event loop. Depending on the underlying protocol of the channel, a close operation might simply close the socket channel or may involve reading and writing messages. -
getSelector
-
getChannel
-