|
| 1 | +namespace net.openstack.Providers.Rackspace.Objects.LoadBalancers |
| 2 | +{ |
| 3 | + using System; |
| 4 | + using Newtonsoft.Json; |
| 5 | + |
| 6 | + /// <summary> |
| 7 | + /// This class represents a connection throttling configuration for a load |
| 8 | + /// balancer in the load balancer service. |
| 9 | + /// </summary> |
| 10 | + /// <threadsafety static="true" instance="false"/> |
| 11 | + /// <preliminary/> |
| 12 | + [JsonObject(MemberSerialization.OptIn)] |
| 13 | + public class ConnectionThrottles |
| 14 | + { |
| 15 | + /// <summary> |
| 16 | + /// This is the backing field for the <see cref="MaxConnectionRate"/> property. |
| 17 | + /// </summary> |
| 18 | + [JsonProperty("maxConnectionRate", DefaultValueHandling = DefaultValueHandling.Ignore)] |
| 19 | + private int? _maxConnectionRate; |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// This is the backing field for the <see cref="MaxConnections"/> property. |
| 23 | + /// </summary> |
| 24 | + [JsonProperty("maxConnections", DefaultValueHandling = DefaultValueHandling.Ignore)] |
| 25 | + private int? _maxConnections; |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// This is the backing field for the <see cref="MinConnections"/> property. |
| 29 | + /// </summary> |
| 30 | + [JsonProperty("minConnections", DefaultValueHandling = DefaultValueHandling.Ignore)] |
| 31 | + private int? _minConnections; |
| 32 | + |
| 33 | + /// <summary> |
| 34 | + /// This is the backing field for the <see cref="RateInterval"/> property. |
| 35 | + /// </summary> |
| 36 | + [JsonProperty("rateInterval", DefaultValueHandling = DefaultValueHandling.Ignore)] |
| 37 | + private int? _rateInterval; |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Initializes a new instance of the <see cref="ConnectionThrottles"/> class during |
| 41 | + /// JSON deserialization. |
| 42 | + /// </summary> |
| 43 | + [JsonConstructor] |
| 44 | + protected ConnectionThrottles() |
| 45 | + { |
| 46 | + } |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// Initializes a new instance of the <see cref="ConnectionThrottles"/> class with |
| 50 | + /// the specified configuration. |
| 51 | + /// </summary> |
| 52 | + /// <param name="maxConnectionRate">The maximum number of connections per rate interval to allow from a single IP address, or <c>0</c> to not limit the connection rate. If this value is <c>null</c>, the value for this throttle will not be changed during a call to <see cref="ILoadBalancerService.UpdateThrottlesAsync"/>.</param> |
| 53 | + /// <param name="maxConnections">The maximum number of connections to allow from a single IP address, or <c>0</c> to not limit the number connections. If this value is <c>null</c>, the value for this throttle will not be changed during a call to <see cref="ILoadBalancerService.UpdateThrottlesAsync"/>.</param> |
| 54 | + /// <param name="minConnections">The minimum number of connections to allow from an IP address before applying throttling restrictions. If this value is <c>null</c>, the value for this throttle will not be changed during a call to <see cref="ILoadBalancerService.UpdateThrottlesAsync"/>.</param> |
| 55 | + /// <param name="rateInterval">The time period for which the connection rate limit is evaluated. If this value is <c>null</c>, the value for this throttle will not be changed during a call to <see cref="ILoadBalancerService.UpdateThrottlesAsync"/>.</param> |
| 56 | + /// <exception cref="ArgumentOutOfRangeException"> |
| 57 | + /// If <paramref name="maxConnectionRate"/> is less than 0. |
| 58 | + /// <para>-or-</para> |
| 59 | + /// <para>If <paramref name="maxConnections"/> is less than 0.</para> |
| 60 | + /// <para>-or-</para> |
| 61 | + /// <para>If <paramref name="minConnections"/> is less than 0.</para> |
| 62 | + /// <para>-or-</para> |
| 63 | + /// <para>If <paramref name="rateInterval"/> is negative or <see cref="TimeSpan.Zero"/>.</para> |
| 64 | + /// </exception> |
| 65 | + public ConnectionThrottles(int? maxConnectionRate, int? maxConnections, int? minConnections, TimeSpan? rateInterval) |
| 66 | + { |
| 67 | + if (maxConnectionRate < 0) |
| 68 | + throw new ArgumentOutOfRangeException("maxConnectionRate"); |
| 69 | + if (maxConnections < 0) |
| 70 | + throw new ArgumentOutOfRangeException("maxConnections"); |
| 71 | + if (minConnections < 0) |
| 72 | + throw new ArgumentOutOfRangeException("minConnections"); |
| 73 | + if (rateInterval <= TimeSpan.Zero) |
| 74 | + throw new ArgumentOutOfRangeException("rateInterval"); |
| 75 | + |
| 76 | + _maxConnectionRate = maxConnectionRate; |
| 77 | + _maxConnections = maxConnections; |
| 78 | + _minConnections = minConnections; |
| 79 | + _rateInterval = rateInterval != null ? (int?)rateInterval.Value.TotalSeconds : default(int?); |
| 80 | + } |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// Gets the maximum number of connections allowed from a single IP address in the defined <see cref="RateInterval"/>. |
| 84 | + /// A value of 0 indicates an unlimited connection rate. A value of <c>null</c> indicates this connection limit is |
| 85 | + /// not configured. |
| 86 | + /// </summary> |
| 87 | + /// <value> |
| 88 | + /// The maximum number of connections allowed from a single IP address in the defined <see cref="RateInterval"/>, |
| 89 | + /// or one of the following values: |
| 90 | + /// |
| 91 | + /// <list type="bullet"> |
| 92 | + /// <item>0, if the connection rate is configured but unlimited.</item> |
| 93 | + /// <item><c>null</c>, if the connection rate limit is not configured.</item> |
| 94 | + /// </list> |
| 95 | + /// </value> |
| 96 | + public int? MaxConnectionRate |
| 97 | + { |
| 98 | + get |
| 99 | + { |
| 100 | + return _maxConnectionRate; |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + /// <summary> |
| 105 | + /// Gets the maximum number of connections allowed for a single IP address. A value of 0 indicates |
| 106 | + /// an unlimited number of connections. A value of <c>null</c> indicates this connection limit is |
| 107 | + /// not configured. |
| 108 | + /// </summary> |
| 109 | + public int? MaxConnections |
| 110 | + { |
| 111 | + get |
| 112 | + { |
| 113 | + return _maxConnections; |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + /// <summary> |
| 118 | + /// Gets the minimum number of connections to allow from an IP address before applying throttling restrictions. |
| 119 | + /// A value of <c>null</c> indicates this connection limit is not configured. |
| 120 | + /// </summary> |
| 121 | + public int? MinConnections |
| 122 | + { |
| 123 | + get |
| 124 | + { |
| 125 | + return _minConnections; |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + /// <summary> |
| 130 | + /// Gets the time period for which <see cref="MaxConnectionRate"/> is evaluated. For example, a <see cref="MaxConnectionRate"/> |
| 131 | + /// of 30 with a <see cref="RateInterval"/> of 60 seconds would allow a maximum of 30 connections per minute from a single IP |
| 132 | + /// address. A value of <c>null</c> indicates this connection limit is not configured. |
| 133 | + /// </summary> |
| 134 | + public TimeSpan? RateInterval |
| 135 | + { |
| 136 | + get |
| 137 | + { |
| 138 | + if (_rateInterval == null) |
| 139 | + return null; |
| 140 | + |
| 141 | + return TimeSpan.FromSeconds(_rateInterval.Value); |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | +} |
0 commit comments