| 1 | package com.hammurapi.eventbus; |
| 2 | |
| 3 | import com.hammurapi.extract.Predicate; |
| 4 | |
| 5 | /** |
| 6 | * Event handler base. |
| 7 | * @author Pavel Vlasov. |
| 8 | * @param <E> Event type. |
| 9 | * @param <P> Priority type. |
| 10 | */ |
| 11 | public interface EventHandlerBase<E, P extends Comparable<P>, C> { |
| 12 | |
| 13 | /** |
| 14 | * Event handler mode. |
| 15 | * Post - handler is fired when event is posted. |
| 16 | * Remove - handler is fired when event is removed. |
| 17 | * Both - handler is fired when event is posted and when event is removed. |
| 18 | * @author Pavel Vlasov |
| 19 | * |
| 20 | */ |
| 21 | enum Mode { POST, REMOVE, BOTH } |
| 22 | |
| 23 | /** |
| 24 | * @return true if this handler consumes or updates events. |
| 25 | */ |
| 26 | boolean consumes(); |
| 27 | |
| 28 | /** |
| 29 | * @return priority Handler priority. Handlers with higher priority are guaranteed to be executed before |
| 30 | * handlers with lower priority and as such can consume events and prevent their dispatching to other handlers. |
| 31 | */ |
| 32 | P getPriority(); |
| 33 | |
| 34 | /** |
| 35 | * @return Number of parameters expected by this handler. |
| 36 | */ |
| 37 | int getCardinality(); |
| 38 | |
| 39 | /** |
| 40 | * Resets handler internal state, if any. |
| 41 | */ |
| 42 | void reset(); |
| 43 | |
| 44 | /** |
| 45 | * @return Context for predicates. |
| 46 | */ |
| 47 | C getContext(); |
| 48 | |
| 49 | /** |
| 50 | * If this method returns true, then handler is invoked only once and then is removed from the bus. |
| 51 | * @return |
| 52 | */ |
| 53 | boolean isOneOff(); |
| 54 | |
| 55 | /** |
| 56 | * Handler mode. |
| 57 | * @return |
| 58 | */ |
| 59 | Mode getMode(); |
| 60 | |
| 61 | /** |
| 62 | * @return Handler predicates. |
| 63 | */ |
| 64 | Predicate<E, C> getPredicate(); |
| 65 | |
| 66 | } |