001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.shiro.event.support;
020
021/**
022 * An event listener knows how to accept and process events of a particular type (or types).
023 * <p/>
024 * Note that this interface is in the event implementation support package (and not the event package directly)
025 * because it is a supporting concept for event bus implementations and not something that most application
026 * developers using Shiro should implement directly.  App developers should instead use the
027 * {@link org.apache.shiro.event.Subscribe Subscribe} annotation on methods they wish to receive events.
028 * <p/>
029 * This interface therefore mainly represents a 'middle man' between the event bus and the actual subscribing
030 * component.  As such, event bus implementors (or framework/infrastructural implementors) or those that wish to
031 * customize listener/dispatch functionality might find this concept useful.
032 * <p/>
033 * It is a concept almost always used in conjunction with a {@link EventListenerResolver} implementation.
034 *
035 * @see SingleArgumentMethodEventListener
036 * @see AnnotationEventListenerResolver
037 *
038 * @since 1.3
039 */
040public interface EventListener {
041
042    /**
043     * Returns {@code true} if the listener instance can process the specified event object, {@code false} otherwise.
044     * @param event the event object to test
045     * @return {@code true} if the listener instance can process the specified event object, {@code false} otherwise.
046     */
047    boolean accepts(Object event);
048
049    /**
050     * Handles the specified event.  Again, as this interface is an implementation concept, implementations of this
051     * method will likely dispatch the event to a 'real' processor (e.g. method).
052     *
053     * @param event the event to handle.
054     */
055    void onEvent(Object event);
056}