Changeset 31718 for main/trunk/gli/src
- Timestamp:
- 2017-05-31T18:05:11+12:00 (7 years ago)
- Location:
- main/trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
r31670 r31718 1456 1456 static private class ExternalApplication 1457 1457 extends Thread { 1458 private Process process = null;1458 private SafeProcess process = null; 1459 1459 /** The initial command string given to this sub-process. */ 1460 1460 private String command = null; … … 1515 1515 } 1516 1516 DebugStream.println("Running " + whole_command.toString()); 1517 Runtime rt = Runtime.getRuntime(); 1518 process = rt.exec(commands); 1519 process.waitFor(); 1517 process = new SafeProcess(commands); 1520 1518 } 1521 1519 else { 1522 1520 DebugStream.println("Running " + command); 1523 Runtime rt = Runtime.getRuntime(); 1524 process = rt.exec(command); 1525 process.waitFor(); 1526 } 1521 process = new SafeProcess(command); 1522 } 1523 process.runProcess(); 1527 1524 } 1528 1525 catch (Exception exception) { … … 1548 1545 public void stopExternalApplication() { 1549 1546 if(process != null) { 1550 process.destroy(); 1547 SafeProcess.log("*** stopExternalApplication called."); 1548 process.cancelRunningProcess(); 1551 1549 } 1552 1550 } … … 1555 1553 static private class BrowserApplication 1556 1554 extends Thread { 1557 private Process process = null;1555 private SafeProcess process = null; 1558 1556 /** The initial command string given to this sub-process. */ 1559 1557 private String command = null; … … 1595 1593 printArray(new_commands); 1596 1594 1597 Runtime rt = Runtime.getRuntime(); 1598 process = rt.exec(new_commands); 1599 int exitCode = process.waitFor(); 1595 process = new SafeProcess(new_commands); 1596 int exitCode = process.runProcess(); 1600 1597 if (exitCode != 0) { // if Netscape or mozilla was not open 1601 1598 DebugStream.println("couldn't do remote, trying original command"); 1602 1599 printArray(commands); 1603 process = rt.exec(commands); // try the original command 1600 process = null; 1601 process = new SafeProcess(commands); // try the original command 1602 process.runProcess(); 1604 1603 } 1605 1604 } else { … … 1611 1610 } 1612 1611 DebugStream.println("Running " + whole_command.toString()); 1613 Runtime rt = Runtime.getRuntime(); 1614 process = rt.exec(commands); 1615 process.waitFor(); 1612 process = new SafeProcess(commands); 1613 process.runProcess(); 1616 1614 } 1617 1615 } … … 1635 1633 public void stopBrowserApplication() { 1636 1634 if(process != null) { 1637 process.destroy(); 1635 SafeProcess.log("*** stopBrowserApplication called."); 1636 process.cancelRunningProcess(); 1638 1637 } 1639 1638 } -
main/trunk/gli/src/org/greenstone/gatherer/util/Readme_Using_SafeProcess.txt
r31717 r31718 163 163 164 164 165 All the runProcess() variants do a Process.waitFor(). This means all runProcess() variants block the primary thread, which is the thread in which they're executing, until the internal Process has completed. 165 166 166 167 If you want to completely override the default behaviour of any of SafeProcess' iostream related worker threads (such as if you want to read a char at a time from the stderr stream and do something, instead of the default behaviour of reading a line at a time from it), then call this method. … … 756 757 + src/org/greenstone/gatherer/gui/DownloadPane.java 757 758 + src/org/greenstone/gatherer/util/GS3ServerThread.java 758 + 2 src/org/greenstone/gatherer/Gatherer.java [2 MORE but don't want to mess with those]759 + 4 src/org/greenstone/gatherer/Gatherer.java [All 4 instances that used Process now go through SafeProcess instead] 759 760 + 1 src/org/greenstone/gatherer/download/ServerInfoDialog.java 760 761 + 2 src/org/greenstone/gatherer/greenstone/Classifiers.java -
main/trunk/gli/src/org/greenstone/gatherer/util/SafeProcess.java
r31716 r31718 162 162 * This method returns a boolean that you can call sentInterrupt. 163 163 */ 164 public boolean cancelRunningProcess() { 164 public boolean cancelRunningProcess() { 165 165 166 166 boolean forceWaitUntilInterruptible = true; … … 921 921 */ 922 922 923 if(pid == -1) { 923 if(pid == -1) { // if the process has already terminated, or we can't get the pid for any reason: 924 924 p.destroy(); // at minimum. Will have no effect if the process had already terminated 925 925 } else { … … 929 929 if(!killUnixProcessWithID(pid, !forceKill, killEntireProcessTree)) { // send sig TERM (kill -15 or kill -TERM) 930 930 killUnixProcessWithID(pid, forceKill, killEntireProcessTree); // send sig KILL (kill -9 or kill -KILL) 931 } 931 } 932 // if both kill commands failed for whatever reason, can still at least end the top level process: 933 p.destroy(); // no effect if the process has already terminated. 932 934 } 933 935
Note:
See TracChangeset
for help on using the changeset viewer.