Beispiel #1
0
        private void ConnectZk()
        {
            Logger.Info("Enter connectZk()");
            if (UseSharedStaticZookeeperClient)
            {
                Logger.Info("After check  UseSharedStaticZookeeperClient");
                if (zkClientStatic == null || zkClientStatic != null &&
                    zkClientStatic.GetClientState() != KeeperState.SyncConnected)
                {
                    Logger.Info("After check  UseSharedStaticZookeeperClient, will lock");
                    lock (zkClientStaticLock)
                    {
                        Logger.Info("got lock ... ");
                        if (zkClientStatic == null || zkClientStatic != null &&
                            zkClientStatic.GetClientState() != KeeperState.SyncConnected)
                        {
                            Logger.InfoFormat("zkClientStatic: {0}   will create one ...",
                                              zkClientStatic == null ? "null" : "not null");
                            Logger.InfoFormat("Connecting to zookeeper instance at {0}  STATIC",
                                              config.ZooKeeper.ZkConnect);
                            zkClientStatic = new ZooKeeperClient(config.ZooKeeper.ZkConnect,
                                                                 config.ZooKeeper.ZkSessionTimeoutMs, ZooKeeperStringSerializer.Serializer,
                                                                 config.ZooKeeper.ZkConnectionTimeoutMs);
                            zkClientStatic.Connect();
                            Logger.InfoFormat("Connecting to zookeeper instance at {0}  STATIC. Done",
                                              config.ZooKeeper.ZkConnect);
                        }

                        Logger.Info("release lock ... ");
                    }
                }

                Logger.InfoFormat("zkClientStatic: {0}", zkClientStatic == null ? "null" : "not null");
                if (zkClientStatic != null)
                {
                    Logger.InfoFormat("zkClientStatic.ClientState: {0}", zkClientStatic.GetClientState());
                }
            }
            else
            {
                Logger.InfoFormat("Connecting to zookeeper instance at {0}", config.ZooKeeper.ZkConnect);
                if (zkClientInternal != null)
                {
                    zkClientInternal.Dispose();
                    zkClientInternal = null;
                }
                zkClientInternal = new ZooKeeperClient(config.ZooKeeper.ZkConnect, config.ZooKeeper.ZkSessionTimeoutMs,
                                                       ZooKeeperStringSerializer.Serializer, config.ZooKeeper.ZkConnectionTimeoutMs);
                zkClientInternal.Connect();
            }
        }
Beispiel #2
0
        protected override void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            if (disposed)
            {
                return;
            }

            Logger.Info("ConsumerOffsetChecker shutting down");

            try
            {
                zkClient.UnsubscribeAll();

                Thread.Sleep(1000);

                lock (shuttingDownLock)
                {
                    if (disposed)
                    {
                        return;
                    }

                    disposed = true;
                }

                if (zkClient != null)
                {
                    zkClient.Dispose();
                }
            }
            catch (Exception exc)
            {
                Logger.Debug("Ignoring unexpected errors on shutting down", exc);
            }

            Logger.Info("ConsumerOffsetChecker shut down completed");
        }