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); } }
public override Envelope <TItem, TBorrowerId> Borrow(TBorrowerId borrower, string membershipId) { ExclusiveItemStore <TItem, TBorrowerId> .BorrowerAccount borrowerAccount = null; TItem tItem = default(TItem); Envelope <TItem, TBorrowerId> envelope; this.Trace("Exclusive item store Borrow"); if (!this.borrowersDictionary.TryLockKey(borrower, out borrowerAccount)) { ExclusiveItemStore <TItem, TBorrowerId> .BorrowerAccount borrowerAccount1 = new ExclusiveItemStore <TItem, TBorrowerId> .BorrowerAccount(membershipId, this, this.borrowerAccountMaxCacheSize); try { this.borrowersDictionary.AddOrLockKey(borrower, borrowerAccount1, out borrowerAccount); } finally { this.borrowersDictionary.TryUnlockKey(borrower); } } else { try { if (borrowerAccount.MembershipId == membershipId) { if (borrowerAccount.IdleQueue.TryDequeue(out tItem)) { TraceHelper.Current.ExclusiveStoreTookFromCache(borrower.ToString(), typeof(TItem).ToString()); envelope = new Envelope <TItem, TBorrowerId>(tItem, membershipId, this, borrower); return(envelope); } } else { borrowerAccount.IdleQueue.Clear(); borrowerAccount.MembershipId = membershipId; } TraceHelper.Current.ExclusiveStoreCreatedNew(borrower.ToString(), typeof(TItem).ToString()); return(new Envelope <TItem, TBorrowerId>(base.Factory.Create(borrower, membershipId), membershipId, this, borrower)); } finally { this.borrowersDictionary.TryUnlockKey(borrower); } return(envelope); } TraceHelper.Current.ExclusiveStoreCreatedNew(borrower.ToString(), typeof(TItem).ToString()); return(new Envelope <TItem, TBorrowerId>(base.Factory.Create(borrower, membershipId), membershipId, this, borrower)); }