home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 November / PCONLINE_11_99.ISO / filesbbs / OS2 / APCHSSL2.ZIP / OS2HTTPD / jserv / com / bitmechanic / gsp / ApplicationManager.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-02-03  |  3.3 KB  |  116 lines

  1. package com.bitmechanic.gsp;
  2.  
  3. import java.util.Enumeration;
  4. import java.util.Hashtable;
  5. import java.util.Vector;
  6. import javax.servlet.http.HttpSession;
  7.  
  8. public class ApplicationManager implements Runnable {
  9.    private GspServlet servlet;
  10.    private Vector appList;
  11.    private Hashtable appSessionHash;
  12.    private final int DEFAULT_TIMEOUT_MINUTES = 60;
  13.    private final int DEFAULT_SLEEP_INTERVAL = 1;
  14.    private int timeoutMinutes;
  15.    private int sleepInterval;
  16.  
  17.    public ApplicationManager(GspServlet var1) {
  18.       this.servlet = var1;
  19.       this.appList = new Vector();
  20.       this.appSessionHash = new Hashtable();
  21.  
  22.       try {
  23.          this.timeoutMinutes = Integer.parseInt(var1.getProperty("session.timeout.minutes"));
  24.          this.sleepInterval = Integer.parseInt(var1.getProperty("session.sleepinterval.minutes"));
  25.          if (this.timeoutMinutes < 1) {
  26.             this.timeoutMinutes = 60;
  27.          }
  28.  
  29.          if (this.sleepInterval < 1) {
  30.             this.sleepInterval = 1;
  31.          }
  32.       } catch (NumberFormatException var2) {
  33.          this.timeoutMinutes = 60;
  34.          this.sleepInterval = 1;
  35.       }
  36.  
  37.       var1.getScheduler().scheduleJob(this, this.sleepInterval * 60);
  38.    }
  39.  
  40.    public void destroy() throws Exception {
  41.       Enumeration var1 = this.appList.elements();
  42.  
  43.       while(var1.hasMoreElements()) {
  44.          Application var2 = (Application)var1.nextElement();
  45.          var2.destroy();
  46.       }
  47.  
  48.    }
  49.  
  50.    public Application getApplication(String var1) {
  51.       for(int var2 = 0; var2 < this.appList.size(); ++var2) {
  52.          Application var3 = (Application)this.appList.elementAt(var2);
  53.          if (var3.acceptsURL(var1)) {
  54.             return var3;
  55.          }
  56.       }
  57.  
  58.       return null;
  59.    }
  60.  
  61.    public void addApplication(Application var1) {
  62.       var1.init(this.servlet, this);
  63.       this.appList.addElement(var1);
  64.    }
  65.  
  66.    public void registerSessionWithApp(Application var1, HttpSession var2, GspRequest var3) {
  67.       Hashtable var4 = (Hashtable)this.appSessionHash.get(var2);
  68.       if (var4 == null) {
  69.          var4 = new Hashtable();
  70.          this.appSessionHash.put(var2, var4);
  71.       }
  72.  
  73.       if (var4.get(var1) == null) {
  74.          var4.put(var1, var2);
  75.          var1.sessionStart(var3);
  76.       }
  77.  
  78.    }
  79.  
  80.    public void invalidateSession(HttpSession var1) {
  81.       Hashtable var2 = (Hashtable)this.appSessionHash.get(var1);
  82.       Enumeration var3 = var2.keys();
  83.  
  84.       while(var3.hasMoreElements()) {
  85.          Application var4 = (Application)var3.nextElement();
  86.          var4.sessionTimeout(var1);
  87.       }
  88.  
  89.       this.appSessionHash.remove(var1);
  90.       var1.invalidate();
  91.    }
  92.  
  93.    private void timeoutSessions() {
  94.       long var1 = System.currentTimeMillis() - (long)(this.timeoutMinutes * '\uea60');
  95.       Enumeration var3 = this.appSessionHash.keys();
  96.  
  97.       while(var3.hasMoreElements()) {
  98.          HttpSession var4 = (HttpSession)var3.nextElement();
  99.          synchronized(var4){}
  100.  
  101.          try {
  102.             if (var4.getLastAccessedTime() < var1) {
  103.                this.invalidateSession(var4);
  104.             }
  105.          } catch (Throwable var7) {
  106.             throw var7;
  107.          }
  108.       }
  109.  
  110.    }
  111.  
  112.    public void run() {
  113.       this.timeoutSessions();
  114.    }
  115. }
  116.