Ejemplo n.º 1
0
        /// <summary>
        /// Stops the server.
        /// </summary>
        public void Stop()
        {
            DebugHelper.Log("Stopping reindexer server...");
            try
            {
                foreach (var ns in ExecuteSql <Namespace>(GetNamespacesQuery).Items)
                {
                    CloseNamespace(ns.Name);
                }
            }
            catch
            { //sometimes server had been stopped before this stop method because of ctrl+c on console or any sigterm signal.
            }

            Assert.ThrowIfError(() =>
                                ReindexerBinding.stop_reindexer_server(_pServer)
                                );

            var waitTimeout = TimeSpan.FromSeconds(10);
            var startTime   = DateTime.UtcNow;

            while (IsStarted)
            {
                if (DateTime.UtcNow - startTime > waitTimeout)
                {
                    DebugHelper.Log($"Reindexer Embedded Server couldn't be stopped in {waitTimeout.TotalSeconds} seconds.");
                    break;
                }
                Thread.Sleep(100);
            }

            lock (_serverStartupLocker)
            {
                if (_serverThread.IsAlive)
                {
                    _serverThread.Join();
                }
            }

            Rx = default;
            DebugHelper.Log("Reindexer server is stopped.");
        }