protected override void Dispose(bool disposing)
{
if (!disposing)
{
return;
}
if (disposed)
{
return;
}
Logger.Info("ZookeeperConsumerConnector shutting down and dispose ...");
try
{
// Stop any async rebalance operations that might be running
stopAsyncRebalancing.ForEach(s => s.Invoke());
if (UseSharedStaticZookeeperClient)
{
Logger.InfoFormat(
"will call Unsubscribe since use static zkClient. subscribedChildCollection:{0} , subscribedZookeeperStateCollection:{1} subscribedZookeeperDataCollection:{2} "
, subscribedChildCollection.Count, subscribedZookeeperStateCollection.Count,
subscribedZookeeperDataCollection.Count);
if (GetZkClient() != null)
{
foreach (var t in subscribedChildCollection)
{
GetZkClient().Unsubscribe(t.Item1, t.Item2);
}
foreach (var t in subscribedZookeeperStateCollection)
{
GetZkClient().Unsubscribe(t);
}
foreach (var t in subscribedZookeeperDataCollection)
{
GetZkClient().Unsubscribe(t.Item1, t.Item2);
}
}
else
{
Logger.Warn("STATIC zkCLient still null. ");
}
subscribedChildCollection = new ConcurrentBag <Tuple <string, IZooKeeperChildListener> >();
subscribedZookeeperStateCollection = new ConcurrentBag <IZooKeeperStateListener>();
subscribedZookeeperDataCollection = new ConcurrentBag <Tuple <string, IZooKeeperDataListener> >();
Logger.InfoFormat(
"Finish call Unsubscribe since use static zkClient. collection have been clean up. subscribedChildCollection:{0} , subscribedZookeeperStateCollection:{1} subscribedZookeeperDataCollection:{2} "
, subscribedChildCollection.Count, subscribedZookeeperStateCollection.Count,
subscribedZookeeperDataCollection.Count);
}
else
{
Logger.Info("will call UnsubscribeAll since use local zkClient. ");
GetZkClient().UnsubscribeAll();
Logger.Info("After call UnsubscribeAll since use local zkClient. ");
}
if (scheduler != null)
{
scheduler.Dispose();
}
Thread.Sleep(1000);
if (fetcher != null)
{
fetcher.Dispose();
}
SendShutdownToAllQueues();
if (config.AutoCommit)
{
CommitOffsets();
}
lock (shuttingDownLock)
{
if (disposed)
{
return;
}
disposed = true;
}
if (UseSharedStaticZookeeperClient)
{
Logger.Info("will NOT call zkClient.Dispose() since using static one");
Logger.Info("will explicitly call ReleaseAllPartitionOwnerships() since using static one");
ReleaseAllPartitionOwnerships();
Logger.Info("will explicitly call DeleteConsumerIdNode() since using static one");
DeleteConsumerIdNode();
}
else
{
Logger.Info("will call this.zkClient.Dispose(); ");
if (GetZkClient() != null)
{
GetZkClient().Dispose();
}
}
}
catch (Exception exc)
{
Logger.Warn("Ignoring unexpected errors on shutting down", exc);
}
Logger.Info("ZookeeperConsumerConnector shut down completed");
}