Changeset 891
- Timestamp:
- Dec 7, 2008, 8:46:16 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/base2/net.sf.basedb.pluginutilities/trunk/src/net/sf/basedb/plugins/AbstractRunBinaryPlugin.java
r890 r891 47 47 import net.sf.basedb.core.plugin.Response; 48 48 49 import java.io.BufferedInputStream; 50 import java.io.FileWriter; 49 51 import java.io.IOException; 50 52 import java.io.PrintStream; … … 79 81 80 82 protected AbstractRunBinaryPlugin() { 81 if (debug_output) 83 if (debug_output) { 84 debug_outputfile=(System.getProperty("java.io.tmpdir") + 85 java.io.File.separator + debug_outputfile); 86 debug_subprocess_outputfile=(System.getProperty("java.io.tmpdir") + 87 java.io.File.separator + 88 debug_subprocess_outputfile); 82 89 try 83 90 { … … 88 95 e.printStackTrace(); 89 96 } 97 } 90 98 } 91 99 … … 137 145 138 146 139 protected void execute(String[] cmd , ProgressReporter progress)147 protected void execute(String[] cmd) 140 148 throws InterruptedException, IOException 141 149 { … … 143 151 percentDone+=1; 144 152 progress.display(percentDone,"Running " + about.getName()); 153 cmd[0]=getBinaryPath(this.getClass(),cmd[0]); 145 154 Process p = Runtime.getRuntime().exec(cmd, null, getExecDirectory()); 155 if (debug_output) 156 { 157 BufferedInputStream bis=new BufferedInputStream(p.getInputStream()); 158 FileWriter fw=new FileWriter(debug_subprocess_outputfile); 159 int ch; 160 while ((ch=bis.read())>-1) fw.write(ch); 161 fw.close(); 162 } 146 163 p.waitFor(); 147 164 int status=p.exitValue(); … … 150 167 if (debug_output) System.err.println("execute failed"); 151 168 throw new IOException("Unexpected exit of " + about.getName() + 152 " WeNNIsub-process. Return value: " + status);169 " sub-process. Return value: " + status); 153 170 } 154 171 if (debug_output) System.err.println("execute end succesfully reached"); … … 162 179 163 180 164 pr otectedString getBinaryPath(Class cls, String binaryname)181 private String getBinaryPath(Class cls, String binaryname) 165 182 { 166 183 if (debug_output) System.err.println("Acquiring binary path"); … … 209 226 if (execDirectory == null) { 210 227 execDirectory = new java.io.File 211 (System.getProperty("java.io.tmpdir") + java.io.File.separator + 212 getAbout().getName() + java.io.File.separator + job.getId()); 228 (System.getProperty("java.io.tmpdir") + java.io.File.separator + 229 job.getPluginDefinition().getName() + java.io.File.separator + 230 job.getId()); 213 231 execDirectory.mkdirs(); 214 232 } … … 247 265 248 266 @SuppressWarnings("unchecked") 249 public void run(Request request, Response response, ProgressReporter progress)267 public void run(Request request, Response response, ProgressReporter _progress) 250 268 { 251 269 if (debug_output) System.err.println("run"); 270 progress=_progress; 252 271 DbControl dc=sc.newDbControl(); 253 272 try { 254 273 String name=(String)job.getValue("name"); 255 274 if (name==null) 256 name="New root bioassay set"; 257 Experiment experiment=(Experiment)job.getValue("experiment"); 258 if (experiment==null) 259 throw new InvalidUseOfNullException("experiment"); 260 experiment=Experiment.getById(dc, experiment.getId()); 261 List<RawBioAssay> sources=(List<RawBioAssay>)job.getValues("rawBioAssays"); 262 if (sources==null || sources.size()==0) 263 throw new InvalidUseOfNullException("sources"); 264 for (RawBioAssay rba : sources) 265 dc.reattachItem(rba); 266 runBinary(sources,progress); 267 storeResult(dc,experiment,sources,name,progress); 275 name="New bioassay set"; 276 BioAssaySet source = getSourceBioAssaySet(dc); 277 runBinary(); 278 storeResult(dc,name); 268 279 // dc.commit(); 269 280 response.setDone("Plug-in ended successfully"); 281 if (debug_output) System.err.println("run succesful"); 270 282 } 271 283 catch (Throwable e) { … … 289 301 } 290 302 if (debug_output) System.err.println("run end"); 291 } 292 293 294 abstract protected void runBinary(List<RawBioAssay> sources, 295 ProgressReporter progress) 303 response.setError("All is okay, just make sure that BASE produces error.", 304 null); 305 } 306 307 308 abstract protected void runBinary() 296 309 throws InterruptedException, IOException; 297 310 298 311 299 abstract protected void storeResult(DbControl dc, Experiment experiment, 300 List<RawBioAssay> sources, String name, 301 ProgressReporter progress); 312 abstract protected void storeResult(DbControl dc, String name); 302 313 303 314 … … 317 328 private java.io.File execDirectory; 318 329 private int percentDone=0; 319 320 // debug options. Note, if debug information is on, the exec 321 // directory is not removed after plug-in execution. 322 protected Boolean debug_output=true; 323 private String debug_outputfile="/tmp/base_debug.txt"; 330 private ProgressReporter progress=null; 331 332 // debug settings. Note, if debug information is on, the exec 333 // directory is not removed after plug-in execution. The file names 334 // are modified in the constructor to contain the java temp 335 // directory, i.e. debug files are written into the java temp 336 // directory. The file names are (somewhat) arbitrarily chosen and 337 // may overwrite existing files. 338 protected Boolean debug_output=false; 339 private String debug_outputfile="ARBPdebug.txt"; 340 private String debug_subprocess_outputfile="ARBPdebug_subprocess.txt"; 324 341 }
Note: See TracChangeset
for help on using the changeset viewer.