Debian Codegraph @

uk/ac/babraham/FastQC/Analysis/AnalysisQueue.java

raw symbols SCIP
1 /**
2 * Copyright Copyright 2010-17 Simon Andrews
3 *
4 * This file is part of FastQC.
5 *
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.
10 *
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.
15 *
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
19 */
20 package uk.ac.babraham.FastQC.Analysis;
21
22 import java.util.concurrent.LinkedBlockingDeque;
23 import java.util.concurrent.atomic.AtomicInteger;
24
25 import uk.ac.babraham.FastQC.FastQCConfig;
26 import uk.ac.babraham.FastQC.Modules.QCModule;
27 import uk.ac.babraham.FastQC.Sequence.SequenceFile;
28
29 public class AnalysisQueue implements Runnable, AnalysisListener{
30
31 private static AnalysisQueue instance = new AnalysisQueue();
32
33 private LinkedBlockingDeque<AnalysisRunner>queue = new LinkedBlockingDeque<AnalysisRunner>();
34
35 private AtomicInteger availableSlots = new AtomicInteger(1);
36 private AtomicInteger usedSlots = new AtomicInteger(0);
37
38 public static AnalysisQueue getInstance () {
39 return instance;
40 }
41
42 private AnalysisQueue () {
43
44 if (FastQCConfig.getInstance().threads != null) {
45 availableSlots.set(FastQCConfig.getInstance().threads);
46 }
47
48 Thread t = new Thread(this);
49 t.start();
50 }
51
52 public void addToQueue (AnalysisRunner runner) {
53 queue.add(runner);
54 }
55
56 public void run() {
57
58 while (true) {
59 // System.err.println("Status available="+availableSlots+" used="+usedSlots+" queue="+queue.size());
60 if (availableSlots.intValue() > usedSlots.intValue() && queue.size() > 0) {
61 usedSlots.incrementAndGet();
62 AnalysisRunner currentRun = queue.getFirst();
63 queue.removeFirst();
64 currentRun.addAnalysisListener(this);
65 Thread t = new Thread(currentRun);
66 t.start();
67 }
68
69 try {
70 Thread.sleep(500);
71 } catch (InterruptedException e) {}
72 }
73 }
74
75 public void analysisComplete(SequenceFile file, QCModule[] results) {
76 usedSlots.decrementAndGet();
77 }
78
79 public void analysisUpdated(SequenceFile file, int sequencesProcessed, int percentComplete) {}
80
81 public void analysisExceptionReceived(SequenceFile file, Exception e) {
82 usedSlots.decrementAndGet();
83 }
84
85 public void analysisStarted(SequenceFile file) {}
86
87
88 }