public CacheSettings(RetrySettings retrySettings, JitterSettings jitterSettings, int cacheDurationInSeconds = 60, bool wrapInRetry = true)
        {
            RetrySettings = retrySettings;
            JitterSettings = jitterSettings;
            CacheDurationInSeconds = cacheDurationInSeconds;
            WrapInRetry = wrapInRetry;

            Validate();
        }
        /// <summary>
        /// Updates the settings.
        /// </summary>
        /// <param name="settings">Settings.</param>
        public void UpdateSettings(JitterSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            Settings = settings;
        }
        /// <summary>
        /// Updates the settings.
        /// </summary>
        /// <param name="settings">Settings.</param>
        public void UpdateSettings(JitterSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            Settings = settings;
        }
        public RetrySettings(JitterSettings jitterSettings, int maximumNumberOfAttempts = 5, int millisecondsPerSlot = 32, bool truncateNumberOfSlots = true, int maximumNumberOfSlotsWhenTruncated = 16)
        {
            MaximumNumberOfAttempts = maximumNumberOfAttempts;
            MillisecondsPerSlot = millisecondsPerSlot;
            TruncateNumberOfSlots = truncateNumberOfSlots;
            MaximumNumberOfSlotsWhenTruncated = maximumNumberOfSlotsWhenTruncated;
            JitterSettings = jitterSettings;

            Validate();
        }
Beispiel #5
0
        /// <summary>
        /// Applies jitter to the <see cref="input" /> using the passed in settings.
        /// </summary>
        /// <param name="input">An integer you want to apply jitter to.</param>
        /// <param name="settings">Object that contains settings.</param>
        /// <returns>A random number between <see cref="input" /> +/- percentage.</returns>
        public static int Apply(int input, JitterSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            int lowerBoundary = input * (100 - settings.Percentage) / 100;
            int upperBoundary = input * (100 + settings.Percentage) / 100;

            return Random.Next(lowerBoundary, upperBoundary);
        }
Beispiel #6
0
        /// <summary>
        /// Applies jitter to the <see cref="input" /> using the passed in settings.
        /// </summary>
        /// <param name="input">A double you want to apply jitter to.</param>
        /// <param name="percentage">An integer that has the percentage of the <see cref="input" /> to go below and above the <see cref="input" /> as outer bounds.</param>
        /// <returns>A random number between <see cref="input" /> +/- percentage.</returns>
        public static double Apply(double input, JitterSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            double lowerBoundary = input * (100 - settings.Percentage) / 100;
            double upperBoundary = input * (100 + settings.Percentage) / 100;

            return(lowerBoundary + (upperBoundary - lowerBoundary) * Random.NextDouble());
        }
Beispiel #7
0
        /// <summary>
        /// Applies jitter to the <see cref="input" /> using the passed in settings.
        /// </summary>
        /// <param name="input">An integer you want to apply jitter to.</param>
        /// <param name="settings">Object that contains settings.</param>
        /// <returns>A random number between <see cref="input" /> +/- percentage.</returns>
        public static int Apply(int input, JitterSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            int lowerBoundary = input * (100 - settings.Percentage) / 100;
            int upperBoundary = input * (100 + settings.Percentage) / 100;

            return(Random.Next(lowerBoundary, upperBoundary));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="JitterInstance"/> class with passed in settings.
 /// </summary>
 /// <param name="percentage">Percentage of jitter to apply.</param>
 public JitterInstance(JitterSettings settings)
 {
     UpdateSettings(settings);
 }
Beispiel #9
0
        /// <summary>
        /// Applies jitter to the <see cref="input" /> using the passed in settings.
        /// </summary>
        /// <param name="input">A double you want to apply jitter to.</param>
        /// <param name="percentage">An integer that has the percentage of the <see cref="input" /> to go below and above the <see cref="input" /> as outer bounds.</param>
        /// <returns>A random number between <see cref="input" /> +/- percentage.</returns>
        public static double Apply(double input, JitterSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            double lowerBoundary = input * (100 - settings.Percentage) / 100;
            double upperBoundary = input * (100 + settings.Percentage) / 100;

            return lowerBoundary + (upperBoundary - lowerBoundary) * Random.NextDouble();
        }
Beispiel #10
0
 /// <summary>
 /// Initialize the DefaultPercentage; it can be overriden by the consumer of this class at application startup.
 /// </summary>
 static Jitter()
 {
     Settings = new JitterSettings();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="JitterInstance"/> class with passed in settings.
 /// </summary>
 /// <param name="percentage">Percentage of jitter to apply.</param>
 public JitterInstance(JitterSettings settings)
 {
     UpdateSettings(settings);
 }
Beispiel #12
0
 /// <summary>
 /// Initialize the DefaultPercentage; it can be overriden by the consumer of this class at application startup.
 /// </summary>
 static Jitter()
 {
     Settings = new JitterSettings();
 }