CreateCommsManagerPlugin.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 OpenSim 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. InitialiseCommsManager(openSim);
  75. if (m_commsManager != null)
  76. {
  77. m_openSim.ApplicationRegistry.RegisterInterface<IUserService>(m_commsManager.UserService);
  78. }
  79. }
  80. public void PostInitialise()
  81. {
  82. if (m_openSim.ApplicationRegistry.TryGet<IRegionCreator>(out m_regionCreator))
  83. {
  84. m_regionCreator.OnNewRegionCreated += RegionCreated;
  85. }
  86. }
  87. public void Dispose()
  88. {
  89. }
  90. #endregion
  91. private void RegionCreated(IScene scene)
  92. {
  93. if (m_commsManager != null)
  94. {
  95. scene.RegisterModuleInterface<IUserService>(m_commsManager.UserService);
  96. }
  97. }
  98. protected void InitialiseCommsManager(OpenSimBase openSim)
  99. {
  100. LibraryRootFolder libraryRootFolder = new LibraryRootFolder(m_openSim.ConfigurationSettings.LibrariesXMLFile);
  101. bool hgrid = m_openSim.ConfigSource.Source.Configs["Startup"].GetBoolean("hypergrid", false);
  102. if (hgrid)
  103. {
  104. InitialiseHGServices(openSim, libraryRootFolder);
  105. }
  106. else
  107. {
  108. InitialiseStandardServices(libraryRootFolder);
  109. }
  110. openSim.CommunicationsManager = m_commsManager;
  111. }
  112. protected void InitialiseHGServices(OpenSimBase openSim, LibraryRootFolder libraryRootFolder)
  113. {
  114. // Standalone mode is determined by !startupConfig.GetBoolean("gridmode", false)
  115. if (m_openSim.ConfigurationSettings.Standalone)
  116. {
  117. InitialiseHGStandaloneServices(libraryRootFolder);
  118. }
  119. else
  120. {
  121. // We are in grid mode
  122. InitialiseHGGridServices(libraryRootFolder);
  123. }
  124. HGCommands.HGServices = HGServices;
  125. }
  126. protected void InitialiseStandardServices(LibraryRootFolder libraryRootFolder)
  127. {
  128. // Standalone mode is determined by !startupConfig.GetBoolean("gridmode", false)
  129. if (m_openSim.ConfigurationSettings.Standalone)
  130. {
  131. InitialiseStandaloneServices(libraryRootFolder);
  132. }
  133. else
  134. {
  135. // We are in grid mode
  136. InitialiseGridServices(libraryRootFolder);
  137. }
  138. }
  139. /// <summary>
  140. /// Initialises the backend services for standalone mode, and registers some http handlers
  141. /// </summary>
  142. /// <param name="libraryRootFolder"></param>
  143. protected virtual void InitialiseStandaloneServices(LibraryRootFolder libraryRootFolder)
  144. {
  145. m_commsManager
  146. = new CommunicationsLocal(
  147. m_openSim.ConfigurationSettings, m_openSim.NetServersInfo, m_httpServer, m_openSim.AssetCache,
  148. libraryRootFolder, m_openSim.ConfigurationSettings.DumpAssetsToFile);
  149. CreateGridInfoService();
  150. }
  151. protected virtual void InitialiseGridServices(LibraryRootFolder libraryRootFolder)
  152. {
  153. m_commsManager
  154. = new CommunicationsOGS1(m_openSim.NetServersInfo, m_httpServer, m_openSim.AssetCache, libraryRootFolder);
  155. m_httpServer.AddStreamHandler(new OpenSim.SimStatusHandler());
  156. m_httpServer.AddStreamHandler(new OpenSim.XSimStatusHandler(m_openSim));
  157. if (m_openSim.userStatsURI != String.Empty )
  158. m_httpServer.AddStreamHandler(new OpenSim.UXSimStatusHandler(m_openSim));
  159. }
  160. protected virtual void InitialiseHGStandaloneServices(LibraryRootFolder libraryRootFolder)
  161. {
  162. HGGridServicesStandalone gridService
  163. = new HGGridServicesStandalone(
  164. m_openSim.NetServersInfo, m_httpServer, m_openSim.AssetCache, m_openSim.SceneManager);
  165. m_commsManager
  166. = new HGCommunicationsStandalone(
  167. m_openSim.ConfigurationSettings, m_openSim.NetServersInfo, m_httpServer, m_openSim.AssetCache,
  168. gridService,
  169. libraryRootFolder, m_openSim.ConfigurationSettings.DumpAssetsToFile);
  170. HGServices = gridService;
  171. CreateGridInfoService();
  172. }
  173. protected virtual void InitialiseHGGridServices(LibraryRootFolder libraryRootFolder)
  174. {
  175. m_commsManager
  176. = new HGCommunicationsGridMode(
  177. m_openSim.NetServersInfo, m_httpServer,
  178. m_openSim.AssetCache, m_openSim.SceneManager, libraryRootFolder);
  179. HGServices = ((HGCommunicationsGridMode) m_commsManager).HGServices;
  180. m_httpServer.AddStreamHandler(new OpenSim.SimStatusHandler());
  181. m_httpServer.AddStreamHandler(new OpenSim.XSimStatusHandler(m_openSim));
  182. if (m_openSim.userStatsURI != String.Empty )
  183. m_httpServer.AddStreamHandler(new OpenSim.UXSimStatusHandler(m_openSim));
  184. }
  185. private void CreateGridInfoService()
  186. {
  187. // provide grid info
  188. m_gridInfoService = new GridInfoService(m_openSim.ConfigSource.Source);
  189. m_httpServer.AddXmlRPCHandler("get_grid_info", m_gridInfoService.XmlRpcGridInfoMethod);
  190. m_httpServer.AddStreamHandler(
  191. new RestStreamHandler("GET", "/get_grid_info", m_gridInfoService.RestGetGridInfoMethod));
  192. }
  193. }
  194. }