Example #1
0
 public long GetFreeCapacity()
 {
     using (var lockKey = LockKey.GetLock(this.lockObject, defaultTimeoutInMilliseconds))
     {
         return(Thresold - currentCapacity);
     }
 }
Example #2
0
 public ThreadSafeInMemoryQueue(long capacity)
 {
     using (var lockKey = LockKey.GetLock(this.lockObject, defaultTimeoutInMilliseconds))
     {
         this.Thresold = capacity;
     }
 }
Example #3
0
 public void EnqueData(List <T> data)
 {
     using (var lockKey = LockKey.GetLock(this.lockObject, defaultTimeoutInMilliseconds))
     {
         if (currentCapacity + data.Count > Thresold)
         {
             throw new Exception(QueueErrros.ExceededCapacity);
         }
         currentCapacity = currentCapacity + data.Count;
         cq.Enqueue(data);
     }
 }
Example #4
0
        public List <T> DequeData()
        {
            using (var lockKey = LockKey.GetLock(this.lockObject, defaultTimeoutInMilliseconds))
            {
                if (currentCapacity == 0)
                {
                    return(null);
                }

                while (cq.TryDequeue(out List <T> data))
                {
                    currentCapacity = currentCapacity - data.Count;
                    return(data);
                }
            }

            throw new Exception(QueueErrros.FailedToRetrieveData);
        }