This is an automated email from the ASF dual-hosted git repository. nightowl888 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit 356ff151f2693589d6aee3924cad12e8efc923ab Author: Shad Storhaug <[email protected]> AuthorDate: Tue Apr 20 00:14:09 2021 +0700 Lucene.Net.TestFramework: Removed FEATURE_RANDOMIZEDCONTEXT and deleted all files related to randomizedtesting --- .../Attributes/SeedDecoratorAttribute.cs | 45 ----- .../Support/Randomized/ISeedDecorator.cs | 30 ---- .../Support/Randomized/MurmurHash3.cs | 41 ----- .../Support/Randomized/RandomizedContext.cs | 185 --------------------- .../Support/Randomized/RandomizedRunner.cs | 66 -------- .../Support/Randomized/Randomness.cs | 107 ------------ .../Support/Randomized/SeedUtils.cs | 99 ----------- .../Support/Randomized/SingleThreadedRandom.cs | 132 --------------- .../Support/Randomized/ThreadGroup.cs | 144 ---------------- 9 files changed, 849 deletions(-) diff --git a/src/Lucene.Net.TestFramework/Support/Randomized/Attributes/SeedDecoratorAttribute.cs b/src/Lucene.Net.TestFramework/Support/Randomized/Attributes/SeedDecoratorAttribute.cs deleted file mode 100644 index ed778ae..0000000 --- a/src/Lucene.Net.TestFramework/Support/Randomized/Attributes/SeedDecoratorAttribute.cs +++ /dev/null @@ -1,45 +0,0 @@ -#if FEATURE_RANDOMIZEDCONTEXT -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace Lucene.Net.Randomized.Attributes -{ - // LUCENENET NOTE: Not used (and not CLS compliant because of the constructor), - // so marking internal instead of public - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] - internal class SeedDecoratorAttribute : System.Attribute - { - public IList<Type> Decorators { get; set; } - - public SeedDecoratorAttribute(params Type[] decorators) - { - this.Decorators = new List<Type>(); - - foreach (Type item in decorators) - { - if (item.ImplementedInterfaces.Contains(typeof(ISeedDecorator))) - this.Decorators.Add(item); - } - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.TestFramework/Support/Randomized/ISeedDecorator.cs b/src/Lucene.Net.TestFramework/Support/Randomized/ISeedDecorator.cs deleted file mode 100644 index d00eb4c..0000000 --- a/src/Lucene.Net.TestFramework/Support/Randomized/ISeedDecorator.cs +++ /dev/null @@ -1,30 +0,0 @@ -#if FEATURE_RANDOMIZEDCONTEXT -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; - -namespace Lucene.Net.Randomized -{ - public interface ISeedDecorator - { - void Initialize(Type type); - - int Decorate(int seed); - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.TestFramework/Support/Randomized/MurmurHash3.cs b/src/Lucene.Net.TestFramework/Support/Randomized/MurmurHash3.cs deleted file mode 100644 index 6671e6e..0000000 --- a/src/Lucene.Net.TestFramework/Support/Randomized/MurmurHash3.cs +++ /dev/null @@ -1,41 +0,0 @@ -#if FEATURE_RANDOMIZEDCONTEXT -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace Lucene.Net.Randomized -{ - public class MurmurHash3 - { - private MurmurHash3() - { - } - - public static int Hash(int k) - { - uint x = (uint)k; - - x ^= x >> 16; - x *= 0x85ebca6b; - x ^= x >> 13; - x *= 0xc2b2ae35; - x ^= x >> 16; - - return (int)x; - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.TestFramework/Support/Randomized/RandomizedContext.cs b/src/Lucene.Net.TestFramework/Support/Randomized/RandomizedContext.cs deleted file mode 100644 index 1d0e848..0000000 --- a/src/Lucene.Net.TestFramework/Support/Randomized/RandomizedContext.cs +++ /dev/null @@ -1,185 +0,0 @@ -#if FEATURE_RANDOMIZEDCONTEXT -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using Lucene.Net.Support; -using Lucene.Net.Support.Threading; -using System; -using System.Threading; - -namespace Lucene.Net.Randomized -{ - // LUCENENET TODO: Look into salvaging this. It would be better to have some sort of "randomized context" that runs the tests - // than to have extra Similarity and TimeZone parameters everywhere, if possible. - public class RandomizedContext : IDisposable - { - private static readonly object globalLock = new object(); - protected readonly object m_contextLock = new object(); - - private class ThreadResources - { - public ThreadResources() - { - //this.Queue = new Queue<Randomness>(); - } - - //public Queue<Randomness> Queue { get; private set; } - } - - private static readonly IdentityHashMap<ThreadGroup, RandomizedContext> contexts = - new IdentityHashMap<ThreadGroup, RandomizedContext>(); - - private readonly WeakDictionary<ThreadClass, ThreadResources> threadResources - = new WeakDictionary<ThreadClass, ThreadResources>(); - - private readonly ThreadGroup threadGroup; - private Type suiteClass; - private volatile Boolean isDisposed = false; - private RandomizedRunner runner; - - public Type GetTargetType - { - get - { - this.GuardDiposed(); - return this.suiteClass; - } - } - - public int RunnerSeed - { - get - { - return this.runner.Randomness.Seed; - } - } - - // LUCENENET TODO - /*public Random Random - { - get { return this.Randomness.Random; } - } - - public Randomness Randomness - { - get { - //var randomness = this.PerThreadResources.Queue.Peek(); - //return randomness; - } - }*/ - - private ThreadResources PerThreadResources - { - get - { - this.GuardDiposed(); - lock (m_contextLock) - { - var resource = threadResources[ThreadClass.Current()]; - - return resource; - } - } - } - - private RandomizedContext(ThreadGroup group, Type suiteClass, RandomizedRunner runner) - { - this.threadGroup = group; - this.suiteClass = suiteClass; - this.runner = runner; - } - - public static RandomizedContext Current { get { return Context(ThreadClass.Current()); } } - - 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.m_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; - } - - private void GuardDiposed() - { - if (this.isDisposed) - throw new ObjectDisposedException("RandomContext is diposed for thread," + Thread.CurrentThread.Name + "."); - } - - private static RandomizedContext Create(ThreadGroup tg, Type suiteClass, RandomizedRunner runner) - { - lock (globalLock) - { - var context = new RandomizedContext(tg, suiteClass, runner); - contexts.Add(tg, context); - context.threadResources.Add(ThreadClass.Current(), new ThreadResources()); - return context; - } - } - - // LUCENENET specific: Implemented dispose pattern - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.TestFramework/Support/Randomized/RandomizedRunner.cs b/src/Lucene.Net.TestFramework/Support/Randomized/RandomizedRunner.cs deleted file mode 100644 index 8b01f33..0000000 --- a/src/Lucene.Net.TestFramework/Support/Randomized/RandomizedRunner.cs +++ /dev/null @@ -1,66 +0,0 @@ -#if FEATURE_RANDOMIZEDCONTEXT -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using Lucene.Net.Randomized.Attributes; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Threading; - -namespace Lucene.Net.Randomized -{ - public class RandomizedRunner - { - public Randomness Randomness { get; protected set; } - - private Type suiteClass; - - private static int sequence = new int(); - - public RandomizedRunner(Type testClass) - { - this.suiteClass = testClass; - - var list = new List<ISeedDecorator>(); - var attrs = this.suiteClass.GetCustomAttributes<SeedDecoratorAttribute>(true); - foreach (var attr in attrs) - { - foreach (var decoratorType in attr.Decorators) - { - var decorator = (ISeedDecorator)Activator.CreateInstance(decoratorType); - decorator.Initialize(testClass); - list.Add(decorator); - } - } - - int ticks = (int)System.DateTime.Now.Ticks; - int randomSeed = MurmurHash3.Hash(NextSequence() + ticks); - - int initialSeed = randomSeed; - - this.Randomness = new Randomness(initialSeed, list.ToArray()); - } - - private static int NextSequence() - { - return Interlocked.Increment(ref sequence); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.TestFramework/Support/Randomized/Randomness.cs b/src/Lucene.Net.TestFramework/Support/Randomized/Randomness.cs deleted file mode 100644 index 2ff1151..0000000 --- a/src/Lucene.Net.TestFramework/Support/Randomized/Randomness.cs +++ /dev/null @@ -1,107 +0,0 @@ -#if FEATURE_RANDOMIZEDCONTEXT -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using Lucene.Net.Support.Threading; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Lucene.Net.Randomized -{ - /// <summary> - /// Per-thread, per-lifecycle state randomness defined as an initial seed and - /// the current Random instance for that context. - /// </summary> - /// <remarks> - /// <para> - /// An instance of this class will be typically available from <see cref="RandomizedContext"/>. - /// No need to instantiate manually. - /// </para> - /// </remarks> - /// <see cref="Lucene.Net.Randomized.RandomizedContext"/> - /// <see cref="Lucene.Net.Randomized.SingleThreadedRandom"/> - public class Randomness : IDisposable - { - private List<ISeedDecorator> decorators; - - public Random Random - { - get { return this.SingleThreadedRandom; } - } - - protected SingleThreadedRandom SingleThreadedRandom { get; set; } - - public int Seed { get; protected set; } - - public Randomness(ThreadClass owner, int seed, params ISeedDecorator[] decorators) - : this(owner, seed, decorators.ToList()) - { - } - - public Randomness(int seed, params ISeedDecorator[] decorators) - : this(ThreadClass.Current(), seed, decorators) - { - } - - protected Randomness(ThreadClass owner, int seed, IList<ISeedDecorator> decorators) - { - this.Seed = seed; - this.decorators = decorators.ToList(); - - var decoratedSeed = Decorate(seed, this.decorators); - - this.SingleThreadedRandom = new SingleThreadedRandom(owner, - new Random(decoratedSeed) - ); - } - - public Randomness Clone(ThreadClass newOwner) - { - return new Randomness(newOwner, this.Seed, this.decorators); - } - - public override string ToString() - { - return "[Randomess, seed=" + this.Seed.ToString() + "]"; - } - - private static int Decorate(int seed, List<ISeedDecorator> decorators) - { - var result = seed; - decorators.ForEach(o => result = o.Decorate(result)); - - return result; - } - - // LUCENENET specific: Implemented dispose pattern - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (disposing) - { - SingleThreadedRandom?.Dispose(); - } - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.TestFramework/Support/Randomized/SeedUtils.cs b/src/Lucene.Net.TestFramework/Support/Randomized/SeedUtils.cs deleted file mode 100644 index 00cd067..0000000 --- a/src/Lucene.Net.TestFramework/Support/Randomized/SeedUtils.cs +++ /dev/null @@ -1,99 +0,0 @@ -#if FEATURE_RANDOMIZEDCONTEXT -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * -*/ - -using Lucene.Net.Support; -using System; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; - -namespace Lucene.Net.Randomized -{ - public static class SeedUtils - { - private readonly static char[] HEX = "0123456789ABCDEF".ToCharArray(); - - public static int ParseSeed(string seed) - { - int result = 0; - foreach (var item in seed.ToCharArray()) - { - var character = char.ToLower(item); // LUCENENET NOTE: Intentionally using current culture - result = result << 4; - if (character >= '0' && character <= '9') - result |= (character - '0'); - else if (character >= 'a' && character <= 'f') - result |= (character - 'a' + 10); - else - throw new ArgumentException("Expected the seed to be in a hexadecimal format: " + seed); - } - - return result; - } - - public static string FormatSeed(int seed) - { - var sb = new StringBuilder(); - do - { - sb.Append(HEX[(int)(seed & 0xf)]); - seed = seed >> 4; - } while (seed != 0); - - return sb.ToString().Reverse().ToString(); - } - - public static int[] ParseSeedChain(String chain) - { - if (chain == null) - throw new ArgumentNullException("chain"); - - chain = chain.Replace("[", "").Replace("]", ""); - var matches = Regex.Matches("[0-9A-Fa-f\\:]+", chain); - if (matches.Count == 0) - throw new ArgumentException("Not a valid seed chain: " + chain, "chain"); - - var parts = chain.Split(':').TrimEnd(); - int[] result = new int[parts.Length]; - - for (int i = 0; i < parts.Length; i++) - result[i] = ParseSeed(parts[i]); - - return result; - } - - public static string FormatStringChain(params Randomness[] values) - { - var sb = new StringBuilder(); - sb.Append("["); - for (int i = 0; i < values.Length; i++) - { - if (i > 0) - sb.Append(":"); - sb.Append(FormatSeed(values[i].Seed)); - } - - return sb.ToString(); - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.TestFramework/Support/Randomized/SingleThreadedRandom.cs b/src/Lucene.Net.TestFramework/Support/Randomized/SingleThreadedRandom.cs deleted file mode 100644 index c8ff5de..0000000 --- a/src/Lucene.Net.TestFramework/Support/Randomized/SingleThreadedRandom.cs +++ /dev/null @@ -1,132 +0,0 @@ -#if FEATURE_RANDOMIZEDCONTEXT -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using Lucene.Net.Support.Threading; -using System; -using System.Threading; - -namespace Lucene.Net.Randomized -{ - /// <summary> - /// A random with a delegate, preventing <see cref="System.Random"/>and locked - /// to be used by a single thread. This is the equivelant to AssertRandom - /// </summary> - public class SingleThreadedRandom : Random, IDisposable - { - private Random @delegate; - private readonly WeakReference ownerRef; - private readonly string ownerName; - private string trace; - - private volatile Boolean isDisposed = true; - - public SingleThreadedRandom(ThreadClass owner, Random @delegate) - : base(0) - { - this.@delegate = @delegate; - this.ownerRef = new WeakReference(owner); - this.ownerName = owner.Name; - this.trace = Environment.StackTrace; - } - - public override int Next() - { - this.Guard(); - return [email protected](); - } - - public override int Next(int maxValue) - { - this.Guard(); - return [email protected](maxValue); - } - - public override int Next(int minValue, int maxValue) - { - this.Guard(); - return [email protected](minValue, maxValue); - } - - public override void NextBytes(byte[] buffer) - { - this.Guard(); - [email protected](buffer); - } - - public override double NextDouble() - { - this.Guard(); - return [email protected](); - } - - public override bool Equals(object obj) - { - this.Guard(); - return [email protected](obj); - } - - public override int GetHashCode() - { - this.Guard(); - return [email protected](); - } - - private void Guard() - { - /* checkValid(); */ - - if (!this.isDisposed) - throw new ObjectDisposedException( - "This instance of SingleThreadRandom has been disposed. "); - - Thread owner = ownerRef.Target as Thread; - - if (owner == null || owner != Thread.CurrentThread) - { - var message = "The SingleThreadRandom instance was created for thread," + ownerName + - " and must not be shared. The current thread is " + Thread.CurrentThread.Name + "."; - - throw new InvalidOperationException(message, - new Exception("The instance was illegally accessed\n" + this.trace)); - } - } - - // LUCENENET specific: Implemented dispose pattern - - public void Dispose() - { - this.Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (!this.isDisposed) - { - if (disposing) - { - this.@delegate = null; - this.ownerRef.Target = null; - } - - this.isDisposed = true; - } - } - } -} -#endif \ No newline at end of file diff --git a/src/Lucene.Net.TestFramework/Support/Randomized/ThreadGroup.cs b/src/Lucene.Net.TestFramework/Support/Randomized/ThreadGroup.cs deleted file mode 100644 index a9075b8..0000000 --- a/src/Lucene.Net.TestFramework/Support/Randomized/ThreadGroup.cs +++ /dev/null @@ -1,144 +0,0 @@ -#if FEATURE_RANDOMIZEDCONTEXT -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; - -namespace Lucene.Net.Randomized -{ - public static class ThreadGroupExtensions - { - private static readonly object globalLock = new object(); - - public static ThreadGroup GetThreadGroup(this Thread thread) - { - if (thread.IsAlive) - { - lock (ThreadGroup.GroupLock) - { - foreach (var group in ThreadGroup.Groups) - { - group.Prune(); - foreach (var weak in group) - { - if (thread == (Thread)weak.Target) - return group; - } - } - - ThreadGroup.Root.Add(thread); - return ThreadGroup.Root; - } - } - return null; - } - } - - public class ThreadGroup : IEnumerable<WeakReference>, IDisposable - { - private List<WeakReference> threads; - private static object s_groupLock = new Object(); - - internal static object GroupLock - { - get - { - if (s_groupLock == null) - s_groupLock = new Object(); - return s_groupLock; - } - } - - internal static List<ThreadGroup> Groups { get; set; } - - static ThreadGroup() - { - Groups = new List<ThreadGroup>(); - Root = new ThreadGroup("Root"); - } - - public static ThreadGroup Root { get; set; } - - public string Name { get; protected set; } - - public ThreadGroup Parent { get; protected set; } - - public ThreadGroup(string name) - : this(name, null) - { - } - - public ThreadGroup(string name, ThreadGroup parent) - { - this.Parent = parent; - this.Name = name; - this.threads = new List<WeakReference>(); - lock (GroupLock) - { - Groups.Add(this); - } - } - - internal void Add(Thread instance) - { - var threadRef = new WeakReference(instance); - this.threads.Add(threadRef); - } - - internal void Prune() - { - var copy = this.threads.ToList(); - foreach (var item in copy) - { - if (!item.IsAlive) - this.threads.Remove(item); - } - } - - public IEnumerator<WeakReference> GetEnumerator() - { - return this.threads.GetEnumerator(); - } - - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return this.threads.GetEnumerator(); - } - - // LUCENENET specific: Implemented dispose pattern - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (disposing) - { - lock (GroupLock) - { - Groups.Remove(this); - } - } - } - } -} -#endif \ No newline at end of file
