package edu.vt.marian.WebGate; import java.net.*; import java.io.*; import java.util.*; import edu.vt.marian.common.*; /** Class name: user_manage Class description: this is a thread, it will check user database periodically and write those information which are not used currently back to disk thus the system will not consume unlimited memory when user number and query number grows Author: Jianxin Zhao Finished time: ????, 1998 Known bugs: none Platform: jdk1.1.5 under UNIX */ public class user_manage extends Thread { /** this is just for debugging */ Debug debug; /** this is the user manager object from which this thread is created */ user_manager um; /** this is the interval this thread will check the user database */ private long check_interval; /** this is the interval used to unload user information */ private long unload_interval; // this constructor will create a user manage thread with some default // values public user_manage(user_manager um, Debug debug) { // first initialize data members init(); this.debug = debug; this.um = um; } /** this constructor will create a user manage object from a directory and a user manager object, the directory contain information about the time interval to check user database and to unload users */ public user_manage(String dir, user_manager um, Debug debug) { // first initialize data members init(); this.debug = debug; this.um = um; File user_manage = new File(dir); // read configuration from the file String line; String s; String s1; StringTokenizer st; BufferedReader br; try { FileReader fr = new FileReader(user_manage); br = new BufferedReader(fr); line = br.readLine(); while (line != null) { st = new StringTokenizer(line); if (st.hasMoreTokens()) // in case an empty line is encoutered { s = st.nextToken(); if (! s.startsWith("#")) // lines begin with "#" will be ignored { // process check user database interval if (s.equals("check_interval")) { set_check_interval(Long.parseLong(st.nextToken())); } // process unload user interval if (s.equals("unload_interval")) { set_unload_interval(Long.parseLong(st.nextToken())); } } } line = br.readLine(); }// end while br.close(); } catch (IOException e3) { debug.dumpTrace("error reading data from " + user_manage.getAbsolutePath()); } } /** this method will take all the responsibility of this thread */ public void run() { Date d = null; // then periodically check to see if new servers were installed or // old servers uninstalled while (true) { try { sleep(get_check_interval()); } catch (InterruptedException e) { debug.dumpTrace("sleep exception"); } d = new Date(); debug.dumpTrace("time: " + d.toString() + " method unload is called by user manage"); // inform user manager object to unload users if necessary um.unload(get_unload_interval()); } } /** this method will set the time interval this thread check the user database */ public String set_check_interval(long time) { check_interval = time; return "ok"; } /** this method will return the time interval this thread check user database */ public long get_check_interval() { return check_interval; } /** this method will set the time interval to unload users */ public String set_unload_interval(long time) { unload_interval = time; return "ok"; } /** this method will return the time interval to unload users */ public long get_unload_interval() { return unload_interval; } /** this method will initialize the data members of this class */ private void init() { debug = null; um = null; check_interval = 420000; unload_interval = 420000; } }