1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 module hunt.shiro.event.support.EventListener;
20 
21 /**
22  * An event listener knows how to accept and process events of a particular type (or types).
23  * <p/>
24  * Note that this interface is in the event implementation support package (and not the event package directly)
25  * because it is a supporting concept for event bus implementations and not something that most application
26  * developers using Shiro should implement directly.  App developers should instead use the
27  * {@link hunt.shiro.event.Subscribe Subscribe} annotation on methods they wish to receive events.
28  * <p/>
29  * This interface therefore mainly represents a 'middle man' between the event bus and the actual subscribing
30  * component.  As such, event bus implementors (or framework/infrastructural implementors) or those that wish to
31  * customize listener/dispatch functionality might find this concept useful.
32  * <p/>
33  * It is a concept almost always used in conjunction with a {@link EventListenerResolver} implementation.
34  *
35  * @see SingleArgumentMethodEventListener
36  * @see AnnotationEventListenerResolver
37  *
38  * @since 1.3
39  */
40 interface EventListener {
41 
42     /**
43      * Returns {@code true} if the listener instance can process the specified event object, {@code false} otherwise.
44      * @param event the event object to test
45      * @return {@code true} if the listener instance can process the specified event object, {@code false} otherwise.
46      */
47     bool accepts(Object event);
48 
49     /**
50      * Handles the specified event.  Again, as this interface is an implementation concept, implementations of this
51      * method will likely dispatch the event to a 'real' processor (e.g. method).
52      *
53      * @param event the event to handle.
54      */
55     void onEvent(Object event);
56 }