001 package com.hammurapi.eventbus;
002
003 import java.util.Queue;
004
005 import com.hammurapi.common.ExceptionHandler;
006 import com.hammurapi.common.concurrent.TrackingExecutorService;
007
008 /**
009 * Context propagated through inference processing.
010 * @author Pavel Vlasov
011 *
012 */
013 public interface InferenceContext<E, P extends Comparable<P>, C, K, H extends EventBus.Handle<E,P,C>, S extends EventStore<E,P,C,H,S>> {
014
015 Queue<InferenceCommand<E,P,C,K,H,S>> getInferenceCommandsQueue();
016
017 int getInferenceChainLength();
018
019 TrackingExecutorService getExecutorService();
020
021 ExceptionHandler getRootHandle();
022
023 void setRootHandle(ExceptionHandler rootHandle);
024
025 EventBus<E,P,C,K,H,S> getBus();
026
027 /**
028 * Creates inference context with the same executor and root handle.
029 * The queue is inherited for AFTER_ROOT_EVENT and EXCLUSIVE inference policies.
030 * A new queue is created for AFTER_EVENT policy. Otherwise queue is null.
031 * Inference chain length is incremented by 1.
032 * @param isJoin - true if invoked from multi-event join step.
033 * @return
034 */
035 InferenceContext<E,P,C,K,H,S> createNext();
036
037 /**
038 * For AFTER_HANDLER
039 * @return
040 */
041 InferenceContext<E,P,C,K,H,S> wrap();
042
043 /**
044 * Adds inference command to the queue or processes it immediately depending
045 * on inference policy.
046 * @param command
047 * @return
048 */
049 void postInferenceCommand(InferenceCommand<E, P, C, K, H, S> command);
050
051 /**
052 * Processes accumulated inference commands, if any.
053 */
054 void processInferenceCommands();
055 }