Exemplo n.º 1
0
        public CacheSettings(RetrySettings retrySettings, JitterSettings jitterSettings, int cacheDurationInSeconds = 60, bool wrapInRetry = true)
        {
            RetrySettings = retrySettings;
            JitterSettings = jitterSettings;
            CacheDurationInSeconds = cacheDurationInSeconds;
            WrapInRetry = wrapInRetry;

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

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

            Settings = settings;
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 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);
        }
Exemplo n.º 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());
        }
Exemplo n.º 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));
        }
Exemplo n.º 8
0
 /// <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);
 }
Exemplo n.º 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();
        }
Exemplo n.º 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();
 }
Exemplo n.º 11
0
 /// <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);
 }
Exemplo n.º 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();
 }