001    package com.hammurapi.eventbus;
002    
003    import com.hammurapi.extract.Predicate;
004    
005    /**
006     * Event handler base.
007     * @author Pavel Vlasov.
008     * @param <E> Event type.
009     * @param <P> Priority type.
010     */
011    public interface EventHandlerBase<E, P extends Comparable<P>, C> {
012                    
013            /**
014             * Event handler mode. 
015             * Post - handler is fired when event is posted. 
016             * Remove - handler is fired when event is removed. 
017             * Both - handler is fired when event is posted and when event is removed.
018             * @author Pavel Vlasov
019             *
020             */
021            enum Mode { POST, REMOVE, BOTH }
022            
023            /**
024             * @return true if this handler consumes or updates events.
025             */
026            boolean consumes();
027            
028            /**
029             * @return priority Handler priority. Handlers with higher priority are guaranteed to be executed before
030             * handlers with lower priority and as such can consume events and prevent their dispatching to other handlers. 
031             */
032            P getPriority();
033            
034            /**
035             * @return Number of parameters expected by this handler.
036             */
037            int getCardinality();
038            
039            /**
040             * Resets handler internal state, if any.
041             */
042            void reset();
043            
044            /**
045             * @return Context for predicates.
046             */
047            C getContext();
048            
049            /**
050             * If this method returns true, then handler is invoked only once and then is removed from the bus.
051             * @return
052             */
053            boolean isOneOff();
054            
055            /**
056             * Handler mode.
057             * @return
058             */
059            Mode getMode();
060    
061            /**
062             * @return Handler predicates.
063             */
064            Predicate<E, C> getPredicate();   
065    
066    }