CreateCommsManagerPlugin.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 IRegionCreator m_regionCreator;
  64. public void Initialise()
  65. {
  66. m_log.Info("[LOADREGIONS]: " + Name + " cannot be default-initialized!");
  67. throw new PluginNotInitialisedException(Name);
  68. }
  69. public void Initialise(OpenSimBase openSim)
  70. {
  71. m_openSim = openSim;
  72. m_httpServer = openSim.HttpServer;
  73. MainServer.Instance = m_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. }
  125. protected void InitialiseStandardServices(LibraryRootFolder libraryRootFolder)
  126. {
  127. // Standalone mode is determined by !startupConfig.GetBoolean("gridmode", false)
  128. if (m_openSim.ConfigurationSettings.Standalone)
  129. {
  130. InitialiseStandaloneServices(libraryRootFolder);
  131. }
  132. else
  133. {
  134. // We are in grid mode
  135. InitialiseGridServices(libraryRootFolder);
  136. }
  137. }
  138. /// <summary>
  139. /// Initialises the backend services for standalone mode, and registers some http handlers
  140. /// </summary>
  141. /// <param name="libraryRootFolder"></param>
  142. protected virtual void InitialiseStandaloneServices(LibraryRootFolder libraryRootFolder)
  143. {
  144. m_commsManager
  145. = new CommunicationsLocal(
  146. m_openSim.ConfigurationSettings, m_openSim.NetServersInfo,
  147. libraryRootFolder);
  148. CreateGridInfoService();
  149. }
  150. protected virtual void InitialiseGridServices(LibraryRootFolder libraryRootFolder)
  151. {
  152. m_commsManager
  153. = new CommunicationsOGS1(m_openSim.NetServersInfo, libraryRootFolder);
  154. m_httpServer.AddStreamHandler(new OpenSim.SimStatusHandler());
  155. m_httpServer.AddStreamHandler(new OpenSim.XSimStatusHandler(m_openSim));
  156. if (m_openSim.userStatsURI != String.Empty)
  157. m_httpServer.AddStreamHandler(new OpenSim.UXSimStatusHandler(m_openSim));
  158. }
  159. protected virtual void InitialiseHGStandaloneServices(LibraryRootFolder libraryRootFolder)
  160. {
  161. m_commsManager
  162. = new HGCommunicationsStandalone(
  163. m_openSim.ConfigurationSettings, m_openSim.NetServersInfo, m_httpServer,
  164. libraryRootFolder, false);
  165. CreateGridInfoService();
  166. }
  167. protected virtual void InitialiseHGGridServices(LibraryRootFolder libraryRootFolder)
  168. {
  169. m_commsManager
  170. = new HGCommunicationsGridMode(
  171. m_openSim.NetServersInfo,
  172. m_openSim.SceneManager, libraryRootFolder);
  173. m_httpServer.AddStreamHandler(new OpenSim.SimStatusHandler());
  174. m_httpServer.AddStreamHandler(new OpenSim.XSimStatusHandler(m_openSim));
  175. if (m_openSim.userStatsURI != String.Empty)
  176. m_httpServer.AddStreamHandler(new OpenSim.UXSimStatusHandler(m_openSim));
  177. }
  178. private void CreateGridInfoService()
  179. {
  180. // provide grid info
  181. m_gridInfoService = new GridInfoService(m_openSim.ConfigSource.Source);
  182. m_httpServer.AddXmlRPCHandler("get_grid_info", m_gridInfoService.XmlRpcGridInfoMethod);
  183. m_httpServer.AddStreamHandler(
  184. new RestStreamHandler("GET", "/get_grid_info", m_gridInfoService.RestGetGridInfoMethod));
  185. }
  186. }
  187. }