RootConfig.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using SuperSocket.Common;
  7. using System.Collections.Specialized;
  8. using System.Configuration;
  9. namespace SuperSocket.SocketBase.Config
  10. {
  11. /// <summary>
  12. /// Root configuration model
  13. /// </summary>
  14. [Serializable]
  15. public partial class RootConfig : IRootConfig
  16. {
  17. /// <summary>
  18. /// Initializes a new instance of the <see cref="RootConfig"/> class.
  19. /// </summary>
  20. /// <param name="rootConfig">The root config.</param>
  21. public RootConfig(IRootConfig rootConfig)
  22. {
  23. rootConfig.CopyPropertiesTo(this);
  24. this.OptionElements = rootConfig.OptionElements;
  25. }
  26. /// <summary>
  27. /// Initializes a new instance of the <see cref="RootConfig"/> class.
  28. /// </summary>
  29. public RootConfig()
  30. {
  31. int maxWorkingThread, maxCompletionPortThreads;
  32. ThreadPool.GetMaxThreads(out maxWorkingThread, out maxCompletionPortThreads);
  33. MaxWorkingThreads = maxWorkingThread;
  34. MaxCompletionPortThreads = maxCompletionPortThreads;
  35. int minWorkingThread, minCompletionPortThreads;
  36. ThreadPool.GetMinThreads(out minWorkingThread, out minCompletionPortThreads);
  37. MinWorkingThreads = minWorkingThread;
  38. MinCompletionPortThreads = minCompletionPortThreads;
  39. PerformanceDataCollectInterval = 60;
  40. Isolation = IsolationMode.None;
  41. }
  42. #region IRootConfig Members
  43. /// <summary>
  44. /// Gets/Sets the max working threads.
  45. /// </summary>
  46. public int MaxWorkingThreads { get; set; }
  47. /// <summary>
  48. /// Gets/sets the min working threads.
  49. /// </summary>
  50. public int MinWorkingThreads { get; set; }
  51. /// <summary>
  52. /// Gets/sets the max completion port threads.
  53. /// </summary>
  54. public int MaxCompletionPortThreads { get; set; }
  55. /// <summary>
  56. /// Gets/sets the min completion port threads.
  57. /// </summary>
  58. public int MinCompletionPortThreads { get; set; }
  59. /// <summary>
  60. /// Gets/sets the performance data collect interval, in seconds.
  61. /// </summary>
  62. public int PerformanceDataCollectInterval { get; set; }
  63. /// <summary>
  64. /// Gets/sets a value indicating whether [disable performance data collector].
  65. /// </summary>
  66. /// <value>
  67. /// <c>true</c> if [disable performance data collector]; otherwise, <c>false</c>.
  68. /// </value>
  69. public bool DisablePerformanceDataCollector { get; set; }
  70. /// <summary>
  71. /// Gets/sets the isolation mode.
  72. /// </summary>
  73. public IsolationMode Isolation { get; set; }
  74. /// <summary>
  75. /// Gets/sets the log factory name.
  76. /// </summary>
  77. /// <value>
  78. /// The log factory.
  79. /// </value>
  80. public string LogFactory { get; set; }
  81. /// <summary>
  82. /// Gets/sets the option elements.
  83. /// </summary>
  84. public NameValueCollection OptionElements { get; set; }
  85. /// <summary>
  86. /// Gets the child config.
  87. /// </summary>
  88. /// <typeparam name="TConfig">The type of the config.</typeparam>
  89. /// <param name="childConfigName">Name of the child config.</param>
  90. /// <returns></returns>
  91. public virtual TConfig GetChildConfig<TConfig>(string childConfigName)
  92. where TConfig : ConfigurationElement, new()
  93. {
  94. return this.OptionElements.GetChildConfig<TConfig>(childConfigName);
  95. }
  96. #endregion
  97. }
  98. }