public void CancelRealtimeFeed( IModuleInfo clientInfo, Guid subscriptionId, AsyncQueueCallback <QuotedAssetSet> callback) { _mds.CancelRealtimeFeed(clientInfo, subscriptionId, callback); }
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); } } }
public void StartRealtimeFeed( IModuleInfo clientInfo, Guid subscriptionId, NamedValueSet requestParams, QuotedAssetSet instruments, TimeSpan subsLifetime, AsyncQueueCallback <QuotedAssetSet> callback) { _mds.StartRealtimeFeed( clientInfo, subscriptionId, requestParams, instruments, subsLifetime, callback); }
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); } } }
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); } } }
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; }
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); }
/// <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); }
public AsyncEventThrottle(AsyncQueueCallback <T> callback) { _Callback = callback ?? throw new ArgumentNullException(nameof(callback)); }
public void Dispatch <T>(T data, AsyncQueueCallback <T> callback, AsyncQueuePriority priority) { EnqueueData(data, callback, priority, null); }
public void Dispatch <T>(T data, AsyncQueueCallback <T> callback, AsyncQueuePriority priority, string itemKey) { EnqueueData <T>(data, callback, priority, itemKey); }
public AsyncQueueItemUser(AsyncQueueCallback <T> userCallback, T userData) { _UserCallback = userCallback; _UserData = userData; }