From: <mwl...@us...> - 2008-01-31 21:07:34
|
Revision: 612 http://cishell.svn.sourceforge.net/cishell/?rev=612&view=rev Author: mwlinnem Date: 2008-01-31 13:07:23 -0800 (Thu, 31 Jan 2008) Log Message: ----------- Static Executables are now Progress Trackable. They only support the cancel operation, however (currently executed by highlighting the algorithm and click "Remove From List". Probably should have a separate more obvious cancel button). Modified Paths: -------------- trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableAlgorithmFactory.java trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableRunner.java Modified: trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableAlgorithmFactory.java =================================================================== --- trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableAlgorithmFactory.java 2008-01-30 22:32:46 UTC (rev 611) +++ trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableAlgorithmFactory.java 2008-01-31 21:07:23 UTC (rev 612) @@ -29,6 +29,8 @@ import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmFactory; +import org.cishell.framework.algorithm.ProgressMonitor; +import org.cishell.framework.algorithm.ProgressTrackable; import org.cishell.framework.data.Data; import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; @@ -73,7 +75,7 @@ return provider; } - private class StaticExecutableAlgorithm implements Algorithm { + private class StaticExecutableAlgorithm implements Algorithm, ProgressTrackable { private String ALGORITHM; private String ALGORITHM_MACOSX_PPC; private String MACOSX; @@ -87,7 +89,10 @@ CIShellContext context; LogService logger; - public StaticExecutableAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) { + private ProgressMonitor monitor; + + public StaticExecutableAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) + { this.data = data; this.parameters = parameters; this.context = context; @@ -112,7 +117,7 @@ serviceProps.put("Algorithm-Directory", algName); StaticExecutableRunner runner = - new StaticExecutableRunner(bContext, context, serviceProps, parameters, data); + new StaticExecutableRunner(bContext, context, serviceProps, parameters, data, monitor); copyFiles(runner.getTempDirectory()); @@ -234,5 +239,13 @@ } return props; } + + public ProgressMonitor getProgressMonitor() { + return this.monitor; + } + + public void setProgressMonitor(ProgressMonitor monitor) { + this.monitor = monitor; + } } } Modified: trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableRunner.java =================================================================== --- trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableRunner.java 2008-01-30 22:32:46 UTC (rev 611) +++ trunk/templates/org.cishell.templates/src/org/cishell/templates/staticexecutable/StaticExecutableRunner.java 2008-01-31 21:07:23 UTC (rev 612) @@ -32,6 +32,7 @@ import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmProperty; +import org.cishell.framework.algorithm.ProgressMonitor; import org.cishell.framework.data.BasicData; import org.cishell.framework.data.Data; import org.cishell.framework.data.DataProperty; @@ -52,13 +53,21 @@ protected Properties props; protected CIShellContext ciContext; + protected ProgressMonitor monitor; + + protected Boolean processRunning = new Boolean(true); + protected Boolean killedOnPurpose = new Boolean(false); + - public StaticExecutableRunner(BundleContext bContext, CIShellContext ciContext, Properties props, Dictionary parameters, Data[] data) throws IOException { + public StaticExecutableRunner(BundleContext bContext, CIShellContext ciContext, Properties props, + Dictionary parameters, Data[] data, ProgressMonitor monitor) throws IOException { this.ciContext = ciContext; this.props = props; this.parameters = parameters; this.data = data; + this.monitor = monitor; + guiBuilder = (GUIBuilderService)ciContext.getService(GUIBuilderService.class.getName()); @@ -73,7 +82,8 @@ */ public Data[] execute() { try { - String algDir = tempDir + File.separator + props.getProperty("Algorithm-Directory") + File.separator; + String algDir = tempDir + File.separator + props.getProperty("Algorithm-Directory") + + File.separator; chmod(algDir); File[] output = execute(getTemplate(algDir), algDir); @@ -176,29 +186,57 @@ process.getOutputStream().close(); + this.processRunning = new Boolean(true); + + //start thread to consume stdout of process + new Thread(new Runnable() { public void run() { logStream(LogService.LOG_INFO, process.getInputStream()); } }).start(); + //start thread to consume stderr of process + new Thread(new Runnable() { public void run() { logStream(LogService.LOG_ERROR, process.getErrorStream()); } }).start(); + //if we have a monitor... + if (this.monitor != null) { + this.monitor.start(ProgressMonitor.CANCELLABLE, -1); + + //start thread that checks if the user wants to cancel the process + + new Thread(new Runnable() { + public void run() { + checkForCancellation(process); + } + }).start(); + } + process.waitFor(); - //successfully ran? - if (process.exitValue() != 0) { + + this.processRunning = new Boolean(false); + + if (this.monitor != null) { + + this.monitor.done(); + } + + //if the process failed unexpectedly... + if (process.exitValue() != 0 && this.killedOnPurpose.booleanValue() != true) { //display the error message using gui builder guiBuilder.showError("Algorithm Could Not Finish Execution", "Sorry, the algorithm could not finish execution.", "Please check the console window for the error log messages and report the bug.\n" +"Thank you."); } - //get the outputted files + //get the files output from the process + String[] afterFiles = dir.list(); Arrays.sort(beforeFiles); @@ -245,6 +283,21 @@ e.printStackTrace(); } } + + protected void checkForCancellation(Process process) { + while (StaticExecutableRunner.this.processRunning.booleanValue()) { + if (StaticExecutableRunner.this.monitor.isCanceled()) { + StaticExecutableRunner.this.killedOnPurpose = new Boolean(true); + process.destroy(); + } else { + } + + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + } + } protected String[] getTemplate(String algDir) { String template = "" + props.getProperty("template"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |