IBootstrap.cs 4.2 KB

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