001: package tide.execute;
002:
003: import snow.utils.SysUtils;
004: import tide.profiler.*;
005: import tide.project.*;
006: import snow.utils.storage.*;
007: import snow.sortabletable.*;
008: import java.util.concurrent.*;
009: import javax.swing.*;
010: import java.awt.event.*;
011: import javax.swing.border.*;
012: import javax.swing.event.*;
013: import javax.swing.text.*;
014: import java.util.*;
015: import java.io.*;
016: import java.text.*;
017:
018: /** Item managed in the processmanager
019: */
020: public final class ProcessItem {
021: // Maybe one of the following (or more) may exist :
022: Process proc; // either a thread or a proc
023: JProcess jproc;
024: SProcess sproc;
025: Thread t;
026: Future f;
027:
028: public boolean isNonTIDE = false;
029: boolean visited = true;
030:
031: private List<File> dumpFiles = new ArrayList<File>();
032:
033: public String name;
034: //String state = "Running";
035: public String pid = "";
036:
037: public enum State {
038: Running, Killed, Done
039: }
040:
041: public State state = State.Running;
042:
043: long startTime = System.currentTimeMillis();
044: long endTime = -1;
045: long memoryBytes = -1; // unknown
046:
047: public boolean autoRemoveFromViewWhenTerminated = false;
048:
049: boolean guessedJMX = false;
050: boolean isJavaProcess = false;
051:
052: public ProcessItem(String name, Process proc) {
053: this .proc = proc;
054: this .name = name;
055: }
056:
057: public ProcessItem(String name, JProcess proc) {
058: this .jproc = proc;
059: this .proc = proc.process;
060: this .isNonTIDE = proc.externalNotTide;
061: this .name = name;
062: this .pid = proc.pid;
063: this .guessedJMX = proc.guessedJMXMode;
064: this .isJavaProcess = true;
065: }
066:
067: public ProcessItem(SProcess proc) {
068: this .sproc = proc;
069: this .name = proc.toStringForPM(); //"System process: "+proc.name;
070: this .pid = proc.pid;
071: this .isNonTIDE = true;
072: this .memoryBytes = proc.getMemory();
073: }
074:
075: public ProcessItem(String name, Thread t) {
076: this .t = t;
077: this .name = name;
078: }
079:
080: public ProcessItem(String name, Future f) {
081: this .f = f;
082: this .name = name;
083: }
084:
085: /** @return null if none.
086: */
087: public File getLastValidDump() {
088: for (int i = dumpFiles.size() - 1; i >= 0; i--) // reverse
089: {
090: File df = dumpFiles.get(i);
091: if (df.exists())
092: return df;
093: }
094: return null;
095: }
096:
097: public void addDumpFile(File f) {
098: // subtle: the file may already exist
099: dumpFiles.remove(f);
100: dumpFiles.add(f);
101: }
102:
103: public List<File> getAllDumps() {
104: return dumpFiles;
105: }
106:
107: public boolean hasBeenKilled = false;
108:
109: public void kill() {
110: if (state == State.Done)
111: return;
112: System.out.println("Killing process " + name + " " + proc);
113:
114: if (proc != null) {
115: proc.destroy();
116: }
117:
118: if (t != null) {
119: t.interrupt();
120: // t.stop(); // deprecated
121: }
122:
123: if (f != null) {
124: f.cancel(true);
125: }
126:
127: if (proc == null && t == null) {
128: if (pid != null && pid.length() > 0) {
129: try {
130: SysUtils.killProcess(pid);
131: } catch (Exception e) {
132: e.printStackTrace();
133: }
134: }
135: }
136:
137: state = State.Killed; // temp, is set to Done from the gobbler ...
138: hasBeenKilled = true;
139: }
140:
141: public boolean isTerminated() {
142: if (state == ProcessItem.State.Done
143: || state == ProcessItem.State.Killed)
144: return true;
145: return false;
146: }
147:
148: }
|