// Path: src/main/java/abra/ThreadManager.java
// public class ThreadManager {
// 	
// 	private static final int MAX_PENDING = 100;
// 	
// 	private int numThreads;
// 	private List<AbraRunnable> threads = new ArrayList<AbraRunnable>();
// 	private ExecutorService executor;
// 
// 	public ThreadManager(int numThreads) {
// 		this.numThreads = numThreads;
// 		executor = Executors.newFixedThreadPool(numThreads);
// 	}
// 	
// 	public void spawnThread(AbraRunnable runnable) {
// 		
// 		try {
// 			waitForAvailableThread();
// 		} catch (InterruptedException e) {}
// 		
// 		addThread(runnable);
// 		
// 		executor.submit(runnable);
// 	}
// 	
// 	private synchronized void addThread(AbraRunnable thread) {
// 		threads.add(thread);
// 	}
// 	
// 	public synchronized void removeThread(AbraRunnable thread) {
// 		threads.remove(thread);
// 	}
// 	
// 	private synchronized int activeThreads() {
// 		return threads.size();
// 	}
// 	
// 	private void waitForAvailableThread() throws InterruptedException {
// 		while (activeThreads() >= MAX_PENDING) {
// 			Thread.sleep(50);
// 		}
// 	}
// 	
// 	public void waitForAllThreadsToComplete() throws InterruptedException, IOException {
// 		executor.shutdown();
// 		while (!executor.awaitTermination(60, TimeUnit.SECONDS)) {
// 			log("Waiting on " + threads.size() + " threads.");
// 		}
// 	}
// 
// 	public int getNumThreads() {
// 		return numThreads;
// 	}
// }


import java.util.List;
import htsjdk.samtools.SAMRecord;
import abra.AbraRunnable;
import abra.ThreadManager;
package abra.rna;



public class RnaRegionHandler extends AbraRunnable {
	
	private RnaPoc poc;
	private List<SAMRecord> reads;
	private String id;

	public RnaRegionHandler(ThreadManager threadManager, RnaPoc poc, List<SAMRecord> reads) {
		super(threadManager);
		this.poc = poc;
		this.reads = reads;
		SAMRecord first = reads.get(0);
		SAMRecord last = reads.get(reads.size()-1);
		// NOTE: No guarantee that the last read's alignment end is really the end of the region.
		// Calculating this requires iterating over entire region.
		id = "thread: " + first.getReferenceName() + "_" + first.getAlignmentStart() + "_" + last.getAlignmentEnd() + " reads: " + reads.size();
	}
	
	@Override
// Path: src/main/java/abra/ThreadManager.java
// public class ThreadManager {
// 	
// 	private static final int MAX_PENDING = 100;
// 	
// 	private int numThreads;
// 	private List<AbraRunnable> threads = new ArrayList<AbraRunnable>();
// 	private ExecutorService executor;
// 
// 	public ThreadManager(int numThreads) {
// 		this.numThreads = numThreads;
// 		executor = Executors.newFixedThreadPool(numThreads);
// 	}
// 	
// 	public void spawnThread(AbraRunnable runnable) {
// 		
// 		try {
// 			waitForAvailableThread();
// 		} catch (InterruptedException e) {}
// 		
// 		addThread(runnable);
// 		
// 		executor.submit(runnable);
// 	}
// 	
// 	private synchronized void addThread(AbraRunnable thread) {
// 		threads.add(thread);
// 	}
// 	
// 	public synchronized void removeThread(AbraRunnable thread) {
// 		threads.remove(thread);
// 	}
// 	
// 	private synchronized int activeThreads() {
// 		return threads.size();
// 	}
// 	
// 	private void waitForAvailableThread() throws InterruptedException {
// 		while (activeThreads() >= MAX_PENDING) {
// 			Thread.sleep(50);
// 		}
// 	}
// 	
// 	public void waitForAllThreadsToComplete() throws InterruptedException, IOException {
// 		executor.shutdown();
// 		while (!executor.awaitTermination(60, TimeUnit.SECONDS)) {
// 			log("Waiting on " + threads.size() + " threads.");
// 		}
// 	}
// 
// 	public int getNumThreads() {
// 		return numThreads;
// 	}
// }


// Path: src/main/java/abra/rna/RnaRegionHandler.java
import java.util.List;
import htsjdk.samtools.SAMRecord;
import abra.AbraRunnable;
import abra.ThreadManager;

package abra.rna;



public class RnaRegionHandler extends AbraRunnable {
	
	private RnaPoc poc;
	private List<SAMRecord> reads;
	private String id;

	public RnaRegionHandler(ThreadManager threadManager, RnaPoc poc, List<SAMRecord> reads) {
		super(threadManager);
		this.poc = poc;
		this.reads = reads;
		SAMRecord first = reads.get(0);
		SAMRecord last = reads.get(reads.size()-1);
		// NOTE: No guarantee that the last read's alignment end is really the end of the region.
		// Calculating this requires iterating over entire region.
		id = "thread: " + first.getReferenceName() + "_" + first.getAlignmentStart() + "_" + last.getAlignmentEnd() + " reads: " + reads.size();
	}
	
	@Override
	public void go() throws Exception {