CreateCommsManagerPlugin.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using log4net;
  31. using OpenSim.Data;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Communications;
  34. using OpenSim.Framework.Communications.Services;
  35. using OpenSim.Framework.Communications.Cache;
  36. using OpenSim.Framework.Communications.Osp;
  37. using OpenSim.Framework.Servers;
  38. using OpenSim.Framework.Servers.HttpServer;
  39. using OpenSim.Region.Communications.Hypergrid;
  40. using OpenSim.Region.Communications.Local;
  41. using OpenSim.Region.Communications.OGS1;
  42. namespace OpenSim.ApplicationPlugins.CreateCommsManager
  43. {
  44. public class CreateCommsManagerPlugin : IApplicationPlugin
  45. {
  46. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  47. #region IApplicationPlugin Members
  48. // TODO: required by IPlugin, but likely not at all right
  49. private string m_name = "CreateCommsManagerPlugin";
  50. private string m_version = "0.0";
  51. public string Version
  52. {
  53. get { return m_version; }
  54. }
  55. public string Name
  56. {
  57. get { return m_name; }
  58. }
  59. protected OpenSimBase m_openSim;
  60. protected BaseHttpServer m_httpServer;
  61. protected CommunicationsManager m_commsManager;
  62. protected GridInfoService m_gridInfoService;
  63. protected IHyperlink HGServices = null;
  64. protected IRegionCreator m_regionCreator;
  65. public void Initialise()
  66. {
  67. m_log.Info("[LOADREGIONS]: " + Name + " cannot be default-initialized!");
  68. throw new PluginNotInitialisedException(Name);
  69. }
  70. public void Initialise(OpenSimBase openSim)
  71. {
  72. m_openSim = openSim;
  73. m_httpServer = openSim.HttpServer;
  74. MainServer.Instance = m_httpServer;
  75. InitialiseCommsManager(openSim);
  76. if (m_commsManager != null)
  77. {
  78. m_openSim.ApplicationRegistry.RegisterInterface<IUserService>(m_commsManager.UserService);
  79. }
  80. }
  81. public void PostInitialise()
  82. {
  83. if (m_openSim.ApplicationRegistry.TryGet<IRegionCreator>(out m_regionCreator))
  84. {
  85. m_regionCreator.OnNewRegionCreated += RegionCreated;
  86. }
  87. }
  88. public void Dispose()
  89. {
  90. }
  91. #endregion
  92. private void RegionCreated(IScene scene)
  93. {
  94. if (m_commsManager != null)
  95. {
  96. scene.RegisterModuleInterface<IUserService>(m_commsManager.UserService);
  97. }
  98. }
  99. protected void InitialiseCommsManager(OpenSimBase openSim)
  100. {
  101. LibraryRootFolder libraryRootFolder = new LibraryRootFolder(m_openSim.ConfigurationSettings.LibrariesXMLFile);
  102. bool hgrid = m_openSim.ConfigSource.Source.Configs["Startup"].GetBoolean("hypergrid", false);
  103. if (hgrid)
  104. {
  105. InitialiseHGServices(openSim, libraryRootFolder);
  106. }
  107. else
  108. {
  109. InitialiseStandardServices(libraryRootFolder);
  110. }
  111. openSim.CommunicationsManager = m_commsManager;
  112. }
  113. protected void InitialiseHGServices(OpenSimBase openSim, LibraryRootFolder libraryRootFolder)
  114. {
  115. // Standalone mode is determined by !startupConfig.GetBoolean("gridmode", false)
  116. if (m_openSim.ConfigurationSettings.Standalone)
  117. {
  118. InitialiseHGStandaloneServices(libraryRootFolder);
  119. }
  120. else
  121. {
  122. // We are in grid mode
  123. InitialiseHGGridServices(libraryRootFolder);
  124. }
  125. HGCommands.HGServices = HGServices;
  126. }
  127. protected void InitialiseStandardServices(LibraryRootFolder libraryRootFolder)
  128. {
  129. // Standalone mode is determined by !startupConfig.GetBoolean("gridmode", false)
  130. if (m_openSim.ConfigurationSettings.Standalone)
  131. {
  132. InitialiseStandaloneServices(libraryRootFolder);
  133. }
  134. else
  135. {
  136. // We are in grid mode
  137. InitialiseGridServices(libraryRootFolder);
  138. }
  139. }
  140. /// <summary>
  141. /// Initialises the backend services for standalone mode, and registers some http handlers
  142. /// </summary>
  143. /// <param name="libraryRootFolder"></param>
  144. protected virtual void InitialiseStandaloneServices(LibraryRootFolder libraryRootFolder)
  145. {
  146. m_commsManager
  147. = new CommunicationsLocal(
  148. m_openSim.ConfigurationSettings, m_openSim.NetServersInfo,
  149. libraryRootFolder);
  150. CreateGridInfoService();
  151. }
  152. protected virtual void InitialiseGridServices(LibraryRootFolder libraryRootFolder)
  153. {
  154. m_commsManager
  155. = new CommunicationsOGS1(m_openSim.NetServersInfo, libraryRootFolder);
  156. m_httpServer.AddStreamHandler(new OpenSim.SimStatusHandler());
  157. m_httpServer.AddStreamHandler(new OpenSim.XSimStatusHandler(m_openSim));
  158. if (m_openSim.userStatsURI != String.Empty)
  159. m_httpServer.AddStreamHandler(new OpenSim.UXSimStatusHandler(m_openSim));
  160. }
  161. protected virtual void InitialiseHGStandaloneServices(LibraryRootFolder libraryRootFolder)
  162. {
  163. HGGridServicesStandalone gridService
  164. = new HGGridServicesStandalone(
  165. m_openSim.NetServersInfo, m_httpServer, m_openSim.SceneManager);
  166. m_commsManager
  167. = new HGCommunicationsStandalone(
  168. m_openSim.ConfigurationSettings, m_openSim.NetServersInfo, m_httpServer,
  169. gridService,
  170. libraryRootFolder, false);
  171. HGServices = gridService;
  172. CreateGridInfoService();
  173. }
  174. protected virtual void InitialiseHGGridServices(LibraryRootFolder libraryRootFolder)
  175. {
  176. m_commsManager
  177. = new HGCommunicationsGridMode(
  178. m_openSim.NetServersInfo,
  179. m_openSim.SceneManager, libraryRootFolder);
  180. HGServices = ((HGCommunicationsGridMode) m_commsManager).HGServices;
  181. m_httpServer.AddStreamHandler(new OpenSim.SimStatusHandler());
  182. m_httpServer.AddStreamHandler(new OpenSim.XSimStatusHandler(m_openSim));
  183. if (m_openSim.userStatsURI != String.Empty)
  184. m_httpServer.AddStreamHandler(new OpenSim.UXSimStatusHandler(m_openSim));
  185. }
  186. private void CreateGridInfoService()
  187. {
  188. // provide grid info
  189. m_gridInfoService = new GridInfoService(m_openSim.ConfigSource.Source);
  190. m_httpServer.AddXmlRPCHandler("get_grid_info", m_gridInfoService.XmlRpcGridInfoMethod);
  191. m_httpServer.AddStreamHandler(
  192. new RestStreamHandler("GET", "/get_grid_info", m_gridInfoService.RestGetGridInfoMethod));
  193. }
  194. }
  195. }