Exemplo n.º 1
0
 public void CancelRealtimeFeed(
     IModuleInfo clientInfo,
     Guid subscriptionId,
     AsyncQueueCallback <QuotedAssetSet> callback)
 {
     _mds.CancelRealtimeFeed(clientInfo, subscriptionId, callback);
 }
Exemplo n.º 2
0
        public void TestQueueOrdering()
        {
            using (Reference <ILogger> loggerRef = Reference <ILogger> .Create(new TraceLogger(true)))
            {
                const int iterations  = 500000; // yes 500,000 - takes about 1.0 seconds
                int       sendCount   = 0;
                int       recvCount   = 0;
                int       totalErrors = 0;
                int       threadCount = 0;

                // dispatches a series of tasks
                using (AsyncThreadQueue queue = new AsyncThreadQueue(loggerRef.Target))
                {
                    AsyncQueueCallback <int> callback = delegate(int data)
                    {
                        int count   = Interlocked.Increment(ref recvCount);
                        int threads = Interlocked.Increment(ref threadCount);
                        try
                        {
                            if (threads > 1)
                            {
                                // multithreading issue!
                                int errors = Interlocked.Increment(ref totalErrors);
                                if (errors <= 50)
                                {
                                    loggerRef.Target.LogDebug("Thread count = {0}!", threads);
                                }
                            }
                            if (count != (data + 1))
                            {
                                int errors = Interlocked.Increment(ref totalErrors);
                                if (errors <= 50)
                                {
                                    loggerRef.Target.LogDebug("Recv count = {0} but (data+1) = {1}", count, data + 1);
                                }
                            }
                        }
                        finally
                        {
                            Interlocked.Decrement(ref threadCount);
                        }
                    };
                    for (int i = 0; i < iterations; i++)
                    {
                        Interlocked.Increment(ref sendCount);
                        queue.Dispatch <int>(i, callback);
                    }
                    Assert.AreEqual <int>(iterations, sendCount);
                    long itemsRemaining = queue.WaitUntilEmpty(TimeSpan.FromSeconds(30));
                    Assert.AreEqual <long>(0, itemsRemaining);
                    Assert.AreEqual <int>(iterations, recvCount);
                    Assert.AreEqual <int>(0, totalErrors);
                }
            }
        }
Exemplo n.º 3
0
 public void StartRealtimeFeed(
     IModuleInfo clientInfo,
     Guid subscriptionId,
     NamedValueSet requestParams,
     QuotedAssetSet instruments,
     TimeSpan subsLifetime,
     AsyncQueueCallback <QuotedAssetSet> callback)
 {
     _mds.StartRealtimeFeed(
         clientInfo, subscriptionId, requestParams, instruments, subsLifetime, callback);
 }
Exemplo n.º 4
0
        public void TestPriorityQueue()
        {
            using (Reference <ILogger> loggerRef = Reference <ILogger> .Create(new TraceLogger(true)))
            {
                const int iterations = 100000;
                int       sendCount  = 0;
                int       recvCount  = 0;
                int       excpCount  = 0;

                // dispatches a series of tasks with various priorities
                int   nPriorities = Enum.GetValues(typeof(AsyncQueuePriority)).Length;
                int[] _LastRecv   = new int[nPriorities];
                for (int l = 0; l < nPriorities; l++)
                {
                    _LastRecv[l] = -1;
                }
                using (AsyncPriorityQueue queue = new AsyncPriorityQueue(loggerRef.Target))
                {
                    AsyncQueueCallback <int> callback = delegate(int value)
                    {
                        int count = Interlocked.Increment(ref recvCount);
                        // check values are recevied in priority order
                        int i        = value % 1000000;
                        int priority = (value - i) / 1000000;
                        int last     = _LastRecv[priority];
                        if (i <= last)
                        {
                            int errors = Interlocked.Increment(ref excpCount);
                            if (errors <= 50)
                            {
                                loggerRef.Target.LogDebug("Priority={0}: i ({1}) not greater than previous ({2})!",
                                                          priority, i, last);
                            }
                        }
                        _LastRecv[priority] = i;
                    };
                    for (int i = 0; i < iterations; i++)
                    {
                        Interlocked.Increment(ref sendCount);
                        AsyncQueuePriority priority = (AsyncQueuePriority)(i % nPriorities);
                        int value = (int)priority * 1000000 + i;
                        queue.Dispatch <int>(value, callback, priority);
                    }
                    Assert.AreEqual <int>(iterations, sendCount);
                    long itemsRemaining = queue.WaitUntilEmpty(TimeSpan.FromSeconds(30));
                    Assert.AreEqual <long>(0, itemsRemaining);
                    Assert.AreEqual <int>(iterations, recvCount);
                    Assert.AreEqual <int>(0, excpCount);
                }
            }
        }
Exemplo n.º 5
0
        public void TestQueueConcurrency()
        {
            using (Reference <ILogger> loggerRef = Reference <ILogger> .Create(new TraceLogger(true)))
            {
                const int iterations         = 10;
                int       sendCount          = 0;
                int       totalErrors        = 0;
                int       threadCount        = 0;
                int       callbacksCommenced = 0;
                int       callbacksCompleted = 0;

                // dispatches a series of tasks
                using (AsyncThreadQueue queue = new AsyncThreadQueue(loggerRef.Target))
                {
                    AsyncQueueCallback <int> callback = delegate(int data)
                    {
                        Interlocked.Increment(ref callbacksCommenced);
                        int threads = Interlocked.Increment(ref threadCount);
                        try
                        {
                            if (threads > 1)
                            {
                                // multithreading issue!
                                int errors = Interlocked.Increment(ref totalErrors);
                                if (errors <= 50)
                                {
                                    loggerRef.Target.LogDebug("Thread count = {0}!", threads);
                                }
                            }
                            Thread.Sleep(TimeSpan.FromSeconds(0.5));
                        }
                        finally
                        {
                            Interlocked.Decrement(ref threadCount);
                        }
                        Interlocked.Increment(ref callbacksCompleted);
                    };
                    for (int i = 0; i < iterations; i++)
                    {
                        Interlocked.Increment(ref sendCount);
                        queue.Dispatch <int>(i, callback);
                    }
                    Assert.AreEqual <int>(iterations, sendCount);
                    long itemsRemaining = queue.WaitUntilEmpty(TimeSpan.FromSeconds(30));
                    Assert.AreEqual <long>(0, itemsRemaining);
                    Assert.AreEqual <int>(0, totalErrors);
                    Assert.AreEqual <int>(iterations, callbacksCommenced);
                    Assert.AreEqual <int>(iterations, callbacksCompleted);
                }
            }
        }
Exemplo n.º 6
0
 public SubscriptionDetail(
     Guid subscriptionId,
     TimeSpan subsLifetime,
     MdsSubsState initialState,
     MDSRequestType requestType,
     AsyncQueueCallback <QuotedAssetSet> clientCallback)
 {
     SubsId      = subscriptionId;
     SubsExpires = DateTimeOffset.Now + subsLifetime;
     //_DataLifetime = dataLifetime;
     SubsState      = initialState;
     RequestType    = requestType;
     ClientCallback = clientCallback;
 }
Exemplo n.º 7
0
        protected void EnqueueData <T>(T data, AsyncQueueCallback <T> callback, AsyncQueuePriority priority, string itemKey)
        {
            if (_Closed)
            {
                return; // throw new InvalidOperationException("Cannot enqueue while closing!");
            }
            AsyncQueueItemUser <T> item = new AsyncQueueItemUser <T>(callback, data);

            AcquireLock();
            try
            {
                this.OnEnqueueItem(item, priority, itemKey);
            }
            finally
            {
                ReleaseLock();
            }

            // dispatch a dequeue thread if needed
            Interlocked.Increment(ref _EnqueueThreads);
            ThreadPool.QueueUserWorkItem(DequeueItems);
        }
Exemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 /// <param name="callback"></param>
 public void Dispatch <T>(T data, AsyncQueueCallback <T> callback)
 {
     EnqueueData(data, callback, AsyncQueuePriority.Normal, null);
 }
Exemplo n.º 9
0
 public AsyncEventThrottle(AsyncQueueCallback <T> callback)
 {
     _Callback = callback ?? throw new ArgumentNullException(nameof(callback));
 }
Exemplo n.º 10
0
 public void Dispatch <T>(T data, AsyncQueueCallback <T> callback, AsyncQueuePriority priority)
 {
     EnqueueData(data, callback, priority, null);
 }
Exemplo n.º 11
0
 public void Dispatch <T>(T data, AsyncQueueCallback <T> callback, AsyncQueuePriority priority, string itemKey)
 {
     EnqueueData <T>(data, callback, priority, itemKey);
 }
Exemplo n.º 12
0
 public AsyncQueueItemUser(AsyncQueueCallback <T> userCallback, T userData)
 {
     _UserCallback = userCallback;
     _UserData     = userData;
 }