aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/MessagingServer.Modules/InterMessageUserServerModule.cs
diff options
context:
space:
mode:
authorMW2009-02-25 21:00:58 +0000
committerMW2009-02-25 21:00:58 +0000
commit07ee252cf3894125a06c384614a48c1eda73b289 (patch)
tree23d6665e399e031faf7003a1bf2374c4a1166a8a /OpenSim/Grid/MessagingServer.Modules/InterMessageUserServerModule.cs
parent* minor: Remove most mono compiler warnings (diff)
downloadopensim-SC-07ee252cf3894125a06c384614a48c1eda73b289.zip
opensim-SC-07ee252cf3894125a06c384614a48c1eda73b289.tar.gz
opensim-SC-07ee252cf3894125a06c384614a48c1eda73b289.tar.bz2
opensim-SC-07ee252cf3894125a06c384614a48c1eda73b289.tar.xz
Renamed IMessageUserServerService to IInterServiceUserService.cs
Renamed MessageUserServerModule to InterMessageUserServerModule
Diffstat (limited to 'OpenSim/Grid/MessagingServer.Modules/InterMessageUserServerModule.cs')
-rw-r--r--OpenSim/Grid/MessagingServer.Modules/InterMessageUserServerModule.cs186
1 files changed, 186 insertions, 0 deletions
diff --git a/OpenSim/Grid/MessagingServer.Modules/InterMessageUserServerModule.cs b/OpenSim/Grid/MessagingServer.Modules/InterMessageUserServerModule.cs
new file mode 100644
index 0000000..ea7649a
--- /dev/null
+++ b/OpenSim/Grid/MessagingServer.Modules/InterMessageUserServerModule.cs
@@ -0,0 +1,186 @@
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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Net;
32using System.Reflection;
33using System.Threading;
34using System.Timers;
35using log4net;
36using Nwc.XmlRpc;
37using OpenMetaverse;
38using OpenSim.Data;
39using OpenSim.Framework;
40using OpenSim.Grid.Framework;
41using Timer = System.Timers.Timer;
42
43namespace OpenSim.Grid.MessagingServer.Modules
44{
45 public class InterMessageUserServerModule : IInterServiceUserService
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private MessageServerConfig m_cfg;
50
51 private IGridServiceCore m_messageCore;
52
53 private Timer reconnectTimer = new Timer(300000); // 5 mins
54
55 public InterMessageUserServerModule(MessageServerConfig config, IGridServiceCore messageCore)
56 {
57 m_cfg = config;
58 m_messageCore = messageCore;
59
60 reconnectTimer.Elapsed += registerWithUserServer;
61 reconnectTimer.Start();
62 }
63
64 public void Initialise()
65 {
66 m_messageCore.RegisterInterface<IInterServiceUserService>(this);
67 }
68
69 public void PostInitialise()
70 {
71
72 }
73
74 public void RegisterHandlers()
75 {
76 //have these in separate method as some servers restart the http server and reregister all the handlers.
77
78 }
79
80 public void registerWithUserServer(object sender, ElapsedEventArgs e)
81 {
82 registerWithUserServer();
83 }
84
85 public bool registerWithUserServer()
86 {
87 Hashtable UserParams = new Hashtable();
88 // Login / Authentication
89
90 if (m_cfg.HttpSSL)
91 {
92 UserParams["uri"] = "https://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort;
93 }
94 else
95 {
96 UserParams["uri"] = "http://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort;
97 }
98
99 UserParams["recvkey"] = m_cfg.UserRecvKey;
100 UserParams["sendkey"] = m_cfg.UserRecvKey;
101
102 // Package into an XMLRPC Request
103 ArrayList SendParams = new ArrayList();
104 SendParams.Add(UserParams);
105
106 bool success = true;
107 string[] servers = m_cfg.UserServerURL.Split(' ');
108
109 foreach (string srv in servers)
110 {
111 // Send Request
112 try
113 {
114 XmlRpcRequest UserReq = new XmlRpcRequest("register_messageserver", SendParams);
115 XmlRpcResponse UserResp = UserReq.Send(srv, 16000);
116
117 // Process Response
118 Hashtable GridRespData = (Hashtable)UserResp.Value;
119 // if we got a response, we were successful
120 if (!GridRespData.ContainsKey("responsestring"))
121 success = false;
122 else
123 m_log.InfoFormat("[SERVER] Registered with {0}", srv);
124 }
125 catch
126 {
127 m_log.ErrorFormat("Unable to connect to server {0}. Server not running?", srv);
128 success = false;
129 }
130 }
131 return success;
132 }
133
134 public bool deregisterWithUserServer()
135 {
136 Hashtable request = new Hashtable();
137
138 return SendToUserServer(request, "deregister_messageserver");
139 }
140
141 public bool SendToUserServer(Hashtable request, string method)
142 {
143 // Login / Authentication
144
145 if (m_cfg.HttpSSL)
146 {
147 request["uri"] = "https://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort;
148 }
149 else
150 {
151 request["uri"] = "http://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort;
152 }
153
154 request["recvkey"] = m_cfg.UserRecvKey;
155 request["sendkey"] = m_cfg.UserRecvKey;
156
157 // Package into an XMLRPC Request
158 ArrayList SendParams = new ArrayList();
159 SendParams.Add(request);
160
161 bool success = true;
162 string[] servers = m_cfg.UserServerURL.Split(' ');
163
164 // Send Request
165 foreach (string srv in servers)
166 {
167 try
168 {
169 XmlRpcRequest UserReq = new XmlRpcRequest(method, SendParams);
170 XmlRpcResponse UserResp = UserReq.Send(m_cfg.UserServerURL, 16000);
171 // Process Response
172 Hashtable UserRespData = (Hashtable)UserResp.Value;
173 // if we got a response, we were successful
174 if (!UserRespData.ContainsKey("responsestring"))
175 success = false;
176 }
177 catch
178 {
179 m_log.ErrorFormat("Unable to connect to server {0}. Server not running?", srv);
180 success = false;
181 }
182 }
183 return success;
184 }
185 }
186}