Example #1
0
        public override void Return(Envelope <TItem, TBorrowerId> envelope)
        {
            ExclusiveItemStore <TItem, TBorrowerId> .BorrowerAccount borrowerAccount = null;
            this.Trace("Exclusive item store Return");
            try
            {
                if (!this.borrowersDictionary.TryLockKey(envelope.Borrower, out borrowerAccount))
                {
                    ExclusiveItemStore <TItem, TBorrowerId> .BorrowerAccount borrowerAccount1 = new ExclusiveItemStore <TItem, TBorrowerId> .BorrowerAccount(envelope.MembershipId, this, this.borrowerAccountMaxCacheSize);

                    this.borrowersDictionary.AddOrLockKey(envelope.Borrower, borrowerAccount1, out borrowerAccount);
                }
                if (envelope.MembershipId == borrowerAccount.MembershipId)
                {
                    try
                    {
                        borrowerAccount.IdleQueue.Enqueue(envelope.Item);
                    }
                    catch (OverflowException overflowException1)
                    {
                        OverflowException overflowException = overflowException1;
                        overflowException.Trace("Ignoring exception");
                    }
                }
            }
            finally
            {
                this.borrowersDictionary.TryUnlockKey(envelope.Borrower);
            }
        }
Example #2
0
        public override Envelope <TItem, TBorrowerId> Borrow(TBorrowerId borrower, string membershipId)
        {
            TItem tItem = default(TItem);

            this.Trace("Shared Item store Borrow");
            if (this.cache.TryLockKey(membershipId, out tItem))
            {
                TraceHelper.Current.SharedStoreTookFromCache(borrower.ToString(), typeof(TItem).ToString());
            }
            else
            {
                TraceHelper.Current.SharedStoreCreatedNew(borrower.ToString(), typeof(TItem).ToString());
                TItem tItem1 = base.Factory.Create(borrower, membershipId);
                try
                {
                    this.cache.AddOrLockKey(membershipId, tItem1, out tItem);
                }
                catch (OverflowException overflowException1)
                {
                    OverflowException overflowException = overflowException1;
                    overflowException.Trace("Ignoring exception");
                }
            }
            return(new Envelope <TItem, TBorrowerId>(tItem, membershipId, this, borrower));
        }