Changeset 4120


Ignore:
Timestamp:
Feb 4, 2008, 12:09:16 PM (15 years ago)
Author:
Nicklas Nordborg
Message:

References #636: Kill a running job

All core plug-ins can now be killed. Added this to the example plug-ins as well. Support for interruption in some more places in the core.

Location:
trunk/src
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/plugins/SimpleExport.java

    r4095 r4120  
    6161import net.sf.basedb.core.query.Restrictions;
    6262import net.sf.basedb.core.query.ResultIterator;
     63import net.sf.basedb.core.signal.SignalHandler;
     64import net.sf.basedb.core.signal.SignalTarget;
     65import net.sf.basedb.core.signal.ThreadSignalHandler;
    6366import net.sf.basedb.util.Enumeration;
    6467import net.sf.basedb.util.Values;
     
    8992public class SimpleExport
    9093  extends AbstractExporterPlugin
    91   implements InteractivePlugin 
     94  implements InteractivePlugin, SignalTarget
    9295{
    9396
     
    112115  private RequestInformation configureJob;
    113116
     117  private ThreadSignalHandler signalHandler;
     118 
    114119  /*
    115120    From the Plugin interface
     
    223228    throws IOException
    224229  {
     230    if (signalHandler != null) signalHandler.setWorkerThread(null);
     231   
    225232    // Input parameters for the export
    226233    Item itemType = Item.valueOf((String)job.getValue("itemType"));
     
    298305      query.setParameter("_excludes_", Arrays.asList(Values.getInt(exclude.split(","))), Type.INT);
    299306    }
    300    
     307    checkInterrupted();
    301308    exportProperties(dc, out, format, exportedProperties, itemType, query, progress);
    302309  }
     
    311318  }
    312319  // -------------------------------------------
    313  
     320  /*
     321    From the SignalTarget interface
     322    -------------------------------------------
     323  */
     324  public SignalHandler getSignalHandler()
     325  {
     326    signalHandler = new ThreadSignalHandler();
     327    return signalHandler;
     328  }
     329  // -------------------------------------------
     330
    314331  private void initGuiContexts()
    315332  {
     
    474491      do
    475492      {
     493        checkInterrupted();
    476494        result = queryWrapper.iterate();
    477495        while (result.hasNext())
    478496        {
     497          checkInterrupted();
    479498          numExported++;
    480499          Object item = result.next();
  • trunk/src/core/net/sf/basedb/core/signal/ProgressReporterSignalHandler.java

    r4118 r4120  
    3939  and the percentage value is less than 100 the signal handler will check if a signal
    4040  has been received. If so, a {@link SignalReceivedException} will be thrown.
    41   Here is a general outline of a plug-in that uses this signal handler:
     41  <p>
     42  NOTE! Some parts of the BASE core only uses the <code>Thread.interrupt()</code>
     43  mechanism for aborting a process. For example, long-running queries against the
     44  dynamic database. In this case we recommend that a {@link ThreadSignalHandler},
     45  possible linked with {@link DelegatingSignalHandler}, is used instead.
     46  <p>
     47  Here is a general outline of a plug-in that uses the progress reporter signal handler:
    4248 
    4349  <pre class="code">
     
    9096  @author nicklas
    9197  @version 2.6
     98  @see ThreadSignalHandler
    9299  @base.modified $Date$
    93100*/
  • trunk/src/core/net/sf/basedb/util/FileUtil.java

    r4034 r4120  
    3737import net.sf.basedb.core.query.Orders;
    3838import net.sf.basedb.core.query.Restrictions;
     39import net.sf.basedb.core.signal.ThreadSignalHandler;
    3940
    4041import java.io.BufferedInputStream;
     
    99100    while (bytes != -1) // -1 = end of stream
    100101    {
     102      ThreadSignalHandler.checkInterrupted();
    101103      bytes = in.read(buffer, 0, buffer.length);
    102104      if (bytes > 0)
     
    128130    while (bytes != -1) // -1 = end of stream
    129131    {
     132      ThreadSignalHandler.checkInterrupted();
    130133      bytes = in.read(buffer, 0, buffer.length);
    131134      if (bytes > 0)
     
    275278    while (directories.size() > 0)
    276279    {
     280      ThreadSignalHandler.checkInterrupted();
    277281      File dir = directories.remove(0);
    278282      File[] files = dir.listFiles(filter);
    279283      for (File f : files)
    280284      {
     285        ThreadSignalHandler.checkInterrupted();
    281286        if (f.isDirectory())
    282287        {
  • trunk/src/examples/plugins/src/net/sf/basedb/exampleplugins/ExampleAnalyzer.java

    r3675 r4120  
    4444import net.sf.basedb.core.query.Restrictions;
    4545import net.sf.basedb.core.query.Selects;
     46import net.sf.basedb.core.signal.SignalHandler;
     47import net.sf.basedb.core.signal.SignalTarget;
     48import net.sf.basedb.core.signal.ThreadSignalHandler;
    4649
    4750import net.sf.basedb.core.plugin.About;
     
    7275public class ExampleAnalyzer
    7376  extends AbstractPlugin
    74   implements InteractivePlugin
     77  implements InteractivePlugin, SignalTarget
    7578{
    7679
     
    105108  private PluginParameter<Float> factorParameter;
    106109 
     110  // So we can react to ABORT requests
     111  private ThreadSignalHandler signalHandler;
     112 
    107113  /**
    108114    Create a new plugin instance.
     
    133139  public void run(Request request, Response response, ProgressReporter progress)
    134140  {
     141    // Ensure that the ABORT signal gets sent to this thread
     142    if (signalHandler != null) signalHandler.setWorkerThread(null);
     143
    135144    // Open a connection to the database
    136145    // sc is set by init() method
     
    179188      // Create batcher and copy data
    180189      SpotBatcher batcher = result.getSpotBatcher();
     190      // Check for the ABORT signal before a lengthy operation
     191      checkInterrupted();
    181192      int spotsCopied = batcher.insert(query);
    182193      batcher.close();
     
    284295      response.setError(ex.getMessage(), Arrays.asList(ex));
    285296    }
     297  }
     298  // -------------------------------------------
     299  /*
     300    From the SignalTarget interface
     301    -------------------------------------------
     302  */
     303  public SignalHandler getSignalHandler()
     304  {
     305    signalHandler = new ThreadSignalHandler();
     306    return signalHandler;
    286307  }
    287308  // -------------------------------------------
  • trunk/src/examples/plugins/src/net/sf/basedb/exampleplugins/ExampleImporter.java

    r3675 r4120  
    4343import net.sf.basedb.core.plugin.Request;
    4444import net.sf.basedb.core.plugin.Response;
     45import net.sf.basedb.core.signal.SignalHandler;
     46import net.sf.basedb.core.signal.SignalTarget;
     47import net.sf.basedb.core.signal.ThreadSignalHandler;
    4548
    4649import java.io.InputStream;
     
    6467public class ExampleImporter
    6568  extends AbstractPlugin
    66   implements InteractivePlugin, AutoDetectingImporter
     69  implements InteractivePlugin, AutoDetectingImporter, SignalTarget
    6770{
    6871
     
    98101  private DbControl dc;
    99102 
     103  // So we can react to ABORT requests
     104  private ThreadSignalHandler signalHandler;
     105 
    100106  /**
    101107    Create a new example importer.
     
    126132  public void run(Request request, Response response, ProgressReporter progress)
    127133  {
     134    // Ensure that the ABORT signal gets sent to this thread
     135    if (signalHandler != null) signalHandler.setWorkerThread(null);
     136   
    128137    // Open a connection to the database
    129138    // sc is set by init() method
     
    245254    throws BaseException
    246255  {
     256    // Check if the ABORT signal has been sent
     257    checkInterrupted();
    247258    /*
    248259      Pseudo code:
    249260      Parse input stream, for each found sample:
     261      checkInterrupted();  // Do this as the first thing in a loop
    250262      String name = ...
    251263      String externalId = ...
     
    267279  }
    268280  // -------------------------------------------
     281  /*
     282    From the SignalTarget interface
     283    -------------------------------------------
     284  */
     285  public SignalHandler getSignalHandler()
     286  {
     287    signalHandler = new ThreadSignalHandler();
     288    return signalHandler;
     289  }
     290  // -------------------------------------------
    269291
    270292  private RequestInformation getConfigureJob(GuiContext context)
  • trunk/src/plugins/core/net/sf/basedb/plugins/Base1PluginExecuter.java

    r4095 r4120  
    7474import net.sf.basedb.core.query.Hql;
    7575import net.sf.basedb.core.query.Orders;
     76import net.sf.basedb.core.signal.SignalException;
     77import net.sf.basedb.core.signal.SignalHandler;
     78import net.sf.basedb.core.signal.SignalTarget;
     79import net.sf.basedb.core.signal.ThreadSignalHandler;
    7680import net.sf.basedb.util.Enumeration;
    7781import net.sf.basedb.util.Values;
     
    122126public class Base1PluginExecuter
    123127  extends AbstractAnalysisPlugin
    124   implements InteractivePlugin
     128  implements InteractivePlugin, SignalTarget
    125129{
    126130
     
    264268
    265269  private int pluginDirectoryId = -1;
     270 
     271  private ThreadSignalHandler signalHandler;
    266272
    267273  /* From InteractivePlugin interface*/
     
    606612  public void run(Request request, Response response, ProgressReporter progress)
    607613  {
     614    if (signalHandler != null) signalHandler.setWorkerThread(null);
    608615    String command = request.getCommand();
    609616    if (command.equals(Request.COMMAND_EXECUTE))
     
    629636          progress.display(0, "Exporting data to be used by plugin.");
    630637          stdin = File.getById(dc, exportData());
    631  
     638          checkInterrupted();
    632639          copy(stdin, getExecDirectory());
    633640        }
    634641        catch(Exception e)
    635642        {
    636           response.setError("Error during export", Arrays.asList(e));
     643          response.setError("Error during export: " + e.getMessage(), Arrays.asList(e));
    637644          return;
    638645        }
    639646       
    640647        //Execution
     648        Process externalProcess = null;
    641649        try
    642650        {
     651          checkInterrupted();
    643652          progress.display(10, "Running on remote computation server.");
    644           Process p = Runtime.getRuntime().exec(getExecLine(), null, getExecDirectory());
     653          externalProcess = Runtime.getRuntime().exec(getExecLine(), null, getExecDirectory());
    645654 
    646655          ByteArrayOutputStream err = new ByteArrayOutputStream();
    647           StreamHandler errorStream = new StreamHandler(new BufferedInputStream(p.getErrorStream()), new BufferedOutputStream(err));
    648  
    649           FileOutputStream out = new FileOutputStream(new java.io.File(getExecDirectory(), "stdout.txt"));
    650           StreamHandler inputStream = new StreamHandler(new BufferedInputStream(p.getInputStream()), new BufferedOutputStream(out));
     656          StreamHandler errorStream = new StreamHandler(
     657              new BufferedInputStream(externalProcess.getErrorStream()),
     658              new BufferedOutputStream(err));
     659 
     660          FileOutputStream out =
     661            new FileOutputStream(new java.io.File(getExecDirectory(), "stdout.txt"));
     662          StreamHandler inputStream = new StreamHandler(
     663            new BufferedInputStream(externalProcess.getInputStream()),
     664            new BufferedOutputStream(out));
    651665         
    652           FileInputStream in = new FileInputStream(new java.io.File(getExecDirectory(), "stdin.txt"));
    653           StreamHandler outputStream = new StreamHandler(new BufferedInputStream(in), new BufferedOutputStream(p.getOutputStream()));
     666          FileInputStream in =
     667            new FileInputStream(new java.io.File(getExecDirectory(), "stdin.txt"));
     668          StreamHandler outputStream = new StreamHandler(
     669            new BufferedInputStream(in),
     670            new BufferedOutputStream(externalProcess.getOutputStream()));
    654671         
    655672          inputStream.start();
    656673          errorStream.start();
    657674          outputStream.start();
    658           int exitValue = p.waitFor();
     675          int exitValue = 0;
     676          try
     677          {
     678            exitValue = externalProcess.waitFor();
     679          }
     680          catch (InterruptedException ex)
     681          {
     682            // Aborted by user
     683            externalProcess.destroy();
     684            throw new SignalException("Aborted by user", ex);
     685          }
    659686
    660687          progress.display(50, "Reading from error stream.");
     
    677704        catch (Exception e)
    678705        {
    679           response.setError("Error during execution", Arrays.asList(e));
     706          response.setError("Error during execution: " + e.getMessage(), Arrays.asList(e));
    680707          return;
    681708        }
     
    695722        try
    696723        {
     724          checkInterrupted();
    697725          progress.display(70, "Importing data from plugin.");
    698726          importData(dc, stdout, trans);
     
    761789    }
    762790  }
    763  
     791  /*
     792    From the SignalTarget interface
     793    -------------------------------------------
     794  */
     795  public SignalHandler getSignalHandler()
     796  {
     797    signalHandler = new ThreadSignalHandler();
     798    return signalHandler;
     799  }
     800  // -------------------------------------------
     801
    764802
    765803  /**
     
    810848      }
    811849     
     850      checkInterrupted();
    812851      BioAssaySetExporter exporter = new BioAssaySetExporter();
    813852      if ((Boolean) configuration.getValue(serialFormatParameter.getName()))
     
    15821621    }
    15831622   
     1623    checkInterrupted();
    15841624    Directory homeDirectory = getPluginDirectory(dc);
    15851625    for(File f : homeDirectory.getFiles().list(dc))
     
    16101650          try
    16111651          {
     1652            checkInterrupted();
    16121653            newFile.upload(new FileInputStream(f), true);
    16131654          }
  • trunk/src/plugins/core/net/sf/basedb/plugins/BioAssaySetExporter.java

    r4095 r4120  
    7575import net.sf.basedb.core.query.Selects;
    7676import net.sf.basedb.core.query.SqlResult;
     77import net.sf.basedb.core.signal.SignalHandler;
     78import net.sf.basedb.core.signal.SignalTarget;
     79import net.sf.basedb.core.signal.ThreadSignalHandler;
    7780import net.sf.basedb.util.BioAssaySetUtil;
    7881import net.sf.basedb.util.Enumeration;
     
    112115public class BioAssaySetExporter
    113116  extends AbstractExporterPlugin
    114   implements InteractivePlugin
     117  implements InteractivePlugin, SignalTarget
    115118{
    116119
     120  private ThreadSignalHandler signalHandler;
     121 
    117122  public void configure(GuiContext context, Request request, Response response)
    118123  {
     
    204209    }
    205210  }
     211 
     212  /*
     213    From the SignalTarget interface
     214    -------------------------------------------
     215  */
     216  public SignalHandler getSignalHandler()
     217  {
     218    signalHandler = new ThreadSignalHandler();
     219    return signalHandler;
     220  }
     221  // -------------------------------------------
    206222
    207223  /**
     
    279295    Map<String, QueryItem> qis = getBaseFileQIMap(dc, bas);
    280296
     297    checkInterrupted();
    281298    exportBaseFileSectionHead(out, parameters);
    282299    exportBaseFileSectionAssays(out, dc, bas);
     
    314331    }
    315332   
     333    checkInterrupted();
    316334    long count = getBaseFileSpotSectionCount(dc, bas.getSpotData(), mergeReporters);
     335    checkInterrupted();
    317336    exportBaseFileSectionSpots(out, dc, bas, query, reporterFields, spotFields, bas.getBioAssays().list(dc), qis, count);
    318337    out.flush();
     
    321340  private void exportBaseFileSectionAssays(PrintWriter out, DbControl dc, BioAssaySet bas)
    322341  {
     342    checkInterrupted();
    323343    out.println("section\tassays");
    324344    out.println("count\t" + bas.getBioAssays().count(dc));
     
    333353    for (BioAssay ba : bas.getBioAssays().list(dc))
    334354    {
     355      checkInterrupted();
    335356      out.print(ba.getId() + "\t" + ba.getName());
    336357      for (AnnotationType at : getExperimentalFactors(dc, bas))
     
    347368  private void exportBaseFileSectionHead(PrintWriter out, Map<String, String> parameters)
    348369  {
     370    checkInterrupted();
    349371    out.println("BASEfile");
    350372   
     
    367389      for (String key : keys)
    368390      {
     391        checkInterrupted();
    369392        out.println(key+"\t"+parameters.get(key));
    370393      }
     
    403426    throws IOException, SQLException
    404427  {
     428    checkInterrupted();
    405429    DbControl dc = bas.getDbControl();
    406430    PrintWriter out = new PrintWriter(os);
     
    413437    for (BioAssay ba : bas.getBioAssays().list(dc))
    414438    {
     439      checkInterrupted();
    415440      DynamicSpotQuery query = ba.getSpotData();
    416441      for (String field : reporterFields)
     
    444469      }
    445470
     471      checkInterrupted();
    446472      long count = getBaseFileSpotSectionCount(dc, ba.getSpotData(), mergeReporters);
    447473      exportBaseFileSectionSpots(out, dc, bas, query, reporterFields, spotFields, Collections.singletonList(ba), qis, count);
     
    457483    throws SQLException
    458484  {
     485    checkInterrupted();
    459486    char[] tabs = new char[spotFields.size()-1];
    460487    Arrays.fill(tabs, '\t');
     
    494521    query.order(Orders.asc(Dynamic.column(VirtualColumn.COLUMN)));
    495522   
     523    checkInterrupted();
    496524    DynamicResultIterator iterator = query.iterate(dc);
    497525    List<Integer> reporterIndex = new ArrayList<Integer>(reporterFields.size());
     
    512540    while (iterator.hasNext())
    513541    {
     542      checkInterrupted();
    514543      SqlResult r = iterator.next();
    515544      Integer currentPos = r.getInt(posIndex);
     
    597626    throws IOException, SQLException
    598627  {
     628    checkInterrupted();
    599629    DbControl dc=bioassayset.getDbControl();
    600630    PrintWriter out = new PrintWriter(to);
     
    616646    out.write("reporterInternalId\treporterID\tgeneSymbol");
    617647    for (ExtendedProperty ep : reporterProperties)
     648    {
    618649      out.write("\t"+ep.getName());
     650    }
    619651    // Number 2 in below statement comes from using two reporter
    620652    // entries from ReporterData. Below there is dependencies on this
     
    634666    for (AnnotationType at : getExperimentalFactors(dc, bioassayset))
    635667    {
     668      checkInterrupted();
    636669      out.write("\n");
    637670      for (int i=0; i<nof_reporter_columns; ++i) out.write("\t");
     
    664697    query.order(Orders.asc(Dynamic.column(VirtualColumn.POSITION)));
    665698    query.order(Orders.asc(Dynamic.column(VirtualColumn.COLUMN)));
    666     DynamicResultIterator spotData = query.iterate(dc);
     699
     700    checkInterrupted();
     701    DynamicResultIterator spotData = query.iterate(dc);
    667702    int column_position=spotData.getIndex(VirtualColumn.POSITION.getName());
    668703    int column_column=spotData.getIndex(VirtualColumn.COLUMN.getName());
     
    688723    while (spotData.hasNext())
    689724    {
     725      checkInterrupted();
    690726      if (progress != null && (nof_processed_reporters%progress_report_interval == 0))
    691727      {
     
    752788    throws IOException, SQLException
    753789  {
     790    checkInterrupted();
    754791    DbControl dc=bioassayset.getDbControl();
    755792    PrintWriter out = new PrintWriter(os);
     
    761798
    762799    if (progress != null)
     800    {
    763801      progress.display(0, "Exporting ... performing database query");
     802    }
    764803
    765804    DynamicSpotQuery query=bioassayset.getSpotData();
     
    771810    query.order(Orders.asc(Dynamic.column(VirtualColumn.COLUMN)));
    772811
     812    checkInterrupted();
    773813    DynamicResultIterator spotData = query.iterate(dc);
    774814    int column_position=spotData.getIndex(VirtualColumn.POSITION.getName());
     
    784824    while (spotData.hasNext())
    785825    {
     826      checkInterrupted();
    786827      SqlResult item = spotData.next();
    787828      int thisposition=item.getInt(column_position);
     
    845886      count.select(Selects.expression(Dynamic.column(VirtualColumn.POSITION), "pos", true));
    846887    }
     888    checkInterrupted();
    847889    return count.count(dc);
    848890  }
     
    11831225    throws IOException
    11841226  {
     1227    if (signalHandler != null) signalHandler.setWorkerThread(null);
    11851228    try
    11861229    {
  • trunk/src/plugins/core/net/sf/basedb/plugins/HelpExporter.java

    r3679 r4120  
    5050import net.sf.basedb.core.plugin.Response;
    5151import net.sf.basedb.core.query.ResultIterator;
     52import net.sf.basedb.core.signal.SignalHandler;
     53import net.sf.basedb.core.signal.SignalTarget;
     54import net.sf.basedb.core.signal.ThreadSignalHandler;
    5255
    5356import java.io.IOException;
     
    7679public class HelpExporter
    7780  extends AbstractExporterPlugin
    78   implements InteractivePlugin
     81  implements InteractivePlugin, SignalTarget
    7982{
    8083 
     
    104107 
    105108  private RequestInformation configureJob;
     109  private ThreadSignalHandler signalHandler;
    106110 
    107111  private RequestInformation getConfigureJobParameters(Boolean requireFile)
     
    271275  }
    272276  // -------------------------------------------
    273 
    274   private float getPercentPerItem(ItemQuery<Help> query, DbControl dc)
    275   {
    276    
    277     long nrOfItem = query.count(dc); 
    278     if (nrOfItem > 0)
    279     {
    280       return (100/nrOfItem);
    281     }
    282     else
    283     {
    284       return 100;
    285     }
    286   }
    287  
     277  /*
     278    From the SignalTarget interface
     279    -------------------------------------------
     280  */
     281  public SignalHandler getSignalHandler()
     282  {
     283    signalHandler = new ThreadSignalHandler();
     284    return signalHandler;
     285  }
     286  // -------------------------------------------
     287
    288288  /*
    289289    From the AbstractExporterPlugin class
     
    300300    throws IOException
    301301  {
     302    if (signalHandler != null) signalHandler.setWorkerThread(null);
    302303    Client client = (Client)job.getValue("client");
    303304    client = Client.getById(dc, client.getId());
     
    309310    ItemQuery<Help> helpTextQuery = client.getHelp();     
    310311    helpTextQuery.setReturnTotalCount(false);
    311     float percentPerItem = getPercentPerItem(helpTextQuery, dc);
    312312   
    313313    //Initialize outputstream and xmldocument
     
    326326
    327327    //Get helpitems from database
     328    checkInterrupted();
     329    long numHelpItems = helpTextQuery.count(dc);
     330    float percentPerItem = 100.0f / numHelpItems;
     331
     332    checkInterrupted();
    328333    result = helpTextQuery.iterate(dc);
    329     long numHelpItems = helpTextQuery.count(dc);
    330    
    331334    while (result.hasNext())
    332335    {
     336      checkInterrupted();
    333337      //Create a new helpitem element         
    334338      Help helpItem = result.next();
     
    351355      if ((progress != null) && ((percentDone-progLastUpdated) > updateInterval))
    352356      {
    353         progress.display((int)percentDone, numExported + " of " + numHelpItems + "helptexts have been exported");
     357        progress.display((int)percentDone, numExported + " of " + numHelpItems + " helptexts have been exported");
    354358        progLastUpdated = percentDone;
    355359      }
  • trunk/src/plugins/core/net/sf/basedb/plugins/HelpImporter.java

    r3675 r4120  
    6969import net.sf.basedb.core.plugin.Request;
    7070import net.sf.basedb.core.plugin.Response;
     71import net.sf.basedb.core.signal.SignalHandler;
     72import net.sf.basedb.core.signal.SignalTarget;
     73import net.sf.basedb.core.signal.ThreadSignalHandler;
    7174import net.sf.basedb.util.XMLUtil;
    7275
     
    8689public class HelpImporter
    8790  extends AbstractPlugin
    88   implements InteractivePlugin, AutoDetectingImporter
     91  implements InteractivePlugin, AutoDetectingImporter, SignalTarget
    8992{
    9093  private int numImported = 0;
     
    125128
    126129  private static final Set<Permissions> permissions = new HashSet<Permissions>();
    127  
     130  private ThreadSignalHandler signalHandler;
    128131
    129132  /*
     
    230233  public void run(Request request, Response response, ProgressReporter progress)
    231234  {   
     235    if (signalHandler != null) signalHandler.setWorkerThread(null);
    232236    String command = request.getCommand();
    233237    if (command.equals(Request.COMMAND_EXECUTE))
     
    270274    }
    271275  }
    272  
     276  /*
     277    From the SignalTarget interface
     278    -------------------------------------------
     279  */
     280  public SignalHandler getSignalHandler()
     281  {
     282    signalHandler = new ThreadSignalHandler();
     283    return signalHandler;
     284  }
     285  // -------------------------------------------
     286   
    273287  /*
    274288    From the AutoDetectingImporter interface
     
    338352      {
    339353        List<Element> helpElements = (List<Element>)rootElement.getChildren(); 
    340         float percentPerItem = 100/helpElements.size();
     354        float percentPerItem = 100.0f / helpElements.size();
    341355       
    342356        for (int i = 0; i < helpElements.size(); i++)
    343         {
     357        {
     358          checkInterrupted();
    344359          Element helpElement = helpElements.get(i);
    345360          String name = helpElement.getChildText("name");
  • trunk/src/plugins/core/net/sf/basedb/plugins/LowessNormalization.java

    r4119 r4120  
    401401    DynamicSpotQuery query = source.getSpotData();
    402402    query.restrict(intensityRestriction);
     403    checkInterrupted();
    403404    long numSpots = query.count(dc);
    404     checkInterrupted();
    405405   
    406406    long normalizedSpots = 0;
     
    430430    // Normalize one bioassay at a time
    431431    List<BioAssay> assays = source.getBioAssays().list(dc);
    432     checkInterrupted();
    433432 
    434433    try
     
    436435      for (BioAssay assay : assays)
    437436      {
     437        checkInterrupted();
     438
    438439        // Prepare list for holding data
    439440        int assaySpots = assay.getNumSpots();
     
    479480        while (fromBlock <= maxBlock)
    480481        {
     482          checkInterrupted();
    481483          // Find start and end index for current block range
    482484          int toBlock = fromBlock + blockGroupSize - 1;
  • trunk/src/plugins/core/net/sf/basedb/plugins/MedianRatioNormalization.java

    r4095 r4120  
    7070import net.sf.basedb.core.query.Selects;
    7171import net.sf.basedb.core.query.SqlResult;
     72import net.sf.basedb.core.signal.SignalHandler;
     73import net.sf.basedb.core.signal.SignalTarget;
     74import net.sf.basedb.core.signal.ThreadSignalHandler;
    7275import net.sf.basedb.util.Values;
    7376
     
    8083public class MedianRatioNormalization
    8184  extends AbstractAnalysisPlugin
    82   implements InteractivePlugin
     85  implements InteractivePlugin, SignalTarget
    8386{
    8487
     
    147150  private RequestInformation configureJob;
    148151
     152  private ThreadSignalHandler signalHandler;
     153 
    149154  /*
    150155    From the Plugin interface
     
    178183  public void run(Request request, Response response, ProgressReporter progress)
    179184  {
     185    if (signalHandler != null) signalHandler.setWorkerThread(null);
    180186    String command = request.getCommand();
    181187    if (command.equals(Request.COMMAND_EXECUTE))
     
    292298      response.setError(ex.getMessage(), Arrays.asList(ex));
    293299    }
     300  }
     301  // -------------------------------------------
     302  /*
     303    From the SignalTarget interface
     304    -------------------------------------------
     305  */
     306  public SignalHandler getSignalHandler()
     307  {
     308    signalHandler = new ThreadSignalHandler();
     309    return signalHandler;
    294310  }
    295311  // -------------------------------------------
     
    348364    DynamicSpotQuery query = source.getSpotData();
    349365    query.restrict(intensityRestriction);
     366    checkInterrupted();
    350367    long numSpots = query.count(dc);
    351368    long normalizedSpots = 0;
     
    367384      for (BioAssay assay : assays)
    368385      {
     386        checkInterrupted();
     387
    369388        // Prepare list for holding data
    370389        int assaySpots = assay.getNumSpots();
     
    384403        while (it.hasNext())
    385404        {
     405          checkInterrupted();
    386406          SqlResult r = it.next();
    387407          SpotData spot = new SpotData(r.getInt(positionIndex),
     
    404424        while (fromBlock <= maxBlock)
    405425        {
     426          checkInterrupted();
    406427          // Find start and end index for current block range
    407428          int toBlock = fromBlock + blockGroupSize - 1;
     
    434455              for (int j = fromIndex; j < toIndex; ++j)
    435456              {
     457                checkInterrupted();
    436458                SpotData spot = data.get(j);
    437459                float newCh1 = (float)(spot.ch1 * invSqrtMedRatio);
  • trunk/src/plugins/core/net/sf/basedb/plugins/PlateMappingExporter.java

    r3675 r4120  
    6060import net.sf.basedb.core.plugin.Request;
    6161import net.sf.basedb.core.plugin.Response;
     62import net.sf.basedb.core.signal.SignalHandler;
     63import net.sf.basedb.core.signal.SignalTarget;
     64import net.sf.basedb.core.signal.ThreadSignalHandler;
    6265
    6366/**
     
    8992public class PlateMappingExporter
    9093  extends AbstractExporterPlugin
    91   implements InteractivePlugin
     94  implements InteractivePlugin, SignalTarget
    9295{
    9396
     
    115118  private RequestInformation configureJob;
    116119
     120  private ThreadSignalHandler signalHandler;
    117121
    118122  /**
     
    262266    throws IOException
    263267  {
     268    if (signalHandler != null) signalHandler.setWorkerThread(null);
     269   
    264270    PlateGeometry sourceGeometry = mapping.getSourceGeometry();
    265271    PlateGeometry destGeometry = mapping.getDestinationGeometry();
     
    289295        for (int column = 0; column < destGeometry.getColumns(); ++column)
    290296        {
     297          checkInterrupted();
    291298          MappingCoordinate destination = new MappingCoordinate(plate, row, column);
    292299          MappingCoordinate source = mapping.getSourceCoordinate(destination);
     
    308315  {
    309316    return "Plate mapping " + mapping.getName() + " exported successfully";
     317  }
     318  // -------------------------------------------
     319  /*
     320    From the SignalTarget interface
     321    -------------------------------------------
     322  */
     323  public SignalHandler getSignalHandler()
     324  {
     325    signalHandler = new ThreadSignalHandler();
     326    return signalHandler;
    310327  }
    311328  // -------------------------------------------
  • trunk/src/plugins/core/net/sf/basedb/plugins/PluginConfigurationExporter.java

    r3679 r4120  
    5555import net.sf.basedb.core.query.Hql;
    5656import net.sf.basedb.core.query.Restrictions;
     57import net.sf.basedb.core.signal.SignalHandler;
     58import net.sf.basedb.core.signal.SignalTarget;
     59import net.sf.basedb.core.signal.ThreadSignalHandler;
    5760
    5861import java.io.IOException;
     
    8487public class PluginConfigurationExporter
    8588  extends AbstractExporterPlugin
    86   implements InteractivePlugin
     89  implements InteractivePlugin, SignalTarget
    8790{
    8891 
     
    107110 
    108111  private int numSelected;
     112 
     113  private ThreadSignalHandler signalHandler;
    109114 
    110115  public Set<GuiContext> getGuiContexts()
     
    240245    throws IOException
    241246  {
     247    if (signalHandler != null) signalHandler.setWorkerThread(null);
    242248    numExported = 0;
    243249    List<Integer> selectedItems = (List<Integer>)job.getValues("items");
     
    262268      );
    263269      configQuery.setParameter("_selected_", selectedItems, Type.INT);
     270      checkInterrupted();
    264271      ItemResultIterator<PluginConfiguration> configurations = configQuery.iterate(dc);
    265272     
     
    273280      while (configurations.hasNext())
    274281      {
     282        checkInterrupted();
    275283        PluginConfiguration pluginConfig = configurations.next();       
    276284       
     
    353361  }
    354362  // ----------------------------------------------------------------
     363  /*
     364    From the SignalTarget interface
     365    -------------------------------------------
     366  */
     367  public SignalHandler getSignalHandler()
     368  {
     369    signalHandler = new ThreadSignalHandler();
     370    return signalHandler;
     371  }
     372  // -------------------------------------------
    355373
    356374 
  • trunk/src/plugins/core/net/sf/basedb/plugins/PluginConfigurationImporter.java

    r4116 r4120  
    6060import net.sf.basedb.core.plugin.Request;
    6161import net.sf.basedb.core.plugin.Response;
    62 import net.sf.basedb.util.PluginConfigInfo;
     62import net.sf.basedb.core.signal.SignalHandler;
     63import net.sf.basedb.core.signal.SignalTarget;
     64import net.sf.basedb.core.signal.ThreadSignalHandler;
    6365import net.sf.basedb.util.XMLUtil;
    6466
     
    9597public class PluginConfigurationImporter
    9698  extends AbstractPlugin
    97     implements InteractivePlugin, AutoDetectingImporter
     99    implements InteractivePlugin, AutoDetectingImporter, SignalTarget
    98100{
    99101  private static final String COMMAND_SELECT_CONFIGURATIONS = "select_configurations";
     
    150152  private HashMap<Integer, Boolean> configurationMap;
    151153
     154  private ThreadSignalHandler signalHandler;
     155 
    152156  /*
    153157    From the InteractivePlugin interface
     
    264268  public void run(Request request, Response response, ProgressReporter progress)
    265269  {
     270    if (signalHandler != null) signalHandler.setWorkerThread(null);
    266271    String command = request.getCommand();
    267272    if (command.equals(Request.COMMAND_EXECUTE))
     
    372377      for (Object obj : configurations)
    373378      {
     379        checkInterrupted();
    374380        Element configuration = (Element)obj;
    375381        String name = configuration.getChildText("configname");
     
    421427      -----------------------------------------------------
    422428  */
     429  /*
     430    From the SignalTarget interface
     431    -------------------------------------------
     432  */
     433  public SignalHandler getSignalHandler()
     434  {
     435    signalHandler = new ThreadSignalHandler();
     436    return signalHandler;
     437  }
     438  // -------------------------------------------
    423439 
    424440  /**
  • trunk/src/test/data/test.plugin.base

    r2959 r4120  
    99serialFormat  1
    1010url
    11 minChannels 2
     11minChannels 1
    1212maxChannels 0
    1313leaveStdin  1
     
    1616defaultMaxRam 134217728
    1717usedColumns position\treporter\tchromosome
    18 usedFields  intensity2\tintensity1
     18usedFields  _allIntensities
    1919columns position  valueType name  commonName  options defaultValue  enumOptions removed
    2020%
Note: See TracChangeset for help on using the changeset viewer.