@FunctionalInterface public interface EventHandler extends VanillaEventHandler
This interface should be implemented by classes that handle specific events within an event loop.
An EventHandler
can be registered to an EventLoop
for processing events.
Modifier and Type | Method and Description |
---|---|
default void |
eventLoop(EventLoop eventLoop)
This method is called once when it is added to an eventLoop, which might be before the EventLoop has started
This could be called in any thread.
|
default void |
loopFinished()
Notify handler that the event handler's action method will not be called again.
|
default void |
loopStarted()
This handler has begun being executed on the event loop.
|
default @NotNull HandlerPriority |
priority()
Returns the priority level of this event handler within the event loop.
|
action
default void eventLoop(EventLoop eventLoop)
eventLoop
- The event loop to which this handler has been added.default void loopStarted()
eventLoop(EventLoop)
and will always be called on the EventLoop thread.
This call will be followed by zero or more invocations of VanillaEventHandler.action()
and then an invocation of loopFinished()
Exceptions thrown by loopStarted will be logged and the handler will be removed from the event loop.
default void loopFinished()
loopStarted()
was called, and will always be called on the event loop thread.
This is called either when the event loop is terminating, or if this EventHandler is being removed from the event loop.
If this handler implements Closeable
then the event loop will call close (once only) on this after
loopFinished has been called.
loopFinished is the place to put any clean-up that MUST be performed on the event loop thread, or
cleanup that only needs to occur if loopStarted()
was called. All other clean up can be put into
Closeable.close()
.
Exceptions thrown by loopFinished or close are caught and logged (at warning level) and cleanup continues.
@NotNull default @NotNull HandlerPriority priority()
Copyright © 2023. All rights reserved.