コード例 #1
0
        /// <summary>
        /// Specifies how long the lease will last, absent auto-renewal.
        ///
        /// If auto-renewal is enabled (the default), then a shorter duration means more frequent auto-renewal requests,
        /// while an infinite duration means no auto-renewal requests. Furthermore, if the lease-holding process were to
        /// exit without explicitly releasing, then duration determines how long other processes would need to wait in
        /// order to acquire the lease.
        ///
        /// If auto-renewal is disabled, then duration determines how long the lease will be held.
        ///
        /// Defaults to 30s.
        /// </summary>
        public AzureBlobLeaseOptionsBuilder Duration(TimeSpan duration)
        {
            var durationTimeoutValue = new TimeoutValue(duration, nameof(duration));

            if (durationTimeoutValue.CompareTo(MinLeaseDuration) < 0 ||
                (!durationTimeoutValue.IsInfinite && durationTimeoutValue.CompareTo(MaxNonInfiniteLeaseDuration) > 0))
            {
                throw new ArgumentOutOfRangeException(nameof(duration), duration, $"Must be infinite or in [{MinLeaseDuration}, {MaxNonInfiniteLeaseDuration}]");
            }

            this._duration = durationTimeoutValue;
            return(this);
        }
        /// <summary>
        /// Specifies how long the lock will last, absent auto-extension. Because auto-extension exists,
        /// this value generally will have little effect on program behavior. However, making the expiry longer means that
        /// auto-extension requests can occur less frequently, saving resources. On the other hand, when a lock is abandoned
        /// without explicit release (e. g. if the holding process crashes), the expiry determines how long other processes
        /// would need to wait in order to acquire it.
        ///
        /// Defaults to 30s.
        /// </summary>
        public RedisDistributedSynchronizationOptionsBuilder Expiry(TimeSpan expiry)
        {
            var expiryTimeoutValue = new TimeoutValue(expiry, nameof(expiry));

            if (expiryTimeoutValue.IsInfinite || expiryTimeoutValue.CompareTo(MinimumExpiry) < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(expiry), expiry, $"Must be >= {MinimumExpiry.TimeSpan} and < ∞");
            }
            this._expiry = expiryTimeoutValue;
            return(this);
        }
        /// <summary>
        /// Waiting to acquire a lock requires a busy wait that alternates acquire attempts and sleeps.
        /// This determines how much time is spent sleeping between attempts. Lower values will raise the
        /// volume of acquire requests under contention but will also raise the responsiveness (how long
        /// it takes a waiter to notice that a contended the lock has become available).
        ///
        /// Specifying a range of values allows the implementation to select an actual value in the range
        /// at random for each sleep. This helps avoid the case where two clients become "synchronized"
        /// in such a way that results in one client monopolizing the lock.
        ///
        /// The default is [10ms, 800ms]
        /// </summary>
        public RedisDistributedSynchronizationOptionsBuilder BusyWaitSleepTime(TimeSpan min, TimeSpan max)
        {
            var minTimeoutValue = new TimeoutValue(min, nameof(min));
            var maxTimeoutValue = new TimeoutValue(max, nameof(max));

            if (minTimeoutValue.IsInfinite)
            {
                throw new ArgumentOutOfRangeException(nameof(min), "may not be infinite");
            }
            if (maxTimeoutValue.IsInfinite || maxTimeoutValue.CompareTo(min) < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(max), max, "must be non-infinite and greater than " + nameof(min));
            }

            this._minBusyWaitSleepTime = minTimeoutValue;
            this._maxBusyWaitSleepTime = maxTimeoutValue;
            return(this);
        }
コード例 #4
0
        public void SetKeepaliveCadence(TimeoutValue keepaliveCadence)
        {
            Invariant.Require(!this._isExternallyOwnedConnection);

            lock (this.Lock)
            {
                Invariant.Require(this._state != State.Disposed);

                var originalKeepaliveCadence = this._keepaliveCadence;
                this._keepaliveCadence = keepaliveCadence;

                if (!this.StartMonitorWorkerIfNeededNoLock() &&
                    this._state == State.Active &&
                    !this.HasRegisteredMonitoringHandlesNoLock &&
                    keepaliveCadence.CompareTo(originalKeepaliveCadence) < 0)
                {
                    // If we get here, then we already have an active worker performing
                    // keepalive on a longer cadence. Since that worker is likely asleep,
                    // we fire state changed to wake it up
                    this.FireStateChangedNoLock();
                }
            }
        }