OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
XmlRpcGridRouterModule.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections.Generic;
30 using System.Reflection;
31 
32 using log4net;
33 using Nini.Config;
34 using OpenMetaverse;
35 using Mono.Addins;
36 
37 using OpenSim.Framework;
38 using OpenSim.Framework.Servers;
39 using OpenSim.Framework.Servers.HttpServer;
40 using OpenSim.Framework.Client;
41 using OpenSim.Region.Framework.Interfaces;
42 using OpenSim.Region.Framework.Scenes;
43 
44 namespace OpenSim.Region.OptionalModules.Scripting.XmlRpcGridRouterModule
45 {
46  public class XmlRpcInfo
47  {
48  public UUID item;
49  public UUID channel;
50  public string uri;
51  }
52 
53  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "XmlRpcGridRouter")]
55  {
56  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
57 
58  private Dictionary<UUID, UUID> m_Channels =
59  new Dictionary<UUID, UUID>();
60 
61  private bool m_Enabled = false;
62  private string m_ServerURI = String.Empty;
63 
64  #region INonSharedRegionModule
65 
66  public void Initialise(IConfigSource config)
67  {
68  IConfig startupConfig = config.Configs["XMLRPC"];
69  if (startupConfig == null)
70  return;
71 
72  if (startupConfig.GetString("XmlRpcRouterModule",
73  "XmlRpcRouterModule") == "XmlRpcGridRouterModule")
74  {
75  m_ServerURI = startupConfig.GetString("XmlRpcHubURI", String.Empty);
76  if (m_ServerURI == String.Empty)
77  {
78  m_log.Error("[XMLRPC GRID ROUTER] Module configured but no URI given. Disabling");
79  return;
80  }
81  m_Enabled = true;
82  }
83  }
84 
85  public void AddRegion(Scene scene)
86  {
87  if (!m_Enabled)
88  return;
89 
90  scene.RegisterModuleInterface<IXmlRpcRouter>(this);
91 
92  IScriptModule scriptEngine = scene.RequestModuleInterface<IScriptModule>();
93  if ( scriptEngine != null )
94  {
95  scriptEngine.OnScriptRemoved += this.ScriptRemoved;
96  scriptEngine.OnObjectRemoved += this.ObjectRemoved;
97 
98  }
99  }
100 
101  public void RegionLoaded(Scene scene)
102  {
103  }
104 
105  public void RemoveRegion(Scene scene)
106  {
107  if (!m_Enabled)
108  return;
109 
110  scene.UnregisterModuleInterface<IXmlRpcRouter>(this);
111  }
112 
113  public void Close()
114  {
115  }
116 
117  public string Name
118  {
119  get { return "XmlRpcGridRouterModule"; }
120  }
121 
122  public Type ReplaceableInterface
123  {
124  get { return null; }
125  }
126 
127  #endregion
128 
129  public void RegisterNewReceiver(IScriptModule scriptEngine, UUID channel, UUID objectID, UUID itemID, string uri)
130  {
131  if (!m_Enabled)
132  return;
133 
134  m_log.InfoFormat("[XMLRPC GRID ROUTER]: New receiver Obj: {0} Ch: {1} ID: {2} URI: {3}",
135  objectID.ToString(), channel.ToString(), itemID.ToString(), uri);
136 
137  XmlRpcInfo info = new XmlRpcInfo();
138  info.channel = channel;
139  info.uri = uri;
140  info.item = itemID;
141 
142  bool success = SynchronousRestObjectRequester.MakeRequest<XmlRpcInfo, bool>(
143  "POST", m_ServerURI+"/RegisterChannel/", info);
144 
145  if (!success)
146  {
147  m_log.Error("[XMLRPC GRID ROUTER] Error contacting server");
148  }
149 
150  m_Channels[itemID] = channel;
151 
152  }
153 
154  public void UnRegisterReceiver(string channelID, UUID itemID)
155  {
156  if (!m_Enabled)
157  return;
158 
159  RemoveChannel(itemID);
160 
161  }
162 
163  public void ScriptRemoved(UUID itemID)
164  {
165  if (!m_Enabled)
166  return;
167 
168  RemoveChannel(itemID);
169 
170  }
171 
172  public void ObjectRemoved(UUID objectID)
173  {
174  // m_log.InfoFormat("[XMLRPC GRID ROUTER]: Object Removed {0}",objectID.ToString());
175  }
176 
177  private bool RemoveChannel(UUID itemID)
178  {
179  if(!m_Channels.ContainsKey(itemID))
180  {
181  //m_log.InfoFormat("[XMLRPC GRID ROUTER]: Attempted to unregister non-existing Item: {0}", itemID.ToString());
182  return false;
183  }
184 
185  XmlRpcInfo info = new XmlRpcInfo();
186 
187  info.channel = m_Channels[itemID];
188  info.item = itemID;
189  info.uri = "http://0.0.0.0:00";
190 
191  if (info != null)
192  {
193  bool success = SynchronousRestObjectRequester.MakeRequest<XmlRpcInfo, bool>(
194  "POST", m_ServerURI+"/RemoveChannel/", info);
195 
196  if (!success)
197  {
198  m_log.Error("[XMLRPC GRID ROUTER] Error contacting server");
199  }
200 
201  m_Channels.Remove(itemID);
202  return true;
203  }
204  return false;
205  }
206  }
207 }
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void RegisterNewReceiver(IScriptModule scriptEngine, UUID channel, UUID objectID, UUID itemID, string uri)
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
delegate void ObjectRemoved(UUID prim)
Interactive OpenSim region server
Definition: OpenSim.cs:55
void Initialise(IConfigSource config)
This is called to initialize the region module. For shared modules, this is called exactly once...
delegate void ScriptRemoved(UUID script)