01: /*
02: * Enhydra Java Application Server Project
03: *
04: * The contents of this file are subject to the Enhydra Public License
05: * Version 1.1 (the "License"); you may not use this file except in
06: * compliance with the License. You may obtain a copy of the License on
07: * the Enhydra web site ( http://www.enhydra.org/ ).
08: *
09: * Software distributed under the License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11: * the License for the specific terms governing rights and limitations
12: * under the License.
13: *
14: * The Initial Developer of the Enhydra Application Server is Lutris
15: * Technologies, Inc. The Enhydra Application Server and portions created
16: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17: * All Rights Reserved.
18: *
19: * Contributor(s):
20: *
21: * $Id: PagedSessionThresholdTimer.java,v 1.2 2006-06-15 13:44:07 sinisa Exp $
22: */
23:
24: package com.lutris.appserver.server.sessionEnhydra;
25:
26: import com.lutris.appserver.server.Application;
27: import com.lutris.appserver.server.Enhydra;
28: import com.lutris.logging.Logger;
29:
30: /**
31: * This thread sleeps in the background, waking up periodically to
32: * check for inactive sessions and to page out any session that
33: * has been inactive for too long.
34: *
35: * @version $Revision: 1.2 $
36: * @author Kyle Clark
37: */
38: public class PagedSessionThresholdTimer extends Thread {
39:
40: private PagedSessionHome home;
41: private Application app; // The application context.
42: private boolean done = false;
43:
44: /*
45: * @param home the paged session home.
46: * @param app the application context.
47: * @param scanIntervalSec Time interval, in seconds, to scan for idle
48: * session.
49: */
50: public PagedSessionThresholdTimer(PagedSessionHome home,
51: Application app) {
52: this .home = home;
53: this .app = app;
54: setDaemon(true);
55: }
56:
57: /**
58: * Main loop.
59: */
60: public void run() {
61: Enhydra.register(app);
62: long scanInterval = 0;
63: while (!done) {
64: try {
65: scanInterval = home.checkPassiveSessions();
66: } catch (Exception e) {
67: Enhydra.getLogChannel().write(Logger.ALERT,
68: "Failed to check idle sessions: " + e, e);
69: }
70: try {
71: sleep(scanInterval);
72: } catch (InterruptedException e) {
73: // Ignore.
74: }
75: }
76: Enhydra.unRegister();
77: }
78:
79: /**
80: * Shutdown the thread associated with this object.
81: */
82: public void shutdown() {
83: done = true;
84: }
85: }
|