| 1 | package com.hammurapi.eventbus; |
| 2 | |
| 3 | /** |
| 4 | * Inference policy defines how new events (conclusions) posted by handlers are dispatched. |
| 5 | * Different policies provide different levels of serialization/concurrency of event processing. |
| 6 | * @author Pavel Vlasov |
| 7 | * |
| 8 | */ |
| 9 | public enum InferencePolicy { |
| 10 | |
| 11 | /** |
| 12 | * New events (conclusions) are dispatched immediately when they are posted. |
| 13 | * IMPORTANT: Use of this policy with join handlers may lead to ConcurrentModificationException if |
| 14 | * posted events match the same join handlers and inference commands are executed in |
| 15 | * the same thread. |
| 16 | */ |
| 17 | IMMEDIATELY, |
| 18 | |
| 19 | /** |
| 20 | * Conclusions are accumulated during handler execution and are posted to the |
| 21 | * bus after the handler successfully finishes execution (without exception). |
| 22 | */ |
| 23 | AFTER_HANDLER, |
| 24 | |
| 25 | /** |
| 26 | * Conclusions are accumulated during event dispatching and are posted to the |
| 27 | * bus after all handlers for the current event finish execution. |
| 28 | */ |
| 29 | AFTER_EVENT, |
| 30 | |
| 31 | /** |
| 32 | * "Root event" is an event which is posted to the bus by the client code (not by a handler) through |
| 33 | * EventBus.post() method. With this inference policy conclusions are accumulated and get posted |
| 34 | * to the bus after all handlers for the root event and previously posted conclusions finish execution. |
| 35 | */ |
| 36 | AFTER_ROOT_EVENT, |
| 37 | |
| 38 | /** |
| 39 | * Only one event at a time is dispatched by the bus. Handlers and predicates still execute in parallel by |
| 40 | * the executor service. |
| 41 | */ |
| 42 | EXCLUSIVE |
| 43 | |
| 44 | } |