コード例 #1
0
        private ThreadResources GetThreadResources()
        {
            ThreadResources resources = threadResources.Value;

            if (resources == null)
            {
                resources             = new ThreadResources();
                resources.termEnum    = Terms();
                threadResources.Value = resources;
            }
            return(resources);
        }
コード例 #2
0
        private static RandomizedContext Context(ThreadClass thread)
        {
            var group = thread.Instance.GetThreadGroup();

            RandomizedContext context;

            lock (globalLock)
            {
                while (true)
                {
                    context = contexts[group];
                    if (context == null && group.Parent != null)
                    {
                        group = group.Parent;
                    }
                    else
                    {
                        break;
                    }
                }

                // TODO: revisit
                if (context == null)
                {
                    context = contexts[group] = new RandomizedContext(group, null, null);
                }
            }

            if (context == null)
            {
                // TODO: revisit
                var message = "No context information for thread," + thread.Name + ". " +
                              "Is this thread running under a " + typeof(RandomizedRunner).Name + " context? ";

                throw new InvalidOperationException(message);
            }

            lock (context.contextLock)
            {
                if (!context.threadResources.ContainsKey(thread))
                {
                    var resources = new ThreadResources();

                    //resources.Queue.Enqueue(context.runner.Randomness.Clone(thread));

                    context.threadResources.Add(thread, resources);
                }
            }

            return(context);
        }
コード例 #3
0
        private ThreadResources GetThreadResources()
        {
            ThreadResources resources = (ThreadResources)threadResources.Get();

            if (resources == null)
            {
                resources          = new ThreadResources();
                resources.termEnum = Terms();
                // Cache does not have to be thread-safe, it is only used by one thread at the same time
                resources.termInfoCache = new SimpleLRUCache(DEFAULT_CACHE_SIZE);
                threadResources.Set(resources);
            }
            return(resources);
        }
コード例 #4
0
        private ThreadResources GetThreadResources(IState state)
        {
            ThreadResources resources = threadResources.Get(state);

            if (resources == null)
            {
                resources = new ThreadResources {
                    termEnum = Terms(state)
                };
                // Cache does not have to be thread-safe, it is only used by one thread at the same time
                threadResources.Set(resources);
            }
            return(resources);
        }
コード例 #5
0
        /// <summary>
        /// Returns the <see cref="TermInfo"/> for a <see cref="Term"/> in the set, or <c>null</c>. </summary>
        private TermInfo Get(Term term, bool mustSeekEnum)
        {
            if (size == 0)
            {
                return(null);
            }

            EnsureIndexIsRead();
            TermInfoAndOrd  tiOrd     = termsCache.Get(new CloneableTerm(term));
            ThreadResources resources = GetThreadResources();

            if (!mustSeekEnum && tiOrd != null)
            {
                return(tiOrd);
            }

            return(SeekEnum(resources.termEnum, term, tiOrd, true));
        }
コード例 #6
0
        /// <summary>Returns the TermInfo for a Term in the set, or null. </summary>
        private TermInfo Get(Term term, bool useCache)
        {
            if (size == 0)
            {
                return(null);
            }

            EnsureIndexIsRead();

            TermInfo        ti;
            ThreadResources resources = GetThreadResources();

            Lucene.Net.Util.Cache.Cache cache = null;

            if (useCache)
            {
                cache = resources.termInfoCache;
                // check the cache first if the term was recently looked up
                ti = (TermInfo)cache.Get(term);
                if (ti != null)
                {
                    return(ti);
                }
            }

            // optimize sequential access: first try scanning cached enum w/o seeking
            SegmentTermEnum enumerator = resources.termEnum;

            if (enumerator.Term() != null && ((enumerator.Prev() != null && term.CompareTo(enumerator.Prev()) > 0) || term.CompareTo(enumerator.Term()) >= 0))
            {
                int enumOffset = (int)(enumerator.position / totalIndexInterval) + 1;
                if (indexTerms.Length == enumOffset || term.CompareTo(indexTerms[enumOffset]) < 0)
                {
                    // no need to seek

                    int numScans = enumerator.ScanTo(term);
                    if (enumerator.Term() != null && term.CompareTo(enumerator.Term()) == 0)
                    {
                        ti = enumerator.TermInfo();
                        if (cache != null && numScans > 1)
                        {
                            // we only  want to put this TermInfo into the cache if
                            // scanEnum skipped more than one dictionary entry.
                            // This prevents RangeQueries or WildcardQueries to
                            // wipe out the cache when they iterate over a large numbers
                            // of terms in order
                            cache.Put(term, ti);
                        }
                    }
                    else
                    {
                        ti = null;
                    }

                    return(ti);
                }
            }

            // random-access: must seek
            SeekEnum(enumerator, GetIndexOffset(term));
            enumerator.ScanTo(term);
            if (enumerator.Term() != null && term.CompareTo(enumerator.Term()) == 0)
            {
                ti = enumerator.TermInfo();
                if (cache != null)
                {
                    cache.Put(term, ti);
                }
            }
            else
            {
                ti = null;
            }
            return(ti);
        }
コード例 #7
0
        private static RandomizedContext Context(ThreadClass thread)
        {
            var group = thread.Instance.GetThreadGroup();

            RandomizedContext context;

            lock (globalLock)
            {
                while (true)
                {
                    context = contexts[group];
                    if (context == null && group.Parent != null)
                        group = group.Parent;
                    else
                        break;
                }

                // TODO: revisit
                if (context == null)
                {
                    context = contexts[group] = new RandomizedContext(group, null, null);
                }
            }

            if (context == null)
            {
                // TODO: revisit
                var message = "No context information for thread," + thread.Name + ". " +
                            "Is this thread running under a " + typeof(RandomizedRunner).Name + " context? ";

                throw new IllegalStateException(message);
            }

            lock (context.contextLock)
            {
                if (!context.threadResources.ContainsKey(thread))
                {
                    var resources = new ThreadResources();

                    //resources.Queue.Enqueue(context.runner.Randomness.Clone(thread));

                    context.threadResources.Add(thread, resources);
                }
            }

            return context;
        }
コード例 #8
0
 private ThreadResources GetThreadResources()
 {
     ThreadResources resources = threadResources.Get();
     if (resources == null)
     {
         resources = new ThreadResources
                         {termEnum = Terms(), termInfoCache = new SimpleLRUCache<Term, TermInfo>(DEFAULT_CACHE_SIZE)};
         // Cache does not have to be thread-safe, it is only used by one thread at the same time
         threadResources.Set(resources);
     }
     return resources;
 }
コード例 #9
0
 internal ThreadResources GetThreadResources()
 {
     ThreadResources resources = (ThreadResources)threadResources.Get();
     if (resources == null)
     {
         resources = new ThreadResources();
         resources.termEnum = Terms();
         // cache does not have to be thread-safe, it is only used by one thread at the same time
         resources.termInfoCache = new SimpleLRUCache(DEFAULT_CACHE_SIZE);
         threadResources.Set(resources);
     }
     return resources;
 }