Reintroduce sync event execution to the Velocity event system
This required a not-insubstantial number of bug fixes, since the sync support had bit-rotted somewhat. This PR also corrects a number of bugs. Finally. the per-plugin executor services are now used to execute all async event tasks.
This commit is contained in:
@@ -45,10 +45,28 @@ public interface EventManager {
|
||||
* @param postOrder the order in which events should be posted to the handler
|
||||
* @param handler the handler to register
|
||||
* @param <E> the event type to handle
|
||||
* @deprecated use {@link #register(Object, Class, short, EventHandler)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
<E> void register(Object plugin, Class<E> eventClass, PostOrder postOrder,
|
||||
EventHandler<E> handler);
|
||||
|
||||
/**
|
||||
* Requests that the specified {@code handler} listen for events and associate it with the {@code
|
||||
* plugin}.
|
||||
*
|
||||
* <p>Note that this method will register a non-asynchronous listener by default. If you want to
|
||||
* use an asynchronous event handler, return {@link EventTask#async(Runnable)} from the handler.</p>
|
||||
*
|
||||
* @param plugin the plugin to associate with the handler
|
||||
* @param eventClass the class for the event handler to register
|
||||
* @param postOrder the relative order in which events should be posted to the handler
|
||||
* @param handler the handler to register
|
||||
* @param <E> the event type to handle
|
||||
*/
|
||||
<E> void register(Object plugin, Class<E> eventClass, short postOrder,
|
||||
EventHandler<E> handler);
|
||||
|
||||
/**
|
||||
* Fires the specified event to the event bus asynchronously. This allows Velocity to continue
|
||||
* servicing connections while a plugin handles a potentially long-running operation such as a
|
||||
|
@@ -12,6 +12,6 @@ package com.velocitypowered.api.event;
|
||||
*/
|
||||
public enum PostOrder {
|
||||
|
||||
FIRST, EARLY, NORMAL, LATE, LAST
|
||||
FIRST, EARLY, NORMAL, LATE, LAST, CUSTOM
|
||||
|
||||
}
|
||||
|
@@ -22,24 +22,38 @@ public @interface Subscribe {
|
||||
/**
|
||||
* The order events will be posted to this listener.
|
||||
*
|
||||
* @deprecated specify the order using {@link #priority()} instead
|
||||
* @return the order
|
||||
*/
|
||||
@Deprecated
|
||||
PostOrder order() default PostOrder.NORMAL;
|
||||
|
||||
/**
|
||||
* Whether the handler must be called asynchronously.
|
||||
* The priority of this event handler. Priorities are used to determine the order in which event
|
||||
* handlers are called. The higher the priority, the earlier the event handler will be called.
|
||||
*
|
||||
* <p><strong>This option currently has no effect, but in the future it will. In Velocity 3.0.0,
|
||||
* all event handlers run asynchronously by default. You are encouraged to determine whether or
|
||||
* not to enable it now. This option is being provided as a migration aid.</strong></p>
|
||||
* <p>Note that due to compatibility constraints, you must specify {@link PostOrder#CUSTOM}
|
||||
* in order to use this field.</p>
|
||||
*
|
||||
* <p>If this method returns {@code true}, the method is guaranteed to be executed
|
||||
* asynchronously. Otherwise, the handler may be executed on the current thread or
|
||||
* asynchronously. <strong>This still means you must consider thread-safety in your
|
||||
* event listeners</strong> as the "current thread" can and will be different each time.</p>
|
||||
* @return the priority
|
||||
*/
|
||||
short priority() default Short.MIN_VALUE;
|
||||
|
||||
/**
|
||||
* Whether the handler must be called asynchronously. By default, all event handlers are called
|
||||
* asynchronously.
|
||||
*
|
||||
* <p>If any method handler targeting an event type is marked with {@code true}, then every
|
||||
* handler targeting that event type will be executed asynchronously.</p>
|
||||
* <p>For performance (for instance, if you use {@link EventTask#withContinuation}), you can
|
||||
* optionally specify <code>false</code>. This option will become {@code false} by default
|
||||
* in a future release of Velocity.</p>
|
||||
*
|
||||
* <p>If this is {@code true}, the method is guaranteed to be executed asynchronously. Otherwise,
|
||||
* the handler may be executed on the current thread or asynchronously. <strong>This still means
|
||||
* you must consider thread-safety in your event listeners</strong> as the "current thread" can
|
||||
* and will be different each time.</p>
|
||||
*
|
||||
* <p>Note that if any method handler targeting an event type is marked with {@code true}, then
|
||||
* every handler targeting that event type will be executed asynchronously.</p>
|
||||
*
|
||||
* @return Requires async
|
||||
*/
|
||||
|
Reference in New Issue
Block a user