Update of /cvsroot/aimmath/AIM/WEB-INF/java
In directory sc8-pr-cvs1:/tmp/cvs-serv5333/WEB-INF/java
Modified Files:
Tag: windows
Alice.java Maple.java MaplePool.java
Log Message:
special to windows installation
Index: Alice.java
===================================================================
RCS file: /cvsroot/aimmath/AIM/WEB-INF/java/Alice.java,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -C2 -d -r1.3 -r1.3.2.1
*** Alice.java 25 Aug 2003 21:47:18 -0000 1.3
--- Alice.java 26 Aug 2003 08:27:43 -0000 1.3.2.1
***************
*** 6,9 ****
--- 6,10 ----
*
* This is the main servlet for the AIM system.
+ * Modified by Ken Monks
*
*
***************
*** 100,105 ****
import com.oreilly.servlet.*;
[...1646 lines suppressed...]
*** 1241,1246 ****
ents = entries.elements();
while(ents.hasMoreElements()) {
! e = (AliceLogEntry)ents.nextElement();
! s = e.toHTML() + s;
}
}
--- 1588,1593 ----
ents = entries.elements();
while(ents.hasMoreElements()) {
! e = (AliceLogEntry)ents.nextElement();
! s = e.toHTML() + s;
}
}
***************
*** 1269,1271 ****
// compile-command: "javac -d /aim/WEB-INF/classes Alice.java"
// End:
-
--- 1616,1617 ----
Index: Maple.java
===================================================================
RCS file: /cvsroot/aimmath/AIM/WEB-INF/java/Maple.java,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -C2 -d -r1.3 -r1.3.2.1
*** Maple.java 25 Aug 2003 21:47:18 -0000 1.3
--- Maple.java 26 Aug 2003 08:27:43 -0000 1.3.2.1
***************
*** 6,9 ****
--- 6,10 ----
*
* This class represents a Maple process.
+ * Modified by Ken Monks
*/
***************
*** 12,15 ****
--- 13,17 ----
public class Maple {
+
public Date creationTime;
***************
*** 23,26 ****
--- 25,42 ----
public int id = 0;
+ // KM
+ // The OS PID for this process, obtained by querying the Maple process
+ // a negative value means no process id is available
+ public int pid = -1;
+
+ // True if this maple object has been discarded from the Maple pool
+ public boolean discarded = false;
+
+ // Since I'm not sure how to throw an exception from one thread to another
+ // The MapleCommandThread stores its exceptions in here
+ // It is null if no exception was encountered
+ public Exception exception = null;
+ // END KM
+
// The number of users assigned to this process
public int load = 0;
***************
*** 37,40 ****
--- 53,61 ----
private BufferedReader mapleOutput;
+ // KM
+ // I think we should handle the Maple Error stream also...
+ private BufferedReader mapleError;
+ // END KM
+
// Note: the exec method is passed an argument webOutput.
// The method reads from mapleOutput, and writes to webOutput.
***************
*** 51,54 ****
--- 72,87 ----
"interface(quiet=true, errorcursor=false, errorbreak=0):";
+ // KM
+ // The command used to kill processes in this OS.
+ // Useful for killing hung maple processes whose PID is known
+ public String killProgram = "Process";
+
+ // The argument to the command used to kill processes in this OS.
+ // For example "process -k 1234" has killProgram="process" and
+ // killProgramArg="-k" and pid=1234. In "kill -9 1234" killProgram="kill"
+ // killProgramArg="-9" and pid= 1234.
+ public String killProgramArg = "-k";
+ // END KM
+
// The exec method asks Maple to executes a command, and then to
// print the terminator string given below. The exec method then
***************
*** 82,85 ****
--- 115,134 ----
}
+ // KM
+ public Maple(String prog,String initoptions,String killprog,String killprogarg) throws IOException {
+ this.creationTime = new Date();
+ this.lastUseTime = this.creationTime;
+ if (prog != null)
+ this.program = prog;
+ if (initoptions != null)
+ this.initOptions = initoptions;
+ if (killprog != null)
+ this.killProgram = killprog;
+ if (killprog != null)
+ this.killProgramArg = killprogarg;
+ this.startProcess();
+ }
+ // END KM
+
private void startProcess() throws IOException {
this.lastUseTime = new Date();
***************
*** 88,94 ****
this.mapleOutput =
new BufferedReader(new InputStreamReader(process.getInputStream()));
!
! this.write(initOptions);
}
// send a string to Maple
--- 137,169 ----
this.mapleOutput =
new BufferedReader(new InputStreamReader(process.getInputStream()));
! // KM
! // we may not need this, but it might be a good idea to manually close
! // it when cleaning up destroyed processes
! this.mapleError =
! new BufferedReader(new InputStreamReader(process.getErrorStream()));
! // get the PID
! this.getPID();
! // END KM
! this.write(initOptions);
! }
!
! // KM
! private void getPID() throws IOException {
! String ms = "if assigned(Sockets) and " +
! " member(GetProcessID,{exports(Sockets)}) then " +
! " printf(\"%d\\n\",Sockets:-GetProcessID()) " +
! "else " +
! " printf(\"-1\\n\") " +
! "fi;\n";
! this.write(ms);
! String s = mapleOutput.readLine();
! // if this is not Maple 8 it should not return an integer
! try {
! this.pid = Integer.parseInt(s);
! } catch (Exception e) {
! this.pid = -1;
! }
}
+ // END KM
// send a string to Maple
***************
*** 99,102 ****
--- 174,179 ----
// return true if the process has exited, or was never started
+ // TODO: check what happens if the process is destroyed externally?
+ // Should this be synchronized?
public boolean noProcess() {
if (process == null) return true;
***************
*** 118,121 ****
--- 195,200 ----
// Close the Maple session:
+ // TODO: check the noProcess behavior when the process is destroyed
+ // externally, e.g. from the monitor page.
public void close() {
if (noProcess()) {
***************
*** 123,128 ****
} else {
try {
! this.write("shutdown();quit;\n");
! process.waitFor();
} catch(Exception ex) {}
}
--- 202,207 ----
} else {
try {
! this.write("shutdown();quit;\n");
! process.waitFor();
} catch(Exception ex) {}
}
***************
*** 130,136 ****
public void destroy() {
! try {
process.destroy();
! } catch(Exception e) {}
}
--- 209,245 ----
public void destroy() {
! // KM
! if (pid<0) {
! // END KM
! try {
process.destroy();
! // KM
! mapleInput.close();
! mapleOutput.close();
! mapleError.close();
! process = null;
! // END KM
! } catch(Exception e) {}
! // KM
! } else {
! try {
! // we know the PID so we kill, close, and smash
! // everything that might possibly cause a problem
! // TODO: What happens if the process is already missing?
! Process rt = Runtime.getRuntime().exec(killProgram + " " +
! killProgramArg + " " +
! pid);
! rt.waitFor();
! rt.getOutputStream().close();
! rt.getInputStream().close();
! rt.getErrorStream().close();
! process.destroy();
! mapleInput.close();
! mapleOutput.close();
! mapleError.close();
! process = null;
! } catch (Exception e) { }
! }
! // END KM
}
***************
*** 153,158 ****
public synchronized void exec(String cmd, PrintWriter out, String mathdisplay)
throws Exception {
!
! lastUseTime = new Date();
StringBuffer outstring = new StringBuffer();
--- 262,267 ----
public synchronized void exec(String cmd, PrintWriter out, String mathdisplay)
throws Exception {
!
! lastUseTime = new Date();
StringBuffer outstring = new StringBuffer();
***************
*** 167,179 ****
// Next, read the output, line-by-line, until terminator is read:
while(true) {
! String s = mapleOutput.readLine();
! if (s == null || s.indexOf(terminator) != -1 ) {
! break;
! }
! outstring.append(s);
! outstring.append("\n");
! }
if (out != null) {
--- 276,288 ----
// Next, read the output, line-by-line, until terminator is read:
while(true) {
! String s = mapleOutput.readLine();
! if (s == null || s.indexOf(terminator) != -1 ) {
! break;
! }
! outstring.append(s);
! outstring.append("\n");
! }
if (out != null) {
***************
*** 187,194 ****
}
! public synchronized boolean check() {
StringWriter s = new StringWriter();
PrintWriter p = new PrintWriter(s);
try {
exec("2+2",p);
--- 296,312 ----
}
! public boolean check() {
StringWriter s = new StringWriter();
PrintWriter p = new PrintWriter(s);
+ // KM
+ // I don't think we want to count this as a "last use", otherwise refreshing
+ // the AIM Monitor page resets all the "last use" times to the present time
+ // I think its more useful to have them show the last time the process was
+ // used for something nontrivial. The status report of "ok" indicates that
+ // the check was successful.
+ Date saveLUT = lastUseTime;
+ // END KM
+
try {
exec("2+2",p);
***************
*** 196,199 ****
--- 314,321 ----
} catch (Exception e) {
return(false);
+ // KM
+ } finally {
+ lastUseTime = saveLUT;
+ // END KM
}
}
***************
*** 212,227 ****
switch(c[i]) {
case '\\':
! q[j] = '\\'; q[j+1] = '\\'; j += 2; break;
case '\"':
! q[j] = '\\'; q[j+1] = '\"'; j += 2; break;
case '\n':
! q[j] = '\\'; q[j+1] = 'n'; j += 2; break;
case '\t':
! q[j] = '\\'; q[j+1] = 't'; j += 2; break;
case '\r':
! q[j] = '\\'; q[j+1] = 'r'; j += 2; break;
default:
! q[j] = c[i];
! j++;
}
}
--- 334,349 ----
switch(c[i]) {
case '\\':
! q[j] = '\\'; q[j+1] = '\\'; j += 2; break;
case '\"':
! q[j] = '\\'; q[j+1] = '\"'; j += 2; break;
case '\n':
! q[j] = '\\'; q[j+1] = 'n'; j += 2; break;
case '\t':
! q[j] = '\\'; q[j+1] = 't'; j += 2; break;
case '\r':
! q[j] = '\\'; q[j+1] = 'r'; j += 2; break;
default:
! q[j] = c[i];
! j++;
}
}
Index: MaplePool.java
===================================================================
RCS file: /cvsroot/aimmath/AIM/WEB-INF/java/MaplePool.java,v
retrieving revision 1.2
retrieving revision 1.2.6.1
diff -C2 -d -r1.2 -r1.2.6.1
*** MaplePool.java 5 May 2003 05:15:42 -0000 1.2
--- MaplePool.java 26 Aug 2003 08:27:43 -0000 1.2.6.1
***************
*** 11,14 ****
--- 11,15 ----
* pass it to the returnMaple() method to return it to the pool.
*
+ * Modified by Ken Monks
* TODO: better handling of broken or nonresponding processes
*/
***************
*** 24,27 ****
--- 25,33 ----
public int maxProcesses = 8; // max allowed number of processes
+ // KM
+ public String killProgram = null; // absolute path to the kill program
+ public String killProgramArg = null; // argument to the kill program that precedes the PID
+ // END KM
+
public Hashtable maplesByID;
public Hashtable maplesByStudent;
***************
*** 54,64 ****
}
! private Maple startMaple()
// Start a new Maple process, mark it as busy, add it to the pool,
// and return it. This method does not check the limit on process
// numbers.
throws IOException {
! synchronized (this) {
! Maple maple = new Maple(program,initOptions);
maple.id = nextID++;
maple.busy = true;
--- 60,77 ----
}
! // KM
! // DIST private Maple startMaple()
! private synchronized Maple startMaple()
! // END KM
// Start a new Maple process, mark it as busy, add it to the pool,
// and return it. This method does not check the limit on process
// numbers.
throws IOException {
! // KM
! // DIST synchronized (this) {
! // DIST Maple maple = new Maple(program,initOptions);
! Maple maple = new Maple(program,initOptions,killProgram,killProgramArg);
! // END KM
!
maple.id = nextID++;
maple.busy = true;
***************
*** 68,75 ****
writeLog("Starting new Maple process: ID = " + maple.id + "\n");
return maple;
! }
}
! public Maple getMaple(String student)
// Get a Maple process for use by the specified student. The pool will
// remember which process the student has used, and try to assign the
--- 81,94 ----
writeLog("Starting new Maple process: ID = " + maple.id + "\n");
return maple;
! // KM
! // DIST }
! // END KM
!
}
! // KM
! // DIST public Maple getMaple(String student)
! public synchronized Maple getMaple(String student)
! // END KM
// Get a Maple process for use by the specified student. The pool will
// remember which process the student has used, and try to assign the
***************
*** 82,86 ****
int minload;
! synchronized(this) {
// remember the time.
// (Any process assigned to a student will be unassigned if it
--- 101,107 ----
int minload;
! // KM
! // DIST synchronized(this) {
! // END KM
// remember the time.
// (Any process assigned to a student will be unassigned if it
***************
*** 92,207 ****
if (bestmaple == null) {
! // no process assigned to this student yet
! if (maplesByID.size() < maxProcesses) {
! // under the process limit, so start a new one for this student
! bestmaple = startMaple();
! bestmaple.load = 1;
! maplesByStudent.put(student,bestmaple);
! bestmaple.busy = true;
! bestmaple.user = student;
! return(bestmaple);
! } else {
! // no more processes allowed, so find one that this student
! // can share, with the minimum possible load
! ids = maplesByID.keys();
! minload = Integer.MAX_VALUE;
! while (ids.hasMoreElements()) {
! id = (Integer)ids.nextElement();
! maple = (Maple)maplesByID.get(id);
! if ((! maple.busy) && (maple.load < minload)) {
! minload = Math.min(minload,maple.load);
! bestmaple = maple;
! }
! }
! if (bestmaple == null) {
! writeLog("Servlet busy - request refused\n");
! return(null);
! } else {
! bestmaple.busy = true;
! bestmaple.load++;
! maplesByStudent.put(student,bestmaple);
! bestmaple.user = student;
! return(bestmaple);
! }
! }
} else {
! // there is a process assigned to this student
! if (bestmaple.busy) {
! // the assigned process is busy
! if (! student.equals("(admin)") &&
! student.equals(bestmaple.user) &&
! ((new Date()).getTime() -
! bestmaple.lastUseTime.getTime()) < 30000) {
! // The process is still working on the last request from
! // this student, which was submitted less than 30 seconds
! // ago; so we reject the request.
! return(null);
! }
! // find another process that this student can use
! ids = maplesByID.keys();
! oldmaple = bestmaple;
! bestmaple = null;
! minload = Integer.MAX_VALUE;
! while (ids.hasMoreElements()) {
! id = (Integer)ids.nextElement();
! maple = (Maple) maplesByID.get(id);
! if ((! maple.busy) && (maple.load < minload)) {
! minload = Math.min(minload,maple.load);
! bestmaple = maple;
! }
! }
! if (bestmaple == null) {
! //
! if (maplesByID.size() >= maxProcesses) {
! writeLog("Servlet busy - request refused\n");
! return(null);
! } else {
! bestmaple = startMaple();
! }
! }
! bestmaple.busy = true;
! bestmaple.user = student;
! oldmaple.load--;
! bestmaple.load++;
! maplesByStudent.put(student,bestmaple);
! return(bestmaple);
! } else {
! // assigned process is not busy
! bestmaple.busy = true;
! bestmaple.user = student;
! return(bestmaple);
! }
}
! }
}
! public void removeMaple(Maple maple) {
Enumeration students;
String student;
!
! synchronized(this) {
maplesByID.remove(new Integer(maple.id));
students = maplesByStudent.keys();
while (students.hasMoreElements()) {
! student = (String)students.nextElement();
! if (maplesByStudent.get(student) == maple) {
! maplesByStudent.remove(student);
! }
}
! }
}
! public void returnMaple(Maple maple)
throws IOException {
! Enumeration students;
! String student;
!
if (maple.condemned) {
removeMaple(maple);
--- 113,246 ----
if (bestmaple == null) {
! // no process assigned to this student yet
! if (maplesByID.size() < maxProcesses) {
! // under the process limit, so start a new one for this student
! bestmaple = startMaple();
! bestmaple.load = 1;
! maplesByStudent.put(student,bestmaple);
! bestmaple.busy = true;
! bestmaple.user = student;
! return(bestmaple);
! } else {
! // no more processes allowed, so find one that this student
! // can share, with the minimum possible load
! ids = maplesByID.keys();
! minload = Integer.MAX_VALUE;
! while (ids.hasMoreElements()) {
! id = (Integer)ids.nextElement();
! maple = (Maple)maplesByID.get(id);
! if ((! maple.busy) && (maple.load < minload)) {
! minload = Math.min(minload,maple.load);
! bestmaple = maple;
! }
! }
! if (bestmaple == null) {
! writeLog("Servlet busy - request refused\n");
! return(null);
! } else {
! bestmaple.busy = true;
! bestmaple.load++;
! maplesByStudent.put(student,bestmaple);
! bestmaple.user = student;
! return(bestmaple);
! }
! }
} else {
! // there is a process assigned to this student
! if (bestmaple.busy) {
! // the assigned process is busy
! if (! student.equals("(admin)") &&
! student.equals(bestmaple.user) &&
! ((new Date()).getTime() -
! bestmaple.lastUseTime.getTime()) < 30000) {
! // The process is still working on the last request from
! // this student, which was submitted less than 30 seconds
! // ago; so we reject the request.
! return(null);
! }
! // find another process that this student can use
! ids = maplesByID.keys();
! oldmaple = bestmaple;
! bestmaple = null;
! minload = Integer.MAX_VALUE;
! while (ids.hasMoreElements()) {
! id = (Integer)ids.nextElement();
! maple = (Maple) maplesByID.get(id);
! if ((! maple.busy) && (maple.load < minload)) {
! minload = Math.min(minload,maple.load);
! bestmaple = maple;
! }
! }
! if (bestmaple == null) {
! //
! if (maplesByID.size() >= maxProcesses) {
! writeLog("Servlet busy - request refused\n");
! return(null);
! } else {
! bestmaple = startMaple();
! }
! }
! bestmaple.busy = true;
! bestmaple.user = student;
! oldmaple.load--;
! bestmaple.load++;
! maplesByStudent.put(student,bestmaple);
! return(bestmaple);
! } else {
! // assigned process is not busy
! bestmaple.busy = true;
! bestmaple.user = student;
! return(bestmaple);
! }
}
! // KM
! // DIST }
! // END KM
}
! // KM
! // removes the maple object from the pool,
! // but doesn't kill the process if its running
! // this is only called by other higher level routines,
! // so I am changing it from public to private
! // dist public void removeMaple(Maple maple) {
! private synchronized void removeMaple(Maple maple) {
! // END KM
Enumeration students;
String student;
! // KM
! // DIST synchronized(this) {
! // END KM
maplesByID.remove(new Integer(maple.id));
students = maplesByStudent.keys();
while (students.hasMoreElements()) {
! student = (String)students.nextElement();
! if (maplesByStudent.get(student) == maple) {
! maplesByStudent.remove(student);
! }
}
! // KM
! // DIST }
! // END KM
}
! // returns a Maple object to the pool when its done executing a command
! // KM
! // DIST public void returnMaple(Maple maple)
! public synchronized void returnMaple(Maple maple)
! // END KM
throws IOException {
! // KM
! // dist Enumeration students;
! // dist String student;
! // dist synchronized(this) {
! // END KM
if (maple.condemned) {
removeMaple(maple);
***************
*** 215,283 ****
}
public void discardMaple(Maple maple) {
- Enumeration students;
- String student;
! removeMaple(maple);
! try {
! writeLog("Closing condemned Maple process: ID = " + maple.id +"\n");
! maple.destroy();
! }
! catch(Exception e) {};
}
! public void condemn(Maple maple) {
! synchronized(this) {
maple.condemned = true;
if ( ! maple.busy) {
! removeMaple(maple);
! try {
! maple.close();
! }
! catch(Exception e) {};
}
! }
}
// close all the processes in the pool
! public void drain()
throws IOException {
Maple maple;
Integer id;
Enumeration ids;
-
- writeLog("Draining Maple process pool");
! synchronized(this) {
! ids = maplesByID.keys();
! while (ids.hasMoreElements()) {
! id = (Integer)ids.nextElement();
! maple = (Maple)maplesByID.get(id);
! maple.close();
! }
! maplesByID.clear();
! maplesByStudent.clear();
}
}
! // close all the processes in the pool
! public void scorch()
throws IOException {
Maple maple;
Integer id;
Enumeration ids;
-
- writeLog("Scorching Maple process pool");
! synchronized(this) {
ids = maplesByID.keys();
while (ids.hasMoreElements()) {
! id = (Integer)ids.nextElement();
! maple = (Maple)maplesByID.get(id);
! maple.destroy();
}
maplesByID.clear();
maplesByStudent.clear();
! }
}
--- 254,356 ----
}
+ // This removes the Maple object from the pool and unconditionally kills its process
+ // KM
+ // DIST public void discardMaple(Maple maple) {
+ // END KM
public void discardMaple(Maple maple) {
! // KM
! // dist Enumeration students;
! // dist String student;
! // END KM
!
! removeMaple(maple);
! try {
! // KM
! // dist writeLog("Closing condemned Maple process: ID = " + maple.id +"\n");
! writeLog("Destroying condemned Maple process: ID = " + maple.id +"\n");
! // END KM
! maple.destroy();
! }
! catch(Exception e) {};
! // KM
! maple.discarded = true;
! // END KM
}
! // Condemn the maple process and if its not busy, close it.
! // KM
! // DIST public void condemn(Maple maple) {
! public synchronized void condemn(Maple maple) {
! // DIST synchronized(this) {
! // END KM
maple.condemned = true;
if ( ! maple.busy) {
! removeMaple(maple);
! try {
! maple.close();
! } catch(Exception e) {};
}
! // KM
! // DIST }
! // END KM
}
// close all the processes in the pool
! // KM
! // DIST public void drain()
! public synchronized void drain()
! // END KM
throws IOException {
Maple maple;
Integer id;
Enumeration ids;
! writeLog("Draining Maple process pool");
! // KM
! // DIST synchronized(this) {
! // END KM
! ids = maplesByID.keys();
! while (ids.hasMoreElements()) {
! id = (Integer)ids.nextElement();
! maple = (Maple)maplesByID.get(id);
! maple.close();
}
+ maplesByID.clear();
+ maplesByStudent.clear();
+ // KM
+ // DIST }
+ // END KM
+
}
! // destroy all the processes in the pool
! // KM
! // DIST public void scorch()
! public synchronized void scorch()
! // END KM
throws IOException {
Maple maple;
Integer id;
Enumeration ids;
! writeLog("Scorching Maple process pool");
! // KM
! // DIST synchronized(this) {
! // END KM
ids = maplesByID.keys();
while (ids.hasMoreElements()) {
! id = (Integer)ids.nextElement();
! maple = (Maple)maplesByID.get(id);
! // KM
! maple.discarded = true;
! // END KM
! maple.destroy();
}
maplesByID.clear();
maplesByStudent.clear();
! // KM
! // DIST }
! // END KM
}
***************
*** 286,290 ****
// unassign processes from students who have not accessed the
// system for age0 milliseconds.
! public void clean(long age0,long age1)
throws IOException {
long cutoff0 = (new Date()).getTime() - age0;
--- 359,366 ----
// unassign processes from students who have not accessed the
// system for age0 milliseconds.
! // KM
! // DIST public void clean(long age0,long age1)
! public synchronized void clean(long age0,long age1)
! // END KM
throws IOException {
long cutoff0 = (new Date()).getTime() - age0;
***************
*** 297,329 ****
msg.append("Cleaning Maple process pool\n");
!
! synchronized(this) {
! ids = maplesByID.keys();
! while(ids.hasMoreElements()) {
! id = (Integer)ids.nextElement();
! maple = (Maple) maplesByID.get(id);
! if (maple.lastUseTime.getTime() < cutoff0 ||
! maple.creationTime.getTime() < cutoff1) {
! msg.append("Condemning old process " + maple.id + "\n");
! condemn(maple);
! }
}
! students = maplesByStudent.keys();
! while (students.hasMoreElements()) {
! student = (String) students.nextElement();
! if (((Date)lastAccessByStudent.get(student)).getTime()
! < cutoff0) {
! lastAccessByStudent.remove(student);
! maple = (Maple) maplesByStudent.get(student);
! if (maple != null) {
! maplesByStudent.remove(student);
! maple.load--;
! }
! }
}
- writeLog(msg.toString());
}
}
--- 373,407 ----
msg.append("Cleaning Maple process pool\n");
! // KM
! // DIST synchronized(this) {
! // END KM
! ids = maplesByID.keys();
! while(ids.hasMoreElements()) {
! id = (Integer)ids.nextElement();
! maple = (Maple) maplesByID.get(id);
! if (maple.lastUseTime.getTime() < cutoff0 ||
! maple.creationTime.getTime() < cutoff1) {
! msg.append("Condemning old process " + maple.id + "\n");
! condemn(maple);
}
+ }
! students = maplesByStudent.keys();
! while (students.hasMoreElements()) {
! student = (String) students.nextElement();
! if (((Date)lastAccessByStudent.get(student)).getTime() < cutoff0) {
! lastAccessByStudent.remove(student);
! maple = (Maple) maplesByStudent.get(student);
! if (maple != null) {
! maplesByStudent.remove(student);
! maple.load--;
! }
}
}
+ writeLog(msg.toString());
+ // KM
+ // DIST }
+ // END KM
}
***************
*** 339,343 ****
}
! public String statusReport() {
StringBuffer report = new StringBuffer();
Enumeration ids,students;
--- 417,424 ----
}
! // KM
! // DIST public String statusReport() {
! public synchronized String statusReport() {
! // END KM
StringBuffer report = new StringBuffer();
Enumeration ids,students;
***************
*** 348,436 ****
String creationtime,lastusetime,user,status;
Hashtable index;
!
! synchronized (this) {
ids = maplesByID.keys();
if (ids.hasMoreElements()) {
! report.append("<table border width='100%'>\n" +
! " <tr>\n" +
! " <th>ID</th>\n" +
! " <th>Created</th>\n" +
! " <th>Last Used</th>\n" +
! " <th>User</th>\n" +
! " <th>Load</th>\n" +
! " <th>Status</th>\n" +
! " </tr>\n");
!
! index = new Hashtable();
! while (ids.hasMoreElements()) {
! id = (Integer) ids.nextElement();
! index.put(id,new Vector());
! maple = (Maple)maplesByID.get(id);
! creationtime = tf.format(maple.creationTime);
! lastusetime = tf.format(maple.lastUseTime);
!
! if (maple.busy) {
! user = maple.user;
! status = "busy";
! } else {
! user = "(free)";
! if (maple.condemned) {
! status = "condemned";
! } else {
! if (maple.check()) {
! status = "ok";
! } else {
! status = "not ok - closing";
! condemn(maple);
! }
! }
! }
!
! report.append(" <tr>\n" +
! " <td>" + maple.id + "</td>\n" +
! " <td>" + creationtime + "</td>\n" +
! " <td>" + lastusetime + "</td>\n" +
! " <td>" + user + "</td>\n" +
! " <td>" + maple.load + "</td>\n" +
! " <td>" + status + "</td>\n" +
! " </tr>\n");
!
! }
! report.append("</table>\n");
! students = maplesByStudent.keys();
! while (students.hasMoreElements()) {
! student = (String) students.nextElement();
! id = new Integer(((Maple) (maplesByStudent.get(student))).id);
! ((Vector) index.get(id)).addElement(student);
! }
! report.append("<h2>Process assignments:</h2>\n");
! report.append("<table border width='100%'>\n" +
! "<tr>\n" +
! "<th width='10%'>Process</th>\n" +
! "<th width='90%'>Students</th>\n" );
! ids = maplesByID.keys();
! while (ids.hasMoreElements()) {
! id = (Integer) ids.nextElement();
! report.append("<tr><td width='10%'>" +
! id.intValue() +
! "</td>\n<td width='90%'>");
! students = ((Vector) index.get(id)).elements();
! while (students.hasMoreElements()) {
! student = (String) students.nextElement();
! report.append(student + " ");
! }
! report.append("</td></tr>\n");
! }
! report.append("</table>\n");
} else {
! report.append("There are no active Maple processes.<br>\n");
}
return (report.toString());
}
! }
}
--- 429,531 ----
String creationtime,lastusetime,user,status;
Hashtable index;
! // KM
! // DIST synchronized (this) {
! // END KM
ids = maplesByID.keys();
if (ids.hasMoreElements()) {
! report.append(
! "<table border width='100%'>\n" +
! " <tr>\n" +
! " <th>ID</th>\n" +
! // KM
! " <th>PID</th>\n" +
! // END KM
! " <th>Created</th>\n" +
! " <th>Last Used</th>\n" +
! " <th>User</th>\n" +
! " <th>Load</th>\n" +
! " <th>Status</th>\n" +
! " </tr>\n");
!
! index = new Hashtable();
! while (ids.hasMoreElements()) {
! id = (Integer) ids.nextElement();
! index.put(id,new Vector());
! maple = (Maple)maplesByID.get(id);
! creationtime = tf.format(maple.creationTime);
! lastusetime = tf.format(maple.lastUseTime);
!
! if (maple.busy) {
! user = maple.user;
! status = "busy";
! } else {
! user = "(free)";
! if (maple.condemned) {
! status = "condemned";
! } else {
! if (maple.check()) {
! status = "ok";
! } else {
! status = "not ok - closing";
! condemn(maple);
! }
! }
! }
!
! report.append(" <tr>\n" +
! " <td>" + maple.id + "</td>\n" +
! // KM
! " <td>" + (maple.pid == -1 ? "N/A" : Integer.toString(maple.pid)) + "</td>\n" +
! // END KM
! " <td>" + creationtime + "</td>\n" +
! " <td>" + lastusetime + "</td>\n" +
! " <td>" + user + "</td>\n" +
! " <td>" + maple.load + "</td>\n" +
! " <td>" + status + "</td>\n" +
! " </tr>\n");
!
! }
! report.append("</table>\n");
!
! students = maplesByStudent.keys();
! while (students.hasMoreElements()) {
! student = (String) students.nextElement();
! id = new Integer(((Maple) (maplesByStudent.get(student))).id);
! ((Vector) index.get(id)).addElement(student);
! }
!
! report.append("<h2>Process assignments:</h2>\n");
! report.append("<table border width='100%'>\n" +
! "<tr>\n" +
! "<th width='10%'>Process</th>\n" +
! "<th width='90%'>Students</th>\n" );
! ids = maplesByID.keys();
! while (ids.hasMoreElements()) {
! id = (Integer) ids.nextElement();
! report.append(
! "<tr><td width='10%'>" +
! id.intValue() +
! "</td>\n<td width='90%'>");
! students = ((Vector) index.get(id)).elements();
! while (students.hasMoreElements()) {
! student = (String) students.nextElement();
! report.append(student + " ");
! }
! report.append("</td></tr>\n");
! }
! report.append("</table>\n");
} else {
! report.append("There are no active Maple processes.<br>\n");
}
return (report.toString());
}
! // KM
! // DIST }
! // END KM
!
}
|