Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the IterableThreadLocal class and use the one in commons #730

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@

package com.fulcrumgenomics.umi

import java.util.concurrent.ForkJoinPool

import com.fulcrumgenomics.FgBioDef._
import com.fulcrumgenomics.bam.api.SamRecord
import com.fulcrumgenomics.commons.async.AsyncIterator
import com.fulcrumgenomics.commons.util.LazyLogging
import com.fulcrumgenomics.commons.util.Threads.IterableThreadLocal
import com.fulcrumgenomics.umi.UmiConsensusCaller.SimpleRead
import com.fulcrumgenomics.util.ProgressLogger

Expand Down Expand Up @@ -105,22 +104,6 @@ class ConsensusCallingIterator[ConsensusRead <: SimpleRead](sourceIterator: Iter
override def next(): SamRecord = this.iter.next
}

// TODO: migrate to the commons version of this class after the next commons release
// TODO: https://github.com/fulcrumgenomics/commons/pull/51
private class IterableThreadLocal[A](factory: () => A) extends ThreadLocal[A] with Iterable[A] {
private val all = new java.util.concurrent.ConcurrentLinkedQueue[A]()

override def initialValue(): A = {
val a = factory()
all.add(a)
a
}

/** Care should be taken accessing the iterator since objects may be in use by other threads. */
def iterator: Iterator[A] = all.iterator
}


/** Groups consecutive records based on a method to group records. */
private class SamRecordGroupedIterator[Key](sourceIterator: Iterator[SamRecord],
toKey: SamRecord => Key) extends Iterator[Seq[SamRecord]] {
Expand Down