2
* Copyright Copyright 2010-12 Simon Andrews
4
* This file is part of FastQC.
6
* FastQC is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 3 of the License, or
9
* (at your option) any later version.
11
* FastQC is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with FastQC; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
package uk.ac.babraham.FastQC.Analysis;
22
import java.util.LinkedList;
24
import uk.ac.babraham.FastQC.Modules.QCModule;
25
import uk.ac.babraham.FastQC.Sequence.SequenceFile;
27
public class AnalysisQueue implements Runnable, AnalysisListener{
29
private static AnalysisQueue instance = new AnalysisQueue();
31
private LinkedList<AnalysisRunner>queue = new LinkedList<AnalysisRunner>();
33
private int availableSlots = 1;
34
private int usedSlots = 0;
36
public static AnalysisQueue getInstance () {
40
private AnalysisQueue () {
42
if (System.getProperty("fastqc.threads") != null) {
44
availableSlots = Integer.parseInt(System.getProperty("fastqc.threads"));
46
catch (NumberFormatException nfe) {
47
System.err.println("Thead limit '"+System.getProperty("fastqc.threads")+" wasn't a number");
51
if (availableSlots < 1) {
52
System.err.println("Thead limit '"+System.getProperty("fastqc.threads")+" must be > 1");
58
Thread t = new Thread(this);
62
public void addToQueue (AnalysisRunner runner) {
69
// System.err.println("Status available="+availableSlots+" used="+usedSlots+" queue="+queue.size());
70
if (availableSlots > usedSlots && queue.size() > 0) {
72
AnalysisRunner currentRun = queue.getFirst();
74
currentRun.addAnalysisListener(this);
75
Thread t = new Thread(currentRun);
81
} catch (InterruptedException e) {}
85
public void analysisComplete(SequenceFile file, QCModule[] results) {
89
public void analysisUpdated(SequenceFile file, int sequencesProcessed, int percentComplete) {}
91
public void analysisExceptionReceived(SequenceFile file, Exception e) {
95
public void analysisStarted(SequenceFile file) {}