Package org.elasticsearch.nio
Interface ReadWriteHandler
-
- All Known Implementing Classes:
BytesWriteHandler
public interface ReadWriteHandlerImplements the application specific logic for handling inbound and outbound messages for a channel.
-
-
Method Summary
Modifier and Type Method Description voidclose()intconsumeReads(InboundChannelBuffer channelBuffer)This method handles bytes that have been read from the network.WriteOperationcreateWriteOperation(SocketChannelContext context, java.lang.Object message, java.util.function.BiConsumer<java.lang.Void,java.lang.Exception> listener)This method is called when a message is queued with a channel.java.util.List<FlushOperation>pollFlushOperations()Returns any flush operations that are ready to flush.java.util.List<FlushOperation>writeToBytes(WriteOperation writeOperation)This method is called on the event loop thread.
-
-
-
Method Detail
-
createWriteOperation
WriteOperation createWriteOperation(SocketChannelContext context, java.lang.Object message, java.util.function.BiConsumer<java.lang.Void,java.lang.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
java.util.List<FlushOperation> writeToBytes(WriteOperation writeOperation)
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
java.util.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
int consumeReads(InboundChannelBuffer channelBuffer) throws java.io.IOException
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:
java.io.IOException- if an exception occurs
-
close
void close() throws java.io.IOException- Throws:
java.io.IOException
-
-