    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 observer methods.
    010     * @author Pavel Vlasov.
    011     *
    012     */
    013    @Target({ElementType.METHOD})
    014    @Retention(RetentionPolicy.RUNTIME)
    015    public @interface Observer {
    016
    017            /**
    018             * @return Observer method priority. Methods with higher priority value get invoked before methods with lower priority value.
    019             * Observeer 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 Java Scripting Framework is used to look up a script engine to evaluate 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 are named <code>arg0</code>, <code>arg1</code>, etc. for
    030             * method level conditions and <code>arg</code> for parameter level conditions.
    031             * Condition expression is a fragment of Java code returning boolean.
    032             * Rule instance is available through <code>rule</code> parameter.
    033             * @return True if condition is fulfilled and further rule evaluation shall be attempted. If several conditions are specified,
    034             * then they are connected by AND and it is assumed that they can be reordered by the rule compilation/execution engine to
    035             * build conditions chain.
    036             */
    037            String[] value() default {};
    038
    039            /**
    040             * This optional attribute informs the bus about event types which
    041             * this method posts (if any). It allows the engine to optimize the
    042             * predicate network.
    043             * @return
    044             */
    045            Class<?>[] posts() default {};
    046
    047            /**
    048             * @return true if this observer consumes or updates events.
    049             */
    050            boolean consumes() default true;
    051
    052            /**
    053             * @return true if this observer shall be invoked only once.
    054             */
    055            boolean oneOff() default false;
    056
    057    }