| 1 | package com.hammurapi.eventbus; |
| 2 | |
| 3 | |
| 4 | /** |
| 5 | * Discards post commands with derivation loops, i.e. when one of inputs is derived from the event. |
| 6 | * @author Pavel Vlasov |
| 7 | */ |
| 8 | public class DerivationLoopFilter<E, P extends Comparable<P>, C, K, H extends EventBus.Handle<E,P,C>, S extends EventStore<E,P,C,H,S>> implements InferenceFilter<E,P,C,K,H,S> { |
| 9 | |
| 10 | public boolean accept(InferenceCommand<E,P,C,K,H,S> inferenceCommand, EventBus<E,P,C,K,H,S> bus) { |
| 11 | if (inferenceCommand instanceof PostCommand) { |
| 12 | PostCommand<E,P,C,K,H,S> postCommand = (PostCommand<E,P,C,K,H,S>) inferenceCommand; |
| 13 | E event = postCommand.getEvent(); |
| 14 | for (AbstractEventBus.Handle<E, P, C, K> handle: postCommand.getInputs()) { |
| 15 | if (handle.isDerivedFrom(event)) { |
| 16 | return false; |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | return true; |
| 21 | } |
| 22 | } |