01: package com.sun.portal.proxylet.client.common;
02:
03: import com.sun.portal.proxylet.client.common.ui.AbstractEventHandler;
04: import com.sun.portal.proxylet.client.common.ui.ProxyletUI;
05:
06: import java.util.Timer;
07: import java.util.TimerTask;
08:
09: /**
10: * User: ss144266
11: * Date: Apr 27, 2005
12: * Time: 5:07:02 PM
13: * ValidateSession
14: *
15: * Asynchronous timer thread that validates session every timeout seconds.
16: * If session expired, resets proxysettings, stops proxy server and the like...
17: * otherwise, continues...
18: *
19: */
20: public class ValidateSession {
21: Timer timer;
22: AbstractEventHandler evtHandler;
23:
24: public ValidateSession(AbstractEventHandler evtHandler) {
25: this .evtHandler = evtHandler;
26: Log.debug("Starting timer thread...");
27: timer = new Timer();
28: timer
29: .schedule(new RemindTask(),
30: 0, //initial delay
31: Integer.parseInt(Param.getSessionIdleTimeout()) * 60 * 1000); //subsequent rate
32: }
33:
34: class RemindTask extends TimerTask {
35: public void run() {
36:
37: Log.debug("Check session validity");
38: boolean isvalid = checksessiontimeout();
39: if (isvalid == false) {
40: timer.cancel();
41:
42: ProxyletUI
43: .setText(Param
44: .getString("pinfo.22",
45: "Session timedout..Proxylet Console will close in few seconds..."));
46: ProxyletUI.progressIndicator.setIndeterminate(true);
47: try {
48: Thread.sleep(20 * 1000);
49: } catch (InterruptedException e) {
50:
51: }
52:
53: if (ProxyletUI.progressIndicator.isIndeterminate())
54: ProxyletUI.progressIndicator
55: .setIndeterminate(false);
56:
57: // invoke handlestop to perform cleanup activities
58: evtHandler.handleStop();
59:
60: }
61: }
62: }
63:
64: boolean checksessiontimeout() {
65: boolean result = true; //true by default
66: try {
67: Param.sendMsgtoServlet("?command=validatesession", false,
68: false, null);
69: } catch (SessionTimeoutException e) {
70: Log.debug("Session Expired....");
71: ProxyletUI.progressIndicator.setString("");
72: result = false;
73: } catch (Exception e) {
74: // just ignore
75: Log.debug("Session valid....");
76: }
77: return result;
78:
79: }
80: }
|