Package org.elasticsearch.nio
Class EventHandler
- java.lang.Object
-
- org.elasticsearch.nio.EventHandler
-
public class EventHandler extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.function.Consumer<java.lang.Exception>exceptionHandler
-
Constructor Summary
Constructors Constructor Description EventHandler(java.util.function.Consumer<java.lang.Exception> exceptionHandler, java.util.function.Supplier<NioSelector> selectorSupplier)
-
Method Summary
Modifier and Type Method Description protected voidacceptChannel(ServerChannelContext context)This method is called when a server channel signals it is ready to accept a connection.protected voidacceptException(ServerChannelContext context, java.lang.Exception exception)This method is called when an attempt to accept a connection throws an exception.protected voidcloseException(ChannelContext<?> context, java.lang.Exception exception)This method is called when an attempt to close a channel throws an exception.protected voidconnectException(SocketChannelContext context, java.lang.Exception exception)This method is called when an attempt to connect a channel throws an exception.protected voidgenericChannelException(ChannelContext<?> context, java.lang.Exception exception)This method is called when handling an event from a channel fails due to an unexpected exception.protected voidhandleClose(ChannelContext<?> context)This method handles the closing of an NioChannelprotected voidhandleConnect(SocketChannelContext context)This method is called when a NioSocketChannel has just been accepted or if it has receive an OP_CONNECT event.protected voidhandleRead(SocketChannelContext context)This method is called when a channel signals it is ready for be read.protected voidhandleRegistration(ChannelContext<?> context)This method is called when a NioChannel is being registered with the selector.protected voidhandleTask(java.lang.Runnable task)This method is called when a task or listener attached to a channel is available to run.protected voidhandleWrite(SocketChannelContext context)This method is called when a channel signals it is ready to receive writes.protected voidpostHandling(SocketChannelContext context)This method is called after events (READ, WRITE, CONNECT) have been handled for a channel.protected voidreadException(SocketChannelContext context, java.lang.Exception exception)This method is called when an attempt to read from a channel throws an exception.protected voidregistrationException(ChannelContext<?> context, java.lang.Exception exception)This method is called when an attempt to register a channel throws an exception.protected voidselectorException(java.io.IOException exception)This method handles an IOException that was thrown during a call toSelector.select(long)orSelector.close().protected voidtaskException(java.lang.Exception exception)This method is called when a task or listener attached to a channel operation throws an exception.protected voiduncaughtException(java.lang.Exception exception)This method handles an exception that was uncaught during a select loop.protected voidwriteException(SocketChannelContext context, java.lang.Exception exception)This method is called when an attempt to write to a channel throws an exception.
-
-
-
Constructor Detail
-
EventHandler
public EventHandler(java.util.function.Consumer<java.lang.Exception> exceptionHandler, java.util.function.Supplier<NioSelector> selectorSupplier)
-
-
Method Detail
-
acceptChannel
protected void acceptChannel(ServerChannelContext context) throws java.io.IOException
This method is called when a server channel signals it is ready to accept a connection. All of the accept logic should occur in this call.- Parameters:
context- that can accept a connection- Throws:
java.io.IOException
-
acceptException
protected void acceptException(ServerChannelContext context, java.lang.Exception exception)
This method is called when an attempt to accept a connection throws an exception.- Parameters:
context- that accepting a connectionexception- that occurred
-
handleRegistration
protected void handleRegistration(ChannelContext<?> context) throws java.io.IOException
This method is called when a NioChannel is being registered with the selector. It should only be called once per channel.- Parameters:
context- that was registered- Throws:
java.io.IOException
-
registrationException
protected void registrationException(ChannelContext<?> context, java.lang.Exception exception)
This method is called when an attempt to register a channel throws an exception.- Parameters:
context- that was registeredexception- that occurred
-
handleConnect
protected void handleConnect(SocketChannelContext context) throws java.io.IOException
This method is called when a NioSocketChannel has just been accepted or if it has receive an OP_CONNECT event.- Parameters:
context- that was registered- Throws:
java.io.IOException
-
connectException
protected void connectException(SocketChannelContext context, java.lang.Exception exception)
This method is called when an attempt to connect a channel throws an exception.- Parameters:
context- that was connectingexception- that occurred
-
handleRead
protected void handleRead(SocketChannelContext context) throws java.io.IOException
This method is called when a channel signals it is ready for be read. All of the read logic should occur in this call.- Parameters:
context- that can be read- Throws:
java.io.IOException
-
readException
protected void readException(SocketChannelContext context, java.lang.Exception exception)
This method is called when an attempt to read from a channel throws an exception.- Parameters:
context- that was being readexception- that occurred
-
handleWrite
protected void handleWrite(SocketChannelContext context) throws java.io.IOException
This method is called when a channel signals it is ready to receive writes. All of the write logic should occur in this call.- Parameters:
context- that can be written to- Throws:
java.io.IOException
-
writeException
protected void writeException(SocketChannelContext context, java.lang.Exception exception)
This method is called when an attempt to write to a channel throws an exception.- Parameters:
context- that was being written toexception- that occurred
-
handleTask
protected void handleTask(java.lang.Runnable task)
This method is called when a task or listener attached to a channel is available to run.- Parameters:
task- to handle
-
taskException
protected void taskException(java.lang.Exception exception)
This method is called when a task or listener attached to a channel operation throws an exception.- Parameters:
exception- that occurred
-
postHandling
protected void postHandling(SocketChannelContext context)
This method is called after events (READ, WRITE, CONNECT) have been handled for a channel.- Parameters:
context- that was handled
-
selectorException
protected void selectorException(java.io.IOException exception)
This method handles an IOException that was thrown during a call toSelector.select(long)orSelector.close().- Parameters:
exception- the exception
-
uncaughtException
protected void uncaughtException(java.lang.Exception exception)
This method handles an exception that was uncaught during a select loop.- Parameters:
exception- that was uncaught
-
handleClose
protected void handleClose(ChannelContext<?> context) throws java.io.IOException
This method handles the closing of an NioChannel- Parameters:
context- that should be closed- Throws:
java.io.IOException
-
closeException
protected void closeException(ChannelContext<?> context, java.lang.Exception exception)
This method is called when an attempt to close a channel throws an exception.- Parameters:
context- that was being closedexception- that occurred
-
genericChannelException
protected void genericChannelException(ChannelContext<?> context, java.lang.Exception exception)
This method is called when handling an event from a channel fails due to an unexpected exception. An example would be if checking ready ops on aSelectionKeythrewCancelledKeyException.- Parameters:
context- that caused the exceptionexception- that was thrown
-
-