예제 #1
0
 public long GetFreeCapacity()
 {
     using (var lockKey = LockKey.GetLock(this.lockObject, defaultTimeoutInMilliseconds))
     {
         return(Thresold - currentCapacity);
     }
 }
예제 #2
0
 public ThreadSafeInMemoryQueue(long capacity)
 {
     using (var lockKey = LockKey.GetLock(this.lockObject, defaultTimeoutInMilliseconds))
     {
         this.Thresold = capacity;
     }
 }
예제 #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);
     }
 }
예제 #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);
        }