Add system events section to README
This commit is contained in:
parent
6a2cad4ae5
commit
7c3cd017de
32
README.md
32
README.md
@ -123,6 +123,38 @@ This applies to all event handlers that would have been executed after the one c
|
|||||||
Avoid cancelling events while using multiple event handlers with the same priority.
|
Avoid cancelling events while using multiple event handlers with the same priority.
|
||||||
As event handlers are ordered by priority, it is not defined which of them will be executed after the event has been consumed.
|
As event handlers are ordered by priority, it is not defined which of them will be executed after the event has been consumed.
|
||||||
|
|
||||||
|
## System Events
|
||||||
|
|
||||||
|
To accommodate for special circumstances in an event distribution, system events have been introduced.
|
||||||
|
At the moment, there are two system events, which are explained in this section.
|
||||||
|
|
||||||
|
### Detecting Unhandled Events
|
||||||
|
|
||||||
|
When an event is dispatched but not delivered to any handler, a dead event is dispatched that wraps the original event.
|
||||||
|
You can declare a dead event handler to respond to this situation:
|
||||||
|
|
||||||
|
```java
|
||||||
|
private void onDeadEvent(DeadEvent deadEvent) { ... }
|
||||||
|
```
|
||||||
|
|
||||||
|
### Detecting Exceptions Thrown by Event Handlers
|
||||||
|
|
||||||
|
When an event handler throws an exception, an exception event is dispatched that wraps the original event.
|
||||||
|
A exception handler is declared as follows:
|
||||||
|
|
||||||
|
```java
|
||||||
|
private void onExceptionEvent(ExceptionEvent ExceptionEvent) { ... }
|
||||||
|
```
|
||||||
|
|
||||||
|
Both system events reference the event bus that caused them and a warning is logged if they are unhandled.
|
||||||
|
|
||||||
|
### What About Endless Recursion Caused By Dead Events and Exception Events?
|
||||||
|
|
||||||
|
As one might imagine, an unhandled dead event would theoretically lead to an endless recursion.
|
||||||
|
The same applies when an exception event handler throws an exception.
|
||||||
|
|
||||||
|
To avoid this, system events never cause system events and instead just issue a warning to the logger.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Event Bus is available in Maven Central.
|
Event Bus is available in Maven Central.
|
||||||
|
@ -89,7 +89,7 @@ public final class EventBus {
|
|||||||
if (event instanceof DeadEvent || event instanceof ExceptionEvent)
|
if (event instanceof DeadEvent || event instanceof ExceptionEvent)
|
||||||
|
|
||||||
// Warn about system event not being handled
|
// Warn about system event not being handled
|
||||||
logger.log(Level.WARNING, event + " not handled", e);
|
logger.log(Level.WARNING, event + " not handled due to exception", e);
|
||||||
else
|
else
|
||||||
|
|
||||||
// Dispatch exception event
|
// Dispatch exception event
|
||||||
|
Loading…
Reference in New Issue
Block a user