MarshalAppServer.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using SuperSocket.SocketBase;
  6. using SuperSocket.SocketBase.Provider;
  7. using SuperSocket.SocketBase.Config;
  8. using System.Reflection;
  9. using SuperSocket.SocketBase.Metadata;
  10. namespace SuperSocket.SocketEngine
  11. {
  12. class MarshalAppServer : MarshalByRefObject, IWorkItem, IStatusInfoSource
  13. {
  14. private IWorkItem m_AppServer;
  15. /// <summary>
  16. /// Initializes a new instance of the <see cref="AppDomainAppServer"/> class.
  17. /// </summary>
  18. /// <param name="serviceTypeName">Name of the service type.</param>
  19. public MarshalAppServer(string serviceTypeName)
  20. {
  21. var serviceType = Type.GetType(serviceTypeName);
  22. m_AppServer = (IWorkItem)Activator.CreateInstance(serviceType);
  23. }
  24. /// <summary>
  25. /// Gets the name of the server instance.
  26. /// </summary>
  27. public string Name
  28. {
  29. get { return m_AppServer.Name; }
  30. }
  31. /// <summary>
  32. /// Setups the specified root config.
  33. /// </summary>
  34. /// <param name="bootstrap">The bootstrap.</param>
  35. /// <param name="config">The socket server instance config.</param>
  36. /// <param name="factories">The providers.</param>
  37. /// <returns></returns>
  38. public bool Setup(IBootstrap bootstrap, IServerConfig config, ProviderFactoryInfo[] factories)
  39. {
  40. return m_AppServer.Setup(bootstrap, config, factories);
  41. }
  42. /// <summary>
  43. /// Gets the server's config.
  44. /// </summary>
  45. /// <value>
  46. /// The server's config.
  47. /// </value>
  48. public IServerConfig Config
  49. {
  50. get
  51. {
  52. if(m_AppServer == null)
  53. return null;
  54. return m_AppServer.Config;
  55. }
  56. }
  57. /// <summary>
  58. /// Reports the potential configuration change.
  59. /// </summary>
  60. /// <param name="config">The server config which may be changed.</param>
  61. /// <exception cref="System.NotImplementedException"></exception>
  62. public void ReportPotentialConfigChange(IServerConfig config)
  63. {
  64. m_AppServer.ReportPotentialConfigChange(config);
  65. }
  66. /// <summary>
  67. /// Starts this server instance.
  68. /// </summary>
  69. /// <returns>
  70. /// return true if start successfull, else false
  71. /// </returns>
  72. public bool Start()
  73. {
  74. return m_AppServer.Start();
  75. }
  76. /// <summary>
  77. /// Stops this server instance.
  78. /// </summary>
  79. public void Stop()
  80. {
  81. m_AppServer.Stop();
  82. }
  83. /// <summary>
  84. /// Gets the current state of the work item.
  85. /// </summary>
  86. /// <value>
  87. /// The state.
  88. /// </value>
  89. public ServerState State
  90. {
  91. get { return m_AppServer.State; }
  92. }
  93. /// <summary>
  94. /// Gets the total session count.
  95. /// </summary>
  96. public int SessionCount
  97. {
  98. get { return m_AppServer.SessionCount; }
  99. }
  100. StatusInfoAttribute[] IStatusInfoSource.GetServerStatusMetadata()
  101. {
  102. return m_AppServer.GetServerStatusMetadata();
  103. }
  104. StatusInfoCollection IStatusInfoSource.CollectServerStatus(StatusInfoCollection nodeStatus)
  105. {
  106. return m_AppServer.CollectServerStatus(nodeStatus);
  107. }
  108. public void TransferSystemMessage(string messageType, object messageData)
  109. {
  110. m_AppServer.TransferSystemMessage(messageType, messageData);
  111. }
  112. /// <summary>
  113. /// Obtains a lifetime service object to control the lifetime policy for this instance.
  114. /// </summary>
  115. /// <returns>
  116. /// An object of type <see cref="T:System.Runtime.Remoting.Lifetime.ILease" /> used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the <see cref="P:System.Runtime.Remoting.Lifetime.LifetimeServices.LeaseManagerPollTime" /> property.
  117. /// </returns>
  118. /// <PermissionSet>
  119. /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="RemotingConfiguration, Infrastructure" />
  120. /// </PermissionSet>
  121. public override object InitializeLifetimeService()
  122. {
  123. return null;
  124. }
  125. }
  126. }