-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
RequestHandler.java
83 lines (80 loc) · 2.24 KB
/
RequestHandler.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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 Request} handlers.
*
* <h2>Given the following requests:</h2>
*
* <blockquote>
*
* <pre>
* public class PlaceOrder implements Request{@literal <}Void{@literal >} {
* private final OrderItems orderItems;
*
* public PlaceOrder(OrderItems orderItems) {
* this.orderItems = orderItems;
* }
*
* public OrderItems orderItems() {
* return orderItems;
* }
* }
*
* public class GetOrderById implements Request{@literal <}Order{@literal >} {
* private final String orderId;
*
* public GetOrderById(String orderId) {
* this.orderId = orderId;
* }
*
* public String orderId() {
* return orderId;
* }
* }
*
* public class GetOrderCount implements Request{@literal <}Integer{@literal >} {}
* </pre>
*
* </blockquote>
*
* <h2>Valid request handlers are:</h2>
*
* <blockquote>
*
* <pre>
* public class RequestHandlers {
* {@code // PlaceOrder request has Void result type.}
* {@code // Method return type must either be void.}
* {@code @}RequestHandler
* public void handle(PlaceOrder request) {
* placeOrder(request);
* }
*
* {@code // GetOrderById request has Order result type.}
* {@code // Method return type must be Order.}
* {@code @}RequestHandler
* public Order handle(GetOrderById request) {
* return getOrder(request.orderId());
* }
*
* {@code // GetOrderCount request has Integer result type.}
* {@code // Method return type must either be Integer or int.}
* {@code @}RequestHandler
* public int handle(GetOrderCount request) {
* return countOrders();
* }
* }
* </pre>
*
* </blockquote>
*
* @implSpec The annotated methods must accept a single method parameter which is the {@link
* Request} object. The method's return type must match the request's result type (primitives
* and wrapper types (including {@code Void}/{@code void}) are intercheangable).
*/
@Retention(RUNTIME)
@Target(METHOD)
public @interface RequestHandler {}