home *** CD-ROM | disk | FTP | other *** search
- package com.bitmechanic.gsp;
-
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.Vector;
- import javax.servlet.http.HttpSession;
-
- public class ApplicationManager implements Runnable {
- private GspServlet servlet;
- private Vector appList;
- private Hashtable appSessionHash;
- private final int DEFAULT_TIMEOUT_MINUTES = 60;
- private final int DEFAULT_SLEEP_INTERVAL = 1;
- private int timeoutMinutes;
- private int sleepInterval;
-
- public ApplicationManager(GspServlet var1) {
- this.servlet = var1;
- this.appList = new Vector();
- this.appSessionHash = new Hashtable();
-
- try {
- this.timeoutMinutes = Integer.parseInt(var1.getProperty("session.timeout.minutes"));
- this.sleepInterval = Integer.parseInt(var1.getProperty("session.sleepinterval.minutes"));
- if (this.timeoutMinutes < 1) {
- this.timeoutMinutes = 60;
- }
-
- if (this.sleepInterval < 1) {
- this.sleepInterval = 1;
- }
- } catch (NumberFormatException var2) {
- this.timeoutMinutes = 60;
- this.sleepInterval = 1;
- }
-
- var1.getScheduler().scheduleJob(this, this.sleepInterval * 60);
- }
-
- public void destroy() throws Exception {
- Enumeration var1 = this.appList.elements();
-
- while(var1.hasMoreElements()) {
- Application var2 = (Application)var1.nextElement();
- var2.destroy();
- }
-
- }
-
- public Application getApplication(String var1) {
- for(int var2 = 0; var2 < this.appList.size(); ++var2) {
- Application var3 = (Application)this.appList.elementAt(var2);
- if (var3.acceptsURL(var1)) {
- return var3;
- }
- }
-
- return null;
- }
-
- public void addApplication(Application var1) {
- var1.init(this.servlet, this);
- this.appList.addElement(var1);
- }
-
- public void registerSessionWithApp(Application var1, HttpSession var2, GspRequest var3) {
- Hashtable var4 = (Hashtable)this.appSessionHash.get(var2);
- if (var4 == null) {
- var4 = new Hashtable();
- this.appSessionHash.put(var2, var4);
- }
-
- if (var4.get(var1) == null) {
- var4.put(var1, var2);
- var1.sessionStart(var3);
- }
-
- }
-
- public void invalidateSession(HttpSession var1) {
- Hashtable var2 = (Hashtable)this.appSessionHash.get(var1);
- Enumeration var3 = var2.keys();
-
- while(var3.hasMoreElements()) {
- Application var4 = (Application)var3.nextElement();
- var4.sessionTimeout(var1);
- }
-
- this.appSessionHash.remove(var1);
- var1.invalidate();
- }
-
- private void timeoutSessions() {
- long var1 = System.currentTimeMillis() - (long)(this.timeoutMinutes * '\uea60');
- Enumeration var3 = this.appSessionHash.keys();
-
- while(var3.hasMoreElements()) {
- HttpSession var4 = (HttpSession)var3.nextElement();
- synchronized(var4){}
-
- try {
- if (var4.getLastAccessedTime() < var1) {
- this.invalidateSession(var4);
- }
- } catch (Throwable var7) {
- throw var7;
- }
- }
-
- }
-
- public void run() {
- this.timeoutSessions();
- }
- }
-