GridMessagingModule.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using System.Text;
  32. using Nwc.XmlRpc;
  33. using log4net;
  34. using OpenSim.Data;
  35. using OpenSim.Framework.Servers;
  36. using OpenSim.Framework.Servers.HttpServer;
  37. using OpenSim.Framework;
  38. using OpenSim.Grid.Framework;
  39. namespace OpenSim.Grid.GridServer.Modules
  40. {
  41. public class GridMessagingModule : IMessagingServerDiscovery
  42. {
  43. //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  44. protected IRegionProfileService m_gridDBService;
  45. protected IGridServiceCore m_gridCore;
  46. protected GridConfig m_config;
  47. /// <value>
  48. /// Used to notify old regions as to which OpenSim version to upgrade to
  49. /// </value>
  50. //private string m_opensimVersion;
  51. protected BaseHttpServer m_httpServer;
  52. // This is here so that the grid server can hand out MessageServer settings to regions on registration
  53. private List<MessageServerInfo> m_messageServers = new List<MessageServerInfo>();
  54. public GridMessagingModule()
  55. {
  56. }
  57. public void Initialise(string opensimVersion, IRegionProfileService gridDBService, IGridServiceCore gridCore, GridConfig config)
  58. {
  59. //m_opensimVersion = opensimVersion;
  60. m_gridDBService = gridDBService;
  61. m_gridCore = gridCore;
  62. m_config = config;
  63. m_gridCore.RegisterInterface<IMessagingServerDiscovery>(this);
  64. RegisterHandlers();
  65. }
  66. public void PostInitialise()
  67. {
  68. }
  69. public void RegisterHandlers()
  70. {
  71. //have these in separate method as some servers restart the http server and reregister all the handlers.
  72. m_httpServer = m_gridCore.GetHttpServer();
  73. // Message Server ---> Grid Server
  74. m_httpServer.AddXmlRPCHandler("register_messageserver", XmlRPCRegisterMessageServer);
  75. m_httpServer.AddXmlRPCHandler("deregister_messageserver", XmlRPCDeRegisterMessageServer);
  76. }
  77. public List<MessageServerInfo> GetMessageServersList()
  78. {
  79. lock (m_messageServers)
  80. {
  81. return new List<MessageServerInfo>(m_messageServers);
  82. }
  83. }
  84. public XmlRpcResponse XmlRPCRegisterMessageServer(XmlRpcRequest request)
  85. {
  86. XmlRpcResponse response = new XmlRpcResponse();
  87. Hashtable requestData = (Hashtable)request.Params[0];
  88. Hashtable responseData = new Hashtable();
  89. if (requestData.Contains("uri"))
  90. {
  91. string URI = (string)requestData["URI"];
  92. string sendkey = (string)requestData["sendkey"];
  93. string recvkey = (string)requestData["recvkey"];
  94. MessageServerInfo m = new MessageServerInfo();
  95. m.URI = URI;
  96. m.sendkey = sendkey;
  97. m.recvkey = recvkey;
  98. RegisterMessageServer(m);
  99. responseData["responsestring"] = "TRUE";
  100. response.Value = responseData;
  101. }
  102. return response;
  103. }
  104. public XmlRpcResponse XmlRPCDeRegisterMessageServer(XmlRpcRequest request)
  105. {
  106. XmlRpcResponse response = new XmlRpcResponse();
  107. Hashtable requestData = (Hashtable)request.Params[0];
  108. Hashtable responseData = new Hashtable();
  109. if (requestData.Contains("uri"))
  110. {
  111. string URI = (string)requestData["uri"];
  112. string sendkey = (string)requestData["sendkey"];
  113. string recvkey = (string)requestData["recvkey"];
  114. MessageServerInfo m = new MessageServerInfo();
  115. m.URI = URI;
  116. m.sendkey = sendkey;
  117. m.recvkey = recvkey;
  118. DeRegisterMessageServer(m);
  119. responseData["responsestring"] = "TRUE";
  120. response.Value = responseData;
  121. }
  122. return response;
  123. }
  124. public void RegisterMessageServer(MessageServerInfo m)
  125. {
  126. lock (m_messageServers)
  127. {
  128. if (!m_messageServers.Contains(m))
  129. m_messageServers.Add(m);
  130. }
  131. }
  132. public void DeRegisterMessageServer(MessageServerInfo m)
  133. {
  134. lock (m_messageServers)
  135. {
  136. if (m_messageServers.Contains(m))
  137. m_messageServers.Remove(m);
  138. }
  139. }
  140. }
  141. }