KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > server > sessionEnhydra > StandardSessionIdleTimer


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: StandardSessionIdleTimer.java,v 1.2 2005/03/24 10:51:20 slobodan Exp $
23  */

24
25 package com.lutris.appserver.server.sessionEnhydra;
26
27 import com.lutris.appserver.server.Application;
28 import com.lutris.appserver.server.Enhydra;
29 import com.lutris.logging.LogChannel;
30 import com.lutris.logging.Logger;
31
32 /**
33  * The idle timer thread for <CODE>StandardSessionManager</CODE>.
34  * This thread sleeps in the background, waking up periodically to
35  * check for inactive sessions and to terminate any session that has been
36  * inactive for too long.
37  *
38  * @version $Revision: 1.2 $
39  * @author John Marco
40  * @author Shawn McMurdo
41  */

42 public class StandardSessionIdleTimer extends Thread JavaDoc {
43
44     private StandardSessionIdleHandler idleHandler;
45     private long scanInterval; // In milliseconds.
46
private Application app; // The application context.
47

48     /*
49      * Constructor an idle timer object. Sets the
50      * internal session manager reference and check period,
51      * but doesn't start the thread.
52      *
53      * @param manager The session manager to be checked periodically for
54      * idle sessions.
55      * @param app the application context.
56      * @param scanIntervalSec Time interval, in seconds, to scan for idle
57      * session.
58      */

59     public StandardSessionIdleTimer(StandardSessionIdleHandler manager,
60                                     Application app,
61                                     long scanIntervalSec) {
62         idleHandler = manager;
63         this.app = app;
64     // Convert idle timer scanning interval milliseconds.
65
scanInterval = scanIntervalSec * 1000;
66         setPriority(MIN_PRIORITY); // For performance
67
setDaemon(true); // Don't require this thread to exit.
68
}
69
70     /**
71      * The main code body of the Idle Timer Thread. Enters an endless
72      * loop that sleeps for a configurable period, periodically waking
73      * up to check the Session Manager for idle sessions.
74      */

75     public void run() {
76         if (app != null) {
77           Enhydra.register(app);
78         }
79     while (true) {
80         try {
81         sleep(scanInterval);
82         } catch (InterruptedException JavaDoc e) {
83                 // Ignore.
84
}
85             try {
86                 idleHandler.cleanUpIdleSessions();
87             } catch (Exception JavaDoc e) {
88         LogChannel log = Enhydra.getLogChannel();
89         log.write(Logger.ALERT, "Failed to clean up idle sessions: " + e);
90                 // TODO - print to log
91
e.printStackTrace();
92             }
93     }
94         // TODO - Enhydra.unregister();
95
}
96
97     /**
98      * Shutdown the thread associated with this object.
99      */

100     public void shutdown() {
101         stop();
102     }
103 }
104
105
Popular Tags