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.session.SessionListener;
20 
21 import hunt.shiro.session.Session;
22 
23 /**
24  * Interface to be implemented by components that wish to be notified of events that occur during a
25  * {@link Session Session}'s life cycle.
26  *
27  */
28 interface SessionListener {
29 
30     /**
31      * Notification callback that occurs when the corresponding Session has started.
32      *
33      * @param session the session that has started.
34      */
35     void onStart(Session session);
36 
37     /**
38      * Notification callback that occurs when the corresponding Session has stopped, either programmatically via
39      * {@link Session#stop} or automatically upon a subject logging out.
40      *
41      * @param session the session that has stopped.
42      */
43     void onStop(Session session);
44 
45     /**
46      * Notification callback that occurs when the corresponding Session has expired.
47      * <p/>
48      * <b>Note</b>: this method is almost never called at the exact instant that the {@code Session} expires.  Almost all
49      * session management systems, including Shiro's implementations, lazily validate sessions - either when they
50      * are accessed or during a regular validation interval.  It would be too resource intensive to monitor every
51      * single session instance to know the exact instant it expires.
52      * <p/>
53      * If you need to perform time-based logic when a session expires, it is best to write it based on the
54      * session's {@link hunt.shiro.session.Session#getLastAccessTime() lastAccessTime} and <em>not</em> the time
55      * when this method is called.
56      *
57      * @param session the session that has expired.
58      */
59     void onExpiration(Session session);
60 }