Use a ocpy on write list for the consumers map to avoid thrash between threads

Once we've finished caching our consumers map the majority of the operations on
this consumersMap list will be traversals inside of the KafkaPoller. Thus
making the performance hit worth it.

What we don't want to happen is to try to iterate through the consumersmap's
list of consumers while receiving new ZK childEvents

Fixes #6
This commit is contained in:
R. Tyler Croy 2015-01-26 06:52:54 -08:00
parent 4f16c3dfd1
commit 5e1a4e11ba
1 changed files with 2 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package com.github.lookout.verspaetung.zk
import com.github.lookout.verspaetung.TopicPartition
import java.util.concurrent.CopyOnWriteArrayList
import groovy.transform.TypeChecked
import org.apache.curator.framework.CuratorFramework
@ -71,7 +72,7 @@ abstract class AbstractTreeWatcher implements TreeCacheListener {
this.consumersMap[key] << offset
}
else {
this.consumersMap[key] = [offset]
this.consumersMap[key] = new CopyOnWriteArrayList([offset])
}
}