1
0

GridMessagingModule.cs 6.1 KB

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