protected static final class CancellableTimer.ScheduledEventHandler extends Object implements EventHandler, Closeable
| Modifier and Type | Method and Description |
|---|---|
boolean |
action()
Performs an action corresponding to some amount of work and returns a boolean indicating whether
it is expected that a subsequent call to this method would result in additional work being carried out.
|
void |
close() |
@NotNull HandlerPriority |
priority()
Returns the priority level of this event handler within the event loop.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waiteventLoop, loopFinished, loopStartedpublic boolean action()
throws InvalidEventHandlerException,
InvalidMarshallableException
VanillaEventHandler
This method is executed on the event loop's thread. A return value of true suggests to the event loop
that this handler should be serviced again shortly. However, the exact timing depends on various factors,
including the handler's priority and other activity on the event loop.
If an event handler returns true from action(), it biases the event loop to service the same
handler again "soon". How soon depends on a variety of factors and the other work the event loop has
to do across the other handlers.
Returning true when there is no actual work to do may waste cycles servicing a handler which has nothing
to do, at the expense of stealing cycles away from other handlers.
Conversely, returning false when there is work to do will effectively increase latency as the event loop
will take the "false" as a hint that several other handlers can be serviced ahead of this one.
As a rule of thumb, an action handler should do a certain amount of work then yield/return
If it knows for sure that there is remaining work to be done at the point of yielding then return true.
Otherwise return false and the event loop will revisit based on the handler's priority and other work load.
As with a lot of scheduling approaches there's no single answer and some experimentation under typical loads would always be recommended. But the above rule of thumb is a good starting point.
When the event handler is not required anymore and should be removed from the event loop, the
InvalidEventHandlerException.reusable() method returns a reusable pre-created
InvalidEventHandlerException which can be thrown to remove the EventHandler from the EventLoop.
action in interface VanillaEventHandlertrue if it is expected that there is more work to be done imminently; false otherwise.InvalidEventHandlerException - when the event handler is not required anymore and should be removed from
the event loop.
It is recommended to throw this exception if the event handler is closed.
The InvalidEventHandlerException.reusable() method returns a reusable, pre-created,
InvalidEventHandlerException that is unmodifiable and contains no stack trace.
See InvalidEventHandlerException.reusable().InvalidMarshallableException - if there is a failure in the validation of a DTO being read or written.@NotNull public @NotNull HandlerPriority priority()
EventHandlerpriority in interface EventHandlerpublic void close()
close in interface Closeableclose in interface AutoCloseableCopyright © 2024. All rights reserved.