Changeset 891


Ignore:
Timestamp:
Dec 7, 2008, 8:46:16 PM (13 years ago)
Author:
Jari Häkkinen
Message:

Changed interface and added debug code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/base2/net.sf.basedb.pluginutilities/trunk/src/net/sf/basedb/plugins/AbstractRunBinaryPlugin.java

    r890 r891  
    4747import net.sf.basedb.core.plugin.Response;
    4848
     49import java.io.BufferedInputStream;
     50import java.io.FileWriter;
    4951import java.io.IOException;
    5052import java.io.PrintStream;
     
    7981
    8082  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);
    8289      try
    8390      {
     
    8895        e.printStackTrace();
    8996      }
     97    }
    9098  }
    9199
     
    137145
    138146
    139   protected void execute(String[] cmd, ProgressReporter progress)
     147  protected void execute(String[] cmd)
    140148    throws InterruptedException, IOException
    141149  {
     
    143151    percentDone+=1;
    144152    progress.display(percentDone,"Running " + about.getName());
     153    cmd[0]=getBinaryPath(this.getClass(),cmd[0]);
    145154    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    }
    146163    p.waitFor();
    147164    int status=p.exitValue();
     
    150167      if (debug_output) System.err.println("execute failed");
    151168      throw new IOException("Unexpected exit of " + about.getName() +
    152                             "WeNNI sub-process. Return value: " + status);
     169                            " sub-process. Return value: " + status);
    153170    }
    154171    if (debug_output) System.err.println("execute end succesfully reached");
     
    162179
    163180
    164   protected String getBinaryPath(Class cls, String binaryname)
     181  private String getBinaryPath(Class cls, String binaryname)
    165182  {
    166183    if (debug_output) System.err.println("Acquiring binary path");
     
    209226    if (execDirectory == null) {
    210227      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());
    213231      execDirectory.mkdirs();
    214232    }
     
    247265
    248266  @SuppressWarnings("unchecked")
    249   public void run(Request request, Response response, ProgressReporter progress)
     267  public void run(Request request, Response response, ProgressReporter _progress)
    250268  {
    251269    if (debug_output) System.err.println("run");
     270    progress=_progress;
    252271    DbControl dc=sc.newDbControl();
    253272    try {
    254273      String name=(String)job.getValue("name");
    255274      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);
    268279//      dc.commit();
    269280      response.setDone("Plug-in ended successfully");
     281      if (debug_output) System.err.println("run succesful");
    270282    }
    271283    catch (Throwable e) {
     
    289301    }
    290302    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()
    296309    throws InterruptedException, IOException;
    297310
    298311
    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);
    302313
    303314
     
    317328  private java.io.File execDirectory;
    318329  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";
    324341}
Note: See TracChangeset for help on using the changeset viewer.