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     */
019    package org.apache.shiro.session;
020    
021    /**
022     * Interface to be implemented by components that wish to be notified of events that occur during a
023     * {@link Session Session}'s life cycle.
024     *
025     * @author Les Hazlewood
026     * @since 0.9
027     */
028    public interface SessionListener {
029    
030        /**
031         * Notification callback that occurs when the corresponding Session has started.
032         *
033         * @param session the session that has started.
034         */
035        void onStart(Session session);
036    
037        /**
038         * Notification callback that occurs when the corresponding Session has stopped, either programmatically via
039         * {@link Session#stop} or automatically upon a subject logging out.
040         *
041         * @param session the session that has stopped.
042         */
043        void onStop(Session session);
044    
045        /**
046         * Notification callback that occurs when the corresponding Session has expired.
047         * <p/>
048         * <b>Note</b>: this method is almost never called at the exact instant that the {@code Session} expires.  Almost all
049         * session management systems, including Shiro's implementations, lazily validate sessions - either when they
050         * are accessed or during a regular validation interval.  It would be too resource intensive to monitor every
051         * single session instance to know the exact instant it expires.
052         * <p/>
053         * If you need to perform time-based logic when a session expires, it is best to write it based on the
054         * session's {@link org.apache.shiro.session.Session#getLastAccessTime() lastAccessTime} and <em>not</em> the time
055         * when this method is called.
056         *
057         * @param session the session that has expired.
058         */
059        void onExpiration(Session session);
060    }