public void Send()
        {
            var allEndpoints = new ThreadSafeSet<Endpoint>();
            while (_continueSending)
            {
                if(!_choke.ShouldBeginSend())
                    continue;

                var endpoints = gatherEndpoints(allEndpoints.All()).ToArray();
                if (!endpoints.Any())
                {
                    _choke.NoMessagesToSend();
                    continue;
                }
                allEndpoints.Add(endpoints);

                endpoints.Each(endpoint =>
                {
                    var messages = gatherMessagesToSend(endpoint);

                    _choke.StartSend();

                    sendMessages(endpoint, messages)
                        .ContinueWith(x => allEndpoints.Remove(endpoint));
                });
            }
        }
Esempio n. 2
0
 /// <summary>Retrieves a reference to the specified item.</summary>
 /// <typeparam name="T">The type of the items in the set.</typeparam>
 /// <param name="tset">The set to search.</param>
 /// <param name="item">The item sought.</param>
 /// <returns>A reference to a matching item if it is present in the set, null otherwise.</returns>
 /// <remarks>This allows use of the set to restrain a group of objects to exclude duplicates, allowing for
 /// reduced memory use, and reference-based equality checking, comparable with how
 /// <see cref="string.IsInterned(string)"/> allows one to check for a copy of a string in the CLR intern pool,
 /// but also allowing for removal, clearing and multiple pools. This is clearly only valid for reference types.
 /// </remarks>
 public static T Find <T>(this ThreadSafeSet <T> tset, T item) where T : class
 {
     ThreadSafeSet <T> .Box box = tset.Obtain(item);
     return(box == null ? null : box.Value);
 }
Esempio n. 3
0
        public void ConstantReturns()
        {
            var hs = new ThreadSafeSet <int>();

            Assert.IsFalse(((ICollection <int>)hs).IsReadOnly);
        }
Esempio n. 4
0
 public void ExcessiveCapacity()
 {
     var dict = new ThreadSafeSet <decimal>(((int.MaxValue >> 1) + 2));
 }
Esempio n. 5
0
 public void NegativeCapacity()
 {
     var dict = new ThreadSafeSet <decimal>(-1);
 }
 /// <summary>Initialises a new instance of the <see cref="UniqueElementProducerConsumer{T}"/> class.</summary>
 public UniqueElementProducerConsumer()
 {
     _store = new ThreadSafeSet <T>();
 }
 /// <summary>Initialises a new instance of the <see cref="UniqueElementProducerConsumer{T}"/> class.</summary>
 /// <param name="collection">Collection to fill the <see cref="UniqueElementProducerConsumer{T}"/> with upon
 /// creation.</param>
 public UniqueElementProducerConsumer(IEnumerable <T> collection)
 {
     _store = new ThreadSafeSet <T>(collection);
 }
 /// <summary>Initialises a new instance of the <see cref="UniqueElementProducerConsumer{T}"/> class.</summary>
 /// <param name="comparer">Comparer to determine uniqueness of elements.</param>
 public UniqueElementProducerConsumer(IEqualityComparer <T> comparer)
 {
     _store = new ThreadSafeSet <T>(comparer);
 }
Esempio n. 9
0
 /// <summary>Creates a new <see cref="ThreadSafeAtomizer&lt;T>"/> and fills it from the collection passed.</summary>
 /// <param name="collection">The <see cref="IEnumerable&lt;T>"/> to fill the atomizer with on construction.</param>
 /// <param name="comparer">An <see cref="IEqualityComparer&lt;T>"/> to use when comparing items
 /// added to the collection.</param>
 public ThreadSafeAtomizer(IEnumerable <T> collection, IEqualityComparer <T> comparer)
 {
     _store = new ThreadSafeSet <T>(collection, comparer);
 }
Esempio n. 10
0
 /// <summary>Creates a new <see cref="ThreadSafeAtomizer&lt;T>"/>.</summary>
 /// <param name="comparer">An <see cref="IEqualityComparer&lt;T>"/> to use when comparing items
 /// added to the store.</param>
 public ThreadSafeAtomizer(IEqualityComparer <T> comparer)
 {
     _store = new ThreadSafeSet <T>(comparer);
 }
Esempio n. 11
0
 /// <summary>Creates a new <see cref="ThreadSafeAtomizer&lt;T>"/>.</summary>
 /// <param name="capacity">The initial capacity of the atomizer.</param>
 /// <param name="comparer">An <see cref="IEqualityComparer&lt;T>"/> to use when comparing items
 /// added to the store.</param>
 public ThreadSafeAtomizer(int capacity, IEqualityComparer <T> comparer)
 {
     _store = new ThreadSafeSet <T>(capacity, comparer);
 }
Esempio n. 12
0
 private ThreadSafeAtomizer(ThreadSafeSet <T> store)
 {
     _store = store;
 }