001 package com.hammurapi.eventbus;
002
003 import com.hammurapi.common.ExceptionHandler;
004 import com.hammurapi.eventbus.AbstractEventBus.Handle;
005
006
007 /**
008 * Events posted by handlers are wrapped into instances of this class.
009 * Inference commands are queued or processed immediately depending on inference policy.
010 * Inference commands are filtered by InferenceCommandFilter before being applied to
011 * event store and posted to further dispatching.
012 * @author Pavel Vlasov
013 *
014 * @param <E>
015 * @param <P>
016 * @param <C>
017 * @param <H>
018 */
019 public abstract class InferenceCommand<E, P extends Comparable<P>, C, K, H extends EventBus.Handle<E,P,C>, S extends EventStore<E,P,C,H,S>> {
020
021 /**
022 * @return Handler which posted this event.
023 */
024 private EventHandler<E, P, C, H, S> handler;
025
026 /**
027 * @return List of handler inputs which produced this event.
028 */
029 private Handle<E,P,C,K>[] inputs;
030
031 private K handlerId;
032
033 private InferenceContext<E, P, C, K, H, S> inferenceContext;
034
035 protected InferenceCommand(
036 K handlerId,
037 EventHandler<E, P, C, H, S> handler,
038 Handle<E,P,C,K>[] inputs,
039 InferenceContext<E,P,C,K,H,S> inferenceContext) {
040 super();
041 this.handlerId = handlerId;
042 this.handler = handler;
043 this.inputs = inputs;
044 this.inferenceContext = inferenceContext;
045 }
046
047 public EventHandler<E, P, C, H, S> getHandler() {
048 return handler;
049 }
050
051 public Handle<E,P,C,K>[] getInputs() {
052 return inputs;
053 }
054
055 public InferenceContext<E, P, C, K, H, S> getInferenceContext() {
056 return inferenceContext;
057 }
058
059 public K getHandlerId() {
060 return handlerId;
061 }
062
063 public void setInferenceContext(InferenceContext<E, P, C, K, H, S> inferenceContext) {
064 this.inferenceContext = inferenceContext;
065 }
066 }
067