public void InitConnections(IEnumerable<PartitionTopicInfo> topicInfos, Cluster cluster, IEnumerable<BlockingCollection<FetchedDataChunk>> queuesToBeCleared)
{
this.EnsuresNotDisposed();
this.Shutdown();
if (topicInfos == null)
{
return;
}
foreach (var queueToBeCleared in queuesToBeCleared)
{
while (queueToBeCleared.Count > 0)
{
queueToBeCleared.Take();
}
}
var partitionTopicInfoMap = new Dictionary<int, List<PartitionTopicInfo>>();
//// re-arrange by broker id
foreach (var topicInfo in topicInfos)
{
if (!partitionTopicInfoMap.ContainsKey(topicInfo.BrokerId))
{
partitionTopicInfoMap.Add(topicInfo.BrokerId, new List<PartitionTopicInfo>() { topicInfo });
}
else
{
partitionTopicInfoMap[topicInfo.BrokerId].Add(topicInfo);
}
}
//// open a new fetcher thread for each broker
fetcherWorkerObjects = new FetcherRunnable[partitionTopicInfoMap.Count];
int i = 0;
foreach (KeyValuePair<int, List<PartitionTopicInfo>> item in partitionTopicInfoMap)
{
Broker broker = cluster.GetBroker(item.Key);
var fetcherRunnable = new FetcherRunnable("FetcherRunnable-" + i, zkClient, config, broker, item.Value);
var threadStart = new ThreadStart(fetcherRunnable.Run);
var fetcherThread = new Thread(threadStart);
fetcherWorkerObjects[i] = fetcherRunnable;
fetcherThread.Start();
i++;
}
}