コード例 #1
0
        private bool TryRescheduleCollection_Impl(ActivationData item, TimeSpan timeout)
        {
            // note: we expect the activation lock to be held.
            if (default(DateTime) == item.CollectionTicket)
            {
                return(false);
            }
            ThrowIfTicketIsInvalid(item.CollectionTicket);
            if (IsExpired(item.CollectionTicket))
            {
                return(false);
            }

            DateTime oldTicket = item.CollectionTicket;
            DateTime newTicket = MakeTicketFromTimeSpan(timeout);

            // if the ticket value doesn't change, then the source and destination bucket are the same and there's nothing to do.
            if (newTicket.Equals(oldTicket))
            {
                return(true);
            }

            Bucket bucket;

            if (!buckets.TryGetValue(oldTicket, out bucket) || !bucket.TryRemove(item))
            {
                // fail: item is not associated with currentKey.
                return(false);
            }

            // it shouldn't be possible for Add to throw an exception here, as only one concurrent competitor should be able to reach to this point in the method.
            item.ResetCollectionTicket();
            Add(item, newTicket);
            return(true);
        }
コード例 #2
0
        public bool TryRescheduleCollection(ActivationData item)
        {
            if (item.IsExemptFromCollection)
            {
                return(false);
            }

            lock (item)
            {
                if (TryRescheduleCollection_Impl(item, item.CollectionAgeLimit))
                {
                    return(true);
                }

                item.ResetCollectionTicket();
                return(false);
            }
        }