ChannelPoolSettings.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Channels
  5. {
  6. using System.ComponentModel;
  7. using System.Runtime;
  8. using System.ServiceModel;
  9. public class ChannelPoolSettings
  10. {
  11. TimeSpan idleTimeout;
  12. TimeSpan leaseTimeout;
  13. int maxOutboundChannelsPerEndpoint;
  14. public ChannelPoolSettings()
  15. {
  16. this.idleTimeout = OneWayDefaults.IdleTimeout;
  17. this.leaseTimeout = OneWayDefaults.LeaseTimeout;
  18. this.maxOutboundChannelsPerEndpoint = OneWayDefaults.MaxOutboundChannelsPerEndpoint;
  19. }
  20. ChannelPoolSettings(ChannelPoolSettings poolToBeCloned)
  21. {
  22. this.idleTimeout = poolToBeCloned.idleTimeout;
  23. this.leaseTimeout = poolToBeCloned.leaseTimeout;
  24. this.maxOutboundChannelsPerEndpoint = poolToBeCloned.maxOutboundChannelsPerEndpoint;
  25. }
  26. [DefaultValue(typeof(TimeSpan), OneWayDefaults.IdleTimeoutString)]
  27. public TimeSpan IdleTimeout
  28. {
  29. get
  30. {
  31. return this.idleTimeout;
  32. }
  33. set
  34. {
  35. if (value < TimeSpan.Zero)
  36. {
  37. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  38. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  39. }
  40. if (TimeoutHelper.IsTooLarge(value))
  41. {
  42. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  43. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  44. }
  45. this.idleTimeout = value;
  46. }
  47. }
  48. [DefaultValue(typeof(TimeSpan), OneWayDefaults.LeaseTimeoutString)]
  49. public TimeSpan LeaseTimeout
  50. {
  51. get
  52. {
  53. return leaseTimeout;
  54. }
  55. set
  56. {
  57. if (value < TimeSpan.Zero)
  58. {
  59. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  60. SR.GetString(SR.SFxTimeoutOutOfRange0)));
  61. }
  62. if (TimeoutHelper.IsTooLarge(value))
  63. {
  64. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  65. SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
  66. }
  67. this.leaseTimeout = value;
  68. }
  69. }
  70. [DefaultValue(OneWayDefaults.MaxOutboundChannelsPerEndpoint)]
  71. public int MaxOutboundChannelsPerEndpoint
  72. {
  73. get
  74. {
  75. return this.maxOutboundChannelsPerEndpoint;
  76. }
  77. set
  78. {
  79. if (value <= 0)
  80. {
  81. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
  82. SR.GetString(SR.ValueMustBePositive)));
  83. }
  84. this.maxOutboundChannelsPerEndpoint = value;
  85. }
  86. }
  87. internal ChannelPoolSettings Clone()
  88. {
  89. return new ChannelPoolSettings(this);
  90. }
  91. internal bool IsMatch(ChannelPoolSettings channelPoolSettings)
  92. {
  93. if (channelPoolSettings == null)
  94. {
  95. return false;
  96. }
  97. if (this.idleTimeout != channelPoolSettings.idleTimeout)
  98. {
  99. return false;
  100. }
  101. if (this.leaseTimeout != channelPoolSettings.leaseTimeout)
  102. {
  103. return false;
  104. }
  105. if (this.maxOutboundChannelsPerEndpoint != channelPoolSettings.maxOutboundChannelsPerEndpoint)
  106. {
  107. return false;
  108. }
  109. return true;
  110. }
  111. internal bool InternalShouldSerialize()
  112. {
  113. return (this.maxOutboundChannelsPerEndpoint != OneWayDefaults.MaxOutboundChannelsPerEndpoint
  114. || this.idleTimeout != OneWayDefaults.IdleTimeout
  115. || this.leaseTimeout != OneWayDefaults.LeaseTimeout);
  116. }
  117. }
  118. }