KickJava   Java API By Example, From Geeks To Geeks.

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


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: PagedSessionThresholdTimer.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.Logger;
30
31 /**
32  * This thread sleeps in the background, waking up periodically to
33  * check for inactive sessions and to page out any session that
34  * has been inactive for too long.
35  *
36  * @version $Revision: 1.2 $
37  * @author Kyle Clark
38  */

39 public class PagedSessionThresholdTimer extends Thread JavaDoc {
40
41     private PagedSessionHome home;
42     private Application app; // The application context.
43
private boolean done = false;
44
45     /*
46      * @param home the paged session home.
47      * @param app the application context.
48      * @param scanIntervalSec Time interval, in seconds, to scan for idle
49      * session.
50      */

51     public PagedSessionThresholdTimer(PagedSessionHome home,
52                                       Application app) {
53         this.home = home;
54         this.app = app;
55     setDaemon(true);
56     }
57
58     /**
59      * Main loop.
60      */

61     public void run() {
62         Enhydra.register(app);
63         long scanInterval = 0;
64     while (!done) {
65             try {
66                 scanInterval = home.checkPassiveSessions();
67             } catch (Exception JavaDoc e) {
68         Enhydra.getLogChannel().write(Logger.ALERT,
69                                               "Failed to check idle sessions: " + e, e);
70             }
71         try {
72         sleep(scanInterval);
73         } catch (InterruptedException JavaDoc e) {
74                 // Ignore.
75
}
76     }
77         Enhydra.unRegister();
78     }
79
80     /**
81      * Shutdown the thread associated with this object.
82      */

83     public void shutdown() {
84         done = true;
85     }
86 }
87
88
Popular Tags