001    package com.hammurapi.eventbus;
002    
003    import java.lang.annotation.ElementType;
004    import java.lang.annotation.Retention;
005    import java.lang.annotation.RetentionPolicy;
006    import java.lang.annotation.Target;
007    
008    /**
009     * Annotation to mark reflective handler methods.
010     * @author Pavel Vlasov.
011     *
012     */
013    @Target({ElementType.METHOD})
014    @Retention(RetentionPolicy.RUNTIME)
015    public @interface Handler {
016            
017            /**
018             * @return Handler method priority. Methods with higher priority value get invoked before methods with lower priority value.
019             * Handler method can invoke consume() method from EventDispatchContext to "consume" source fact(s) and prevent invocation 
020             * of subsequent handler methods.
021             */
022            int priority() default 0;
023            
024            /**
025             * Condition definition has the following format <code>[language(parameter list)://] condition expression</code>. Default language is Java.
026             * If language is not Java, then Extractor framework is used to look up a extractor provider to create extractor from the expression.
027             * Parameter list is a comma separated list of parameter names, parameters not used in the condition expression can be omitted. 
028             * E.g. <code>parent, child, sibling</code> or, if <code>child</code> is not 
029             * used in the condition expression <code>parent,,sibling</code>. If parameter list is omitted, then arguments can be accessed through <code>args</code> array.
030             * Handler method's declaring class instance is available through <code>eCtx</code> parameter. 
031             */
032            String[] value() default {};
033            
034            /**
035             * This optional attribute informs the bus about event types which
036             * this method posts (if any). It allows the engine to optimize the
037             * predicate network.
038             * @return
039             */
040            Class<?>[] posts() default {};
041            
042            /**
043             * @return true if this handler consumes or updates events.
044             */
045            boolean consumes() default true;
046            
047            /**
048             * @return true if this handler shall be invoked only once.
049             */
050            boolean oneOff() default false;
051            
052            /**
053             * Handler mode. Default is POST.
054             * @return
055             */
056            EventHandlerBase.Mode mode() default EventHandlerBase.Mode.POST;
057            
058    }