Class DietrichEvents2
java.lang.Object
de.florianmichael.dietrichevents2.DietrichEvents2
This class is the main class of DietrichEvents2.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe errorHandler consumer will be called when an exception is thrown in a subscriber. -
Constructor Summary
ConstructorsConstructorDescriptionDietrichEvents2(int trackingDefault, Consumer<Throwable> errorHandler) Creates a new instance of DietrichEvents2. -
Method Summary
Modifier and TypeMethodDescriptionstatic DietrichEvents2global()booleanhasSubscriber(int id) voidpost(int id, AbstractEvent event) This method is the recommended method for event calling, it calls the postInternal method but has some sanity checks and calls the errorHandler if an error occurs.voidpostInternal(int id, AbstractEvent event) This method calls all events, with the difference that it has no sanity checks for errors.protected voidresizeArrays(int maxLength) Internal method that automatically resizes the array with all subscribers, this method should never be called simply because the event system calls it itself.voidSubscribes a listener with the given ID to the given class, can be called multiple times.voidSubscribes a listener with the given ID to the given class, can be called multiple times.voidunsubscribe(int id, Object object) Unsubscribes a listener with the given ID from the given class, can be called multiple times.
-
Field Details
-
errorHandler
The errorHandler consumer will be called when an exception is thrown in a subscriber.
-
-
Constructor Details
-
DietrichEvents2
Creates a new instance of DietrichEvents2. The trackingDefault parameter is the default size of the array that stores all subscribers.- Parameters:
trackingDefault- The default size of the array that stores all subscribers.errorHandler- The errorHandler consumer will be called when an exception is thrown in a subscriber.
-
-
Method Details
-
global
-
hasSubscriber
public boolean hasSubscriber(int id) - Parameters:
id- The id of the event.- Returns:
- Whether the event has subscribers.
-
subscribe
Subscribes a listener with the given ID to the given class, can be called multiple times.- Parameters:
id- The id of the event.object- The object to subscribe.
-
resizeArrays
protected void resizeArrays(int maxLength) Internal method that automatically resizes the array with all subscribers, this method should never be called simply because the event system calls it itself.- Parameters:
maxLength- The new maximum length of the array.
-
subscribe
Subscribes a listener with the given ID to the given class, can be called multiple times. For priorities seePriorities. The higher a priority is, the earlier an event is called.- Parameters:
id- The id of the event.object- The object to subscribe.priority- The priority of the subscriber.
-
unsubscribe
Unsubscribes a listener with the given ID from the given class, can be called multiple times.- Parameters:
id- The id of the event.object- The object to unsubscribe.
-
post
This method is the recommended method for event calling, it calls the postInternal method but has some sanity checks and calls the errorHandler if an error occurs.- Parameters:
id- The id of the event.event- The event to post.
-
postInternal
This method calls all events, with the difference that it has no sanity checks for errors.- Parameters:
id- The id of the event.event- The event to post.
-