-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
EventHandler.java
69 lines (66 loc) · 1.46 KB
/
EventHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package io.github.joeljeremy.deezpatch.core;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
/**
* Methods annotated with this annotation are registered as {@link Event} handlers.
*
* <h2>Given the following events:</h2>
*
* <blockquote>
*
* <pre>
* public class OrderPlaced implements Event {
* private final String orderId;
*
* public OrderPlaced(String orderId) {
* this.orderId = orderId;
* }
*
* public String orderId() {
* return orderId;
* }
* }
*
* public class OrderCancelled implements Event {
* private final String orderId;
*
* public OrderCancelled(String orderId) {
* this.orderId = orderId;
* }
*
* public String orderId() {
* return orderId;
* }
* }
* </pre>
*
* </blockquote>
*
* <h2>Valid event handlers are:</h2>
*
* <blockquote>
*
* <pre>
* public class EventHandlers {
* {@code @}EventHandler
* public void handle(OrderPlaced event) {
* {@code // Handle}
* }
*
* {@code @}EventHandler
* public void handle(OrderCancelled event) {
* {@code // Handle}
* }
* }
* </pre>
*
* </blockquote>
*
* @implSpec The annotated methods accept a single method parameter which is the {@link Event}
* object. The method's return type must be {@code void}.
*/
@Retention(RUNTIME)
@Target(METHOD)
public @interface EventHandler {}