Package org.elasticsearch.nio
Interface NioChannelHandler
- All Known Implementing Classes:
BytesWriteHandler,DelegatingHandler
public interface NioChannelHandler
Implements the application specific logic for handling channel operations.
-
Method Summary
Modifier and TypeMethodDescriptionvoidThis method is called when the channel is active for use.voidclose()booleancloseNow()This method indicates if the underlying channel should be closed.intconsumeReads(InboundChannelBuffer channelBuffer) This method handles bytes that have been read from the network.createWriteOperation(SocketChannelContext context, Object message, BiConsumer<Void, Exception> listener) This method is called when a message is queued with a channel.Returns any flush operations that are ready to flush.writeToBytes(WriteOperation writeOperation) This method is called on the event loop thread.
-
Method Details
-
channelActive
void channelActive()This method is called when the channel is active for use. -
createWriteOperation
WriteOperation createWriteOperation(SocketChannelContext context, Object message, BiConsumer<Void, Exception> listener) This method is called when a message is queued with a channel. It can be called from any thread. This method should validate that the message is a valid type and return a write operation object to be queued with the channel- Parameters:
context- the channel contextmessage- the messagelistener- the listener to be called when the message is sent- Returns:
- the write operation to be queued
-
writeToBytes
This method is called on the event loop thread. It should serialize a write operation object to bytes that can be flushed to the raw nio channel.- Parameters:
writeOperation- to be converted to bytes- Returns:
- the operations to flush the bytes to the channel
-
pollFlushOperations
List<FlushOperation> pollFlushOperations()Returns any flush operations that are ready to flush. This exists as a way to check if any flush operations were produced during a read call.- Returns:
- flush operations
-
consumeReads
This method handles bytes that have been read from the network. It should return the number of bytes consumed so that they can be released.- Parameters:
channelBuffer- of bytes read from the network- Returns:
- the number of bytes consumed
- Throws:
IOException- if an exception occurs
-
closeNow
boolean closeNow()This method indicates if the underlying channel should be closed.- Returns:
- if the channel should be closed
-
close
- Throws:
IOException
-