-
Notifications
You must be signed in to change notification settings - Fork 4
internal.eventBus
orciument edited this page Nov 16, 2024
·
1 revision
Subscriber are functions that are called when a specific Event is dispatched into the Event stream. These functions can then be used to act on these Events, such as saving the Information into the Database, or to produce another Event.
For a function to be a valid Subscriber ist has to be:
- static
- public, both the function and class
- only have one Parameter (this is the class of Event you are subscribing to)
- be annotated with the
@Subscriber
Annotation - don't throw any Exceptions in the function signature (you should also not throw runtime exceptions)
Otherwise, you can do almost all you want with these Events, but here is some additional useful information:
- the return type should be void, if you return something else the value is ignored
- a Subscriber should only have one purpose, if you need to do multiple things if a Event is triggered and these things are separate tasks, you should use multiple Subscriber
- you can freely choose the name of the Subscriber function, but it is advised that you choose a name that is specific and deskriptiv enough that you can guess what the purpose of this Hook is, and which one it is; because it will make debugging easier
- A Subscriber does not consume its event, each Subscriber gets a Copy of this Event (if there are multiple Subscriber for a single Event they are alle run sequentially from the same Thread, the order is random)
Events are dispatched via a call of the EventDispatcher.dispatch(Object event)
Method. This Method is static and can be called from everywhere, it all Subscribers to this event will be run in a separate Thread.