IBootstrap.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Text;
  6. using SuperSocket.SocketBase;
  7. using SuperSocket.SocketBase.Config;
  8. using SuperSocket.SocketBase.Logging;
  9. using System.Net;
  10. namespace SuperSocket.SocketBase
  11. {
  12. /// <summary>
  13. /// The bootstrap start result
  14. /// </summary>
  15. public enum StartResult
  16. {
  17. /// <summary>
  18. /// No appserver has been set in the bootstrap, so nothing was started
  19. /// </summary>
  20. None,
  21. /// <summary>
  22. /// All appserver instances were started successfully
  23. /// </summary>
  24. Success,
  25. /// <summary>
  26. /// Some appserver instances were started successfully, but some of them failed
  27. /// </summary>
  28. PartialSuccess,
  29. /// <summary>
  30. /// All appserver instances failed to start
  31. /// </summary>
  32. Failed
  33. }
  34. /// <summary>
  35. /// SuperSocket bootstrap
  36. /// </summary>
  37. public interface IBootstrap
  38. {
  39. /// <summary>
  40. /// Gets all the app servers running in this bootstrap
  41. /// </summary>
  42. IEnumerable<IWorkItem> AppServers { get; }
  43. /// <summary>
  44. /// Gets the config.
  45. /// </summary>
  46. IRootConfig Config { get; }
  47. /// <summary>
  48. /// Initializes the bootstrap with the configuration
  49. /// </summary>
  50. /// <returns></returns>
  51. bool Initialize();
  52. /// <summary>
  53. /// Initializes the bootstrap with a listen endpoint replacement dictionary
  54. /// </summary>
  55. /// <param name="listenEndPointReplacement">The listen end point replacement.</param>
  56. /// <returns></returns>
  57. bool Initialize(IDictionary<string, IPEndPoint> listenEndPointReplacement);
  58. /// <summary>
  59. /// Initializes the bootstrap with the configuration
  60. /// </summary>
  61. /// <param name="serverConfigResolver">The server config resolver.</param>
  62. /// <returns></returns>
  63. bool Initialize(Func<IServerConfig, IServerConfig> serverConfigResolver);
  64. /// <summary>
  65. /// Initializes the bootstrap with the configuration
  66. /// </summary>
  67. /// <param name="logFactory">The log factory.</param>
  68. /// <returns></returns>
  69. bool Initialize(ILogFactory logFactory);
  70. /// <summary>
  71. /// Initializes the bootstrap with the configuration
  72. /// </summary>
  73. /// <param name="serverConfigResolver">The server config resolver.</param>
  74. /// <param name="logFactory">The log factory.</param>
  75. /// <returns></returns>
  76. bool Initialize(Func<IServerConfig, IServerConfig> serverConfigResolver, ILogFactory logFactory);
  77. /// <summary>
  78. /// Starts this bootstrap.
  79. /// </summary>
  80. /// <returns></returns>
  81. StartResult Start();
  82. /// <summary>
  83. /// Stops this bootstrap.
  84. /// </summary>
  85. void Stop();
  86. /// <summary>
  87. /// Gets the startup config file.
  88. /// </summary>
  89. string StartupConfigFile { get; }
  90. /// <summary>
  91. /// Gets the base directory.
  92. /// </summary>
  93. /// <value>
  94. /// The base directory.
  95. /// </value>
  96. string BaseDirectory { get; }
  97. }
  98. /// <summary>
  99. /// The bootstrap interface to support add new server instance in runtime
  100. /// </summary>
  101. public interface IDynamicBootstrap
  102. {
  103. /// <summary>
  104. /// Adds a new server into the bootstrap.
  105. /// </summary>
  106. /// <param name="config">The new server's config.</param>
  107. /// <returns></returns>
  108. bool Add(IServerConfig config);
  109. /// <summary>
  110. /// Adds a new server into the bootstrap and then start it.
  111. /// </summary>
  112. /// <param name="config">The new server's config.</param>
  113. /// <returns></returns>
  114. bool AddAndStart(IServerConfig config);
  115. /// <summary>
  116. /// Removes the server instance which is specified by name.
  117. /// </summary>
  118. /// <param name="name">The name of the server instance to be removed.</param>
  119. void Remove(string name);
  120. }
  121. }