public override void Run()
        {
            // TODO: maybe use private thread ticktock timer, in
            // case clock shift messes up nanoTime?
            long lastReopenStartNS = DateTime.UtcNow.Ticks * 100;

            //System.out.println("reopen: start");
            while (!finish)
            {
                bool hasWaiting;

                lock (this)
                    hasWaiting = waitingGen > searchingGen;

                long nextReopenStartNS = lastReopenStartNS + (hasWaiting ? targetMinStaleNS : targetMaxStaleNS);
                long sleepNS           = nextReopenStartNS - Time.NanoTime();

                if (sleepNS > 0)
                {
                    try
                    {
                        reopenCond.WaitOne(TimeSpan.FromMilliseconds(sleepNS / Time.MILLISECONDS_PER_NANOSECOND));//Convert NS to Ticks
                    }
                    catch (ThreadInterruptedException)
                    {
                        Thread.CurrentThread.Interrupt();
                        return;
                    }
                }

                if (finish)
                {
                    break;
                }

                lastReopenStartNS = Time.NanoTime();
                // Save the gen as of when we started the reopen; the
                // listener (HandleRefresh above) copies this to
                // searchingGen once the reopen completes:
                refreshStartGen = writer.GetAndIncrementGeneration();
                try
                {
                    manager.MaybeRefreshBlocking();
                }
                catch (IOException ioe)
                {
                    throw new Exception(ioe.ToString(), ioe);
                }
            }
            // this will set the searchingGen so that all waiting threads will exit
            RefreshDone();
        }
예제 #2
0
        public override void Run()
        {
            // TODO: maybe use private thread ticktock timer, in
            // case clock shift messes up nanoTime?
            // LUCENENET NOTE: Time.NanoTime() is not affected by clock changes.
            long lastReopenStartNS = Time.NanoTime();

            //System.out.println("reopen: start");
            while (!finish)
            {
                // TODO: try to guestimate how long reopen might
                // take based on past data?

                // Loop until we've waiting long enough before the
                // next reopen:
                while (!finish)
                {
                    try
                    {
                        // Need lock before finding out if has waiting
                        bool hasWaiting;
                        UninterruptableMonitor.Enter(this);
                        try
                        {
                            // True if we have someone waiting for reopened searcher:
                            hasWaiting = waitingGen > searchingGen;
                        }
                        finally
                        {
                            UninterruptableMonitor.Exit(this);
                        }

                        long nextReopenStartNS = lastReopenStartNS + (hasWaiting ? targetMinStaleNS : targetMaxStaleNS);
                        long sleepNS           = nextReopenStartNS - Time.NanoTime();

                        if (sleepNS > 0)
                        {
                            reopenCond.WaitOne(TimeSpan.FromMilliseconds(sleepNS / Time.MillisecondsPerNanosecond));//Convert NS to MS
                        }
                        else
                        {
                            break;
                        }
                    }
                    catch (Exception ie) when(ie.IsInterruptedException())
                    {
                        Thread.CurrentThread.Interrupt();
                        return;
                    }
                }
                if (finish)
                {
                    break;
                }

                lastReopenStartNS = Time.NanoTime();
                // Save the gen as of when we started the reopen; the
                // listener (HandleRefresh above) copies this to
                // searchingGen once the reopen completes:
                refreshStartGen.Value = writer.GetAndIncrementGeneration();
                try
                {
                    manager.MaybeRefreshBlocking();
                }
                catch (Exception ioe) when(ioe.IsIOException())
                {
                    throw RuntimeException.Create(ioe);
                }
            }
        }