First step in giving the messaging server the modular refactoring treatment. As with the other two servers, this is very much a work in progress.

GenericGridServerConcept
MW 2009-02-22 19:19:24 +00:00
parent 648f55ed11
commit f3a24e432f
8 changed files with 644 additions and 290 deletions

View File

@ -0,0 +1,11 @@
using System;
using OpenSim.Data;
namespace OpenSim.Grid.MessagingServer
{
public interface IMessageRegionService
{
int ClearRegionCache();
RegionProfileData GetRegionInfo(ulong regionhandle);
}
}

View File

@ -0,0 +1,8 @@
using System;
namespace OpenSim.Grid.MessagingServer
{
public interface IMessageUserServerService
{
bool SendToUserServer(System.Collections.Hashtable request, string method);
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
using OpenSim.Framework.Servers;
namespace OpenSim.Grid.MessagingServer
{
public interface IUGAIMCore
{
T Get<T>();
void RegisterInterface<T>(T iface);
bool TryGet<T>(out T iface);
BaseHttpServer GetHttpServer();
}
}

View File

@ -26,6 +26,7 @@
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using log4net;
@ -38,13 +39,18 @@ namespace OpenSim.Grid.MessagingServer
{
/// <summary>
/// </summary>
public class OpenMessage_Main : BaseOpenSimServer
public class OpenMessage_Main : BaseOpenSimServer , IUGAIMCore
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private MessageServerConfig Cfg;
private MessageService msgsvc;
private MessageRegionModule m_regionModule;
private MessageUserServerModule m_userServerModule;
private UserDataBaseService m_userDataBaseService;
// private UUID m_lastCreatedUser = UUID.Random();
public static void Main(string[] args)
@ -77,7 +83,7 @@ namespace OpenSim.Grid.MessagingServer
private void registerWithUserServer()
{
if (msgsvc.registerWithUserServer())
if (m_userServerModule.registerWithUserServer())
{
m_log.Info("[SERVER]: Starting HTTP process");
m_httpServer = new BaseHttpServer(Cfg.HttpPort);
@ -85,12 +91,13 @@ namespace OpenSim.Grid.MessagingServer
m_httpServer.AddXmlRPCHandler("login_to_simulator", msgsvc.UserLoggedOn);
m_httpServer.AddXmlRPCHandler("logout_of_simulator", msgsvc.UserLoggedOff);
m_httpServer.AddXmlRPCHandler("get_presence_info_bulk", msgsvc.GetPresenceInfoBulk);
m_httpServer.AddXmlRPCHandler("region_startup", msgsvc.RegionStartup);
m_httpServer.AddXmlRPCHandler("region_shutdown", msgsvc.RegionShutdown);
m_httpServer.AddXmlRPCHandler("process_region_shutdown", msgsvc.ProcessRegionShutdown);
m_httpServer.AddXmlRPCHandler("agent_location", msgsvc.AgentLocation);
m_httpServer.AddXmlRPCHandler("agent_leaving", msgsvc.AgentLeaving);
m_httpServer.AddXmlRPCHandler("region_startup", m_regionModule.RegionStartup);
m_httpServer.AddXmlRPCHandler("region_shutdown", m_regionModule.RegionShutdown);
m_httpServer.Start();
m_log.Info("[SERVER]: Userserver registration was successful");
}
@ -103,7 +110,7 @@ namespace OpenSim.Grid.MessagingServer
private void deregisterFromUserServer()
{
msgsvc.deregisterWithUserServer();
m_userServerModule.deregisterWithUserServer();
if (m_httpServer != null)
{
// try a completely fresh registration, with fresh handlers, too
@ -117,9 +124,24 @@ namespace OpenSim.Grid.MessagingServer
{
Cfg = new MessageServerConfig("MESSAGING SERVER", (Path.Combine(Util.configDir(), "MessagingServer_Config.xml")));
msgsvc = new MessageService(Cfg);
m_userDataBaseService = new UserDataBaseService();
m_userDataBaseService.AddPlugin(Cfg.DatabaseProvider, Cfg.DatabaseConnect);
m_userServerModule = new MessageUserServerModule(Cfg, this);
m_userServerModule.Initialise();
msgsvc = new MessageService(Cfg, this, m_userDataBaseService);
msgsvc.Initialise();
m_regionModule = new MessageRegionModule(Cfg, this);
m_regionModule.Initialise();
registerWithUserServer();
m_userServerModule.PostInitialise();
msgsvc.PostInitialise();
m_regionModule.PostInitialise();
m_log.Info("[SERVER]: Messageserver 0.5 - Startup complete");
base.StartupSpecific();
@ -135,35 +157,35 @@ namespace OpenSim.Grid.MessagingServer
public void do_create(string what)
{
switch (what)
{
case "user":
try
{
//userID =
//m_userManager.AddUserProfile(tempfirstname, templastname, tempMD5Passwd, regX, regY);
} catch (Exception ex)
{
m_console.Error("[SERVER]: Error creating user: {0}", ex.ToString());
}
//switch (what)
//{
// case "user":
// try
// {
// //userID =
// //m_userManager.AddUserProfile(tempfirstname, templastname, tempMD5Passwd, regX, regY);
// } catch (Exception ex)
// {
// m_console.Error("[SERVER]: Error creating user: {0}", ex.ToString());
// }
try
{
//RestObjectPoster.BeginPostObject<Guid>(m_userManager._config.InventoryUrl + "CreateInventory/",
//userID.Guid);
}
catch (Exception ex)
{
m_console.Error("[SERVER]: Error creating inventory for user: {0}", ex.ToString());
}
// m_lastCreatedUser = userID;
break;
}
// try
// {
// //RestObjectPoster.BeginPostObject<Guid>(m_userManager._config.InventoryUrl + "CreateInventory/",
// //userID.Guid);
// }
// catch (Exception ex)
// {
// m_console.Error("[SERVER]: Error creating inventory for user: {0}", ex.ToString());
// }
// // m_lastCreatedUser = userID;
// break;
//}
}
private void HandleClearCache(string module, string[] cmd)
{
int entries = msgsvc.ClearRegionCache();
int entries = m_regionModule.ClearRegionCache();
m_console.Notice("Region cache cleared! Cleared " +
entries.ToString() + " entries");
}
@ -176,7 +198,48 @@ namespace OpenSim.Grid.MessagingServer
public override void ShutdownSpecific()
{
msgsvc.deregisterWithUserServer();
m_userServerModule.deregisterWithUserServer();
}
#region IUGAIMCore
private readonly Dictionary<Type, object> m_moduleInterfaces = new Dictionary<Type, object>();
/// <summary>
/// Register an Module interface.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="iface"></param>
public void RegisterInterface<T>(T iface)
{
lock (m_moduleInterfaces)
{
if (!m_moduleInterfaces.ContainsKey(typeof(T)))
{
m_moduleInterfaces.Add(typeof(T), iface);
}
}
}
public bool TryGet<T>(out T iface)
{
if (m_moduleInterfaces.ContainsKey(typeof(T)))
{
iface = (T)m_moduleInterfaces[typeof(T)];
return true;
}
iface = default(T);
return false;
}
public T Get<T>()
{
return (T)m_moduleInterfaces[typeof(T)];
}
public BaseHttpServer GetHttpServer()
{
return m_httpServer;
}
#endregion
}
}

View File

@ -0,0 +1,212 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Reflection;
using System.Threading;
using System.Timers;
using log4net;
using Nwc.XmlRpc;
using OpenMetaverse;
using OpenSim.Data;
using OpenSim.Framework;
using Timer = System.Timers.Timer;
namespace OpenSim.Grid.MessagingServer
{
public class MessageRegionModule : IMessageRegionService
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private MessageServerConfig m_cfg;
private IMessageUserServerService m_userServerModule;
private IUGAIMCore m_messageCore;
// a dictionary of all current regions this server knows about
private Dictionary<ulong, RegionProfileData> m_regionInfoCache = new Dictionary<ulong, RegionProfileData>();
public MessageRegionModule(MessageServerConfig config, IUGAIMCore messageCore)
{
m_cfg = config;
m_messageCore = messageCore;
}
public void Initialise()
{
m_messageCore.RegisterInterface<IMessageRegionService>(this);
}
public void PostInitialise()
{
IMessageUserServerService messageUserServer;
if (m_messageCore.TryGet<IMessageUserServerService>(out messageUserServer))
{
m_userServerModule = messageUserServer;
}
}
public void RegisterHandlers()
{
//have these in separate method as some servers restart the http server and reregister all the handlers.
}
/// <summary>
/// Gets and caches a RegionInfo object from the gridserver based on regionhandle
/// if the regionhandle is already cached, use the cached values
/// Gets called by lots of threads!!!!!
/// </summary>
/// <param name="regionhandle">handle to the XY of the region we're looking for</param>
/// <returns>A RegionInfo object to stick in the presence info</returns>
public RegionProfileData GetRegionInfo(ulong regionhandle)
{
RegionProfileData regionInfo = null;
lock (m_regionInfoCache)
{
m_regionInfoCache.TryGetValue(regionhandle, out regionInfo);
}
if (regionInfo == null) // not found in cache
{
regionInfo = RequestRegionInfo(regionhandle);
if (regionInfo != null) // lookup was successful
{
lock (m_regionInfoCache)
{
m_regionInfoCache[regionhandle] = regionInfo;
}
}
}
return regionInfo;
}
public int ClearRegionCache()
{
int cachecount = 0;
lock (m_regionInfoCache)
{
cachecount = m_regionInfoCache.Count;
m_regionInfoCache.Clear();
}
return cachecount;
}
/// <summary>
/// Get RegionProfileData from the GridServer.
/// We'll cache this information in GetRegionInfo and use it for presence updates
/// </summary>
/// <param name="regionHandle"></param>
/// <returns></returns>
public RegionProfileData RequestRegionInfo(ulong regionHandle)
{
RegionProfileData regionProfile = null;
try
{
Hashtable requestData = new Hashtable();
requestData["region_handle"] = regionHandle.ToString();
requestData["authkey"] = m_cfg.GridSendKey;
ArrayList SendParams = new ArrayList();
SendParams.Add(requestData);
XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
XmlRpcResponse GridResp = GridReq.Send(m_cfg.GridServerURL, 3000);
Hashtable responseData = (Hashtable)GridResp.Value;
if (responseData.ContainsKey("error"))
{
m_log.Error("[GRID]: error received from grid server" + responseData["error"]);
return null;
}
uint regX = Convert.ToUInt32((string)responseData["region_locx"]);
uint regY = Convert.ToUInt32((string)responseData["region_locy"]);
string internalIpStr = (string)responseData["sim_ip"];
regionProfile = new RegionProfileData();
regionProfile.httpPort = (uint)Convert.ToInt32((string)responseData["http_port"]);
regionProfile.httpServerURI = "http://" + internalIpStr + ":" + regionProfile.httpPort + "/";
regionProfile.regionHandle = Utils.UIntsToLong((regX * Constants.RegionSize), (regY * Constants.RegionSize));
regionProfile.regionLocX = regX;
regionProfile.regionLocY = regY;
regionProfile.remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]);
regionProfile.UUID = new UUID((string)responseData["region_UUID"]);
regionProfile.regionName = (string)responseData["region_name"];
}
catch (WebException)
{
m_log.Error("[GRID]: " +
"Region lookup failed for: " + regionHandle.ToString() +
" - Is the GridServer down?");
}
return regionProfile;
}
public XmlRpcResponse RegionStartup(XmlRpcRequest request)
{
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable result = new Hashtable();
result["success"] = "FALSE";
if (m_userServerModule.SendToUserServer(requestData, "region_startup"))
result["success"] = "TRUE";
XmlRpcResponse response = new XmlRpcResponse();
response.Value = result;
return response;
}
public XmlRpcResponse RegionShutdown(XmlRpcRequest request)
{
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable result = new Hashtable();
result["success"] = "FALSE";
if (m_userServerModule.SendToUserServer(requestData, "region_shutdown"))
result["success"] = "TRUE";
XmlRpcResponse response = new XmlRpcResponse();
response.Value = result;
return response;
}
}
}

View File

@ -46,30 +46,53 @@ namespace OpenSim.Grid.MessagingServer
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private MessageServerConfig m_cfg;
private UserManager m_userManager;
private UserDataBaseService m_userDataBaseService;
private IUGAIMCore m_messageCore;
private IMessageUserServerService m_userServerModule;
private IMessageRegionService m_regionModule;
// a dictionary of all current presences this server knows about
private Dictionary<UUID, UserPresenceData> m_presences = new Dictionary<UUID,UserPresenceData>();
// a dictionary of all current regions this server knows about
private Dictionary<ulong, RegionProfileData> m_regionInfoCache = new Dictionary<ulong,RegionProfileData>();
private Timer reconnectTimer = new Timer(300000); // 5 mins
public MessageService(MessageServerConfig cfg)
public MessageService(MessageServerConfig cfg, IUGAIMCore messageCore, UserDataBaseService userDataBaseService)
{
m_cfg = cfg;
m_userManager = new UserManager();
m_messageCore = messageCore;
m_userDataBaseService = userDataBaseService;
//???
UserConfig uc = new UserConfig();
uc.DatabaseConnect = cfg.DatabaseConnect;
uc.DatabaseProvider = cfg.DatabaseProvider;
m_userManager.AddPlugin(cfg.DatabaseProvider, cfg.DatabaseConnect);
reconnectTimer.Elapsed += registerWithUserServer;
reconnectTimer.Start();
}
public void Initialise()
{
}
public void PostInitialise()
{
IMessageUserServerService messageUserServer;
if (m_messageCore.TryGet<IMessageUserServerService>(out messageUserServer))
{
m_userServerModule = messageUserServer;
}
IMessageRegionService messageRegion;
if (m_messageCore.TryGet<IMessageRegionService>(out messageRegion))
{
m_regionModule = messageRegion;
}
}
public void RegisterHandlers()
{
//have these in separate method as some servers restart the http server and reregister all the handlers.
}
#region FriendList Methods
@ -107,7 +130,7 @@ namespace OpenSim.Grid.MessagingServer
/// <param name="receiver">We are sending the presence update to this user</param>
private void enqueuePresenceUpdate(UserPresenceData talkingAbout, UserPresenceData receiver)
{
UserAgentData p2Handle = m_userManager.GetUserAgentData(receiver.agentData.AgentID);
UserAgentData p2Handle = m_userDataBaseService.GetUserAgentData(receiver.agentData.AgentID);
if (p2Handle != null)
{
if (receiver.lookupUserRegionYN)
@ -122,7 +145,7 @@ namespace OpenSim.Grid.MessagingServer
PresenceInformer friendlistupdater = new PresenceInformer();
friendlistupdater.presence1 = talkingAbout;
friendlistupdater.presence2 = receiver;
friendlistupdater.OnGetRegionData += GetRegionInfo;
friendlistupdater.OnGetRegionData += m_regionModule.GetRegionInfo;
friendlistupdater.OnDone += PresenceUpdateDone;
WaitCallback cb = new WaitCallback(friendlistupdater.go);
ThreadPool.QueueUserWorkItem(cb);
@ -225,7 +248,7 @@ namespace OpenSim.Grid.MessagingServer
private void PresenceUpdateDone(PresenceInformer obj)
{
obj.OnGetRegionData -= GetRegionInfo;
obj.OnGetRegionData -= m_regionModule.GetRegionInfo;
obj.OnDone -= PresenceUpdateDone;
}
@ -332,7 +355,7 @@ namespace OpenSim.Grid.MessagingServer
UserPresenceData up = new UserPresenceData();
up.agentData = agentData;
up.friendData = GetUserFriendList(agentData.AgentID);
up.regionData = GetRegionInfo(regionHandle);
up.regionData = m_regionModule.GetRegionInfo(regionHandle);
up.OnlineYN = true;
up.lookupUserRegionYN = false;
ProcessFriendListSubscriptions(up);
@ -380,7 +403,7 @@ namespace OpenSim.Grid.MessagingServer
}
try {
Dictionary<UUID, FriendRegionInfo> infos = m_userManager.GetFriendRegionInfos(uuids);
Dictionary<UUID, FriendRegionInfo> infos = m_userDataBaseService.GetFriendRegionInfos(uuids);
m_log.DebugFormat("[FRIEND]: Got {0} region entries back.", infos.Count);
int count = 0;
foreach (KeyValuePair<UUID, FriendRegionInfo> pair in infos)
@ -402,251 +425,13 @@ namespace OpenSim.Grid.MessagingServer
}
}
#region regioninfo gathering
/// <summary>
/// Gets and caches a RegionInfo object from the gridserver based on regionhandle
/// if the regionhandle is already cached, use the cached values
/// Gets called by lots of threads!!!!!
/// </summary>
/// <param name="regionhandle">handle to the XY of the region we're looking for</param>
/// <returns>A RegionInfo object to stick in the presence info</returns>
public RegionProfileData GetRegionInfo(ulong regionhandle)
{
RegionProfileData regionInfo = null;
lock (m_regionInfoCache)
{
m_regionInfoCache.TryGetValue(regionhandle, out regionInfo);
}
if (regionInfo == null) // not found in cache
{
regionInfo = RequestRegionInfo(regionhandle);
if (regionInfo != null) // lookup was successful
{
lock (m_regionInfoCache)
{
m_regionInfoCache[regionhandle] = regionInfo;
}
}
}
return regionInfo;
}
public int ClearRegionCache()
{
int cachecount = 0;
lock (m_regionInfoCache)
{
cachecount = m_regionInfoCache.Count;
m_regionInfoCache.Clear();
}
return cachecount;
}
/// <summary>
/// Get RegionProfileData from the GridServer.
/// We'll cache this information in GetRegionInfo and use it for presence updates
/// </summary>
/// <param name="regionHandle"></param>
/// <returns></returns>
public RegionProfileData RequestRegionInfo(ulong regionHandle)
{
RegionProfileData regionProfile = null;
try
{
Hashtable requestData = new Hashtable();
requestData["region_handle"] = regionHandle.ToString();
requestData["authkey"] = m_cfg.GridSendKey;
ArrayList SendParams = new ArrayList();
SendParams.Add(requestData);
XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
XmlRpcResponse GridResp = GridReq.Send(m_cfg.GridServerURL, 3000);
Hashtable responseData = (Hashtable)GridResp.Value;
if (responseData.ContainsKey("error"))
{
m_log.Error("[GRID]: error received from grid server" + responseData["error"]);
return null;
}
uint regX = Convert.ToUInt32((string)responseData["region_locx"]);
uint regY = Convert.ToUInt32((string)responseData["region_locy"]);
string internalIpStr = (string)responseData["sim_ip"];
regionProfile = new RegionProfileData();
regionProfile.httpPort = (uint)Convert.ToInt32((string)responseData["http_port"]);
regionProfile.httpServerURI = "http://" + internalIpStr + ":" + regionProfile.httpPort + "/";
regionProfile.regionHandle = Utils.UIntsToLong((regX * Constants.RegionSize), (regY * Constants.RegionSize));
regionProfile.regionLocX = regX;
regionProfile.regionLocY = regY;
regionProfile.remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]);
regionProfile.UUID = new UUID((string)responseData["region_UUID"]);
regionProfile.regionName = (string)responseData["region_name"];
}
catch (WebException)
{
m_log.Error("[GRID]: " +
"Region lookup failed for: " + regionHandle.ToString() +
" - Is the GridServer down?");
}
return regionProfile;
}
public void registerWithUserServer(object sender, ElapsedEventArgs e)
{
registerWithUserServer();
}
public bool registerWithUserServer ()
{
Hashtable UserParams = new Hashtable();
// Login / Authentication
if (m_cfg.HttpSSL)
{
UserParams["uri"] = "https://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort;
}
else
{
UserParams["uri"] = "http://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort;
}
UserParams["recvkey"] = m_cfg.UserRecvKey;
UserParams["sendkey"] = m_cfg.UserRecvKey;
// Package into an XMLRPC Request
ArrayList SendParams = new ArrayList();
SendParams.Add(UserParams);
bool success = true;
string[] servers = m_cfg.UserServerURL.Split(' ');
foreach (string srv in servers)
{
// Send Request
try
{
XmlRpcRequest UserReq = new XmlRpcRequest("register_messageserver", SendParams);
XmlRpcResponse UserResp = UserReq.Send(srv, 16000);
// Process Response
Hashtable GridRespData = (Hashtable)UserResp.Value;
// if we got a response, we were successful
if (!GridRespData.ContainsKey("responsestring"))
success = false;
else
m_log.InfoFormat("[SERVER] Registered with {0}", srv);
}
catch
{
m_log.ErrorFormat("Unable to connect to server {0}. Server not running?", srv);
success = false;
}
}
return success;
}
public bool deregisterWithUserServer()
{
Hashtable request = new Hashtable();
return SendToUserServer(request, "deregister_messageserver");
}
public bool SendToUserServer(Hashtable request, string method)
{
// Login / Authentication
if (m_cfg.HttpSSL)
{
request["uri"] = "https://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort;
}
else
{
request["uri"] = "http://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort;
}
request["recvkey"] = m_cfg.UserRecvKey;
request["sendkey"] = m_cfg.UserRecvKey;
// Package into an XMLRPC Request
ArrayList SendParams = new ArrayList();
SendParams.Add(request);
bool success = true;
string[] servers = m_cfg.UserServerURL.Split(' ');
// Send Request
foreach (string srv in servers)
{
try
{
XmlRpcRequest UserReq = new XmlRpcRequest(method, SendParams);
XmlRpcResponse UserResp = UserReq.Send(m_cfg.UserServerURL, 16000);
// Process Response
Hashtable UserRespData = (Hashtable)UserResp.Value;
// if we got a response, we were successful
if (!UserRespData.ContainsKey("responsestring"))
success = false;
}
catch
{
m_log.ErrorFormat("Unable to connect to server {0}. Server not running?", srv);
success = false;
}
}
return success;
}
#endregion
public XmlRpcResponse RegionStartup(XmlRpcRequest request)
{
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable result = new Hashtable();
result["success"] = "FALSE";
if (SendToUserServer(requestData, "region_startup"))
result["success"] = "TRUE";
XmlRpcResponse response = new XmlRpcResponse();
response.Value = result;
return response;
}
public XmlRpcResponse RegionShutdown(XmlRpcRequest request)
{
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable result = new Hashtable();
result["success"] = "FALSE";
if (SendToUserServer(requestData, "region_shutdown"))
result["success"] = "TRUE";
XmlRpcResponse response = new XmlRpcResponse();
response.Value = result;
return response;
}
public XmlRpcResponse AgentLocation(XmlRpcRequest request)
{
Hashtable requestData = (Hashtable)request.Params[0];
Hashtable result = new Hashtable();
result["success"] = "FALSE";
if (SendToUserServer(requestData, "agent_location"))
if (m_userServerModule.SendToUserServer(requestData, "agent_location"))
result["success"] = "TRUE";
@ -661,7 +446,7 @@ namespace OpenSim.Grid.MessagingServer
Hashtable result = new Hashtable();
result["success"] = "FALSE";
if (SendToUserServer(requestData, "agent_leaving"))
if (m_userServerModule.SendToUserServer(requestData, "agent_leaving"))
result["success"] = "TRUE";
XmlRpcResponse response = new XmlRpcResponse();
@ -699,4 +484,4 @@ namespace OpenSim.Grid.MessagingServer
return response;
}
}
}
}

View File

@ -0,0 +1,185 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Reflection;
using System.Threading;
using System.Timers;
using log4net;
using Nwc.XmlRpc;
using OpenMetaverse;
using OpenSim.Data;
using OpenSim.Framework;
using Timer = System.Timers.Timer;
namespace OpenSim.Grid.MessagingServer
{
public class MessageUserServerModule : IMessageUserServerService
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private MessageServerConfig m_cfg;
private IUGAIMCore m_messageCore;
private Timer reconnectTimer = new Timer(300000); // 5 mins
public MessageUserServerModule(MessageServerConfig config, IUGAIMCore messageCore)
{
m_cfg = config;
m_messageCore = messageCore;
reconnectTimer.Elapsed += registerWithUserServer;
reconnectTimer.Start();
}
public void Initialise()
{
m_messageCore.RegisterInterface<IMessageUserServerService>(this);
}
public void PostInitialise()
{
}
public void RegisterHandlers()
{
//have these in separate method as some servers restart the http server and reregister all the handlers.
}
public void registerWithUserServer(object sender, ElapsedEventArgs e)
{
registerWithUserServer();
}
public bool registerWithUserServer()
{
Hashtable UserParams = new Hashtable();
// Login / Authentication
if (m_cfg.HttpSSL)
{
UserParams["uri"] = "https://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort;
}
else
{
UserParams["uri"] = "http://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort;
}
UserParams["recvkey"] = m_cfg.UserRecvKey;
UserParams["sendkey"] = m_cfg.UserRecvKey;
// Package into an XMLRPC Request
ArrayList SendParams = new ArrayList();
SendParams.Add(UserParams);
bool success = true;
string[] servers = m_cfg.UserServerURL.Split(' ');
foreach (string srv in servers)
{
// Send Request
try
{
XmlRpcRequest UserReq = new XmlRpcRequest("register_messageserver", SendParams);
XmlRpcResponse UserResp = UserReq.Send(srv, 16000);
// Process Response
Hashtable GridRespData = (Hashtable)UserResp.Value;
// if we got a response, we were successful
if (!GridRespData.ContainsKey("responsestring"))
success = false;
else
m_log.InfoFormat("[SERVER] Registered with {0}", srv);
}
catch
{
m_log.ErrorFormat("Unable to connect to server {0}. Server not running?", srv);
success = false;
}
}
return success;
}
public bool deregisterWithUserServer()
{
Hashtable request = new Hashtable();
return SendToUserServer(request, "deregister_messageserver");
}
public bool SendToUserServer(Hashtable request, string method)
{
// Login / Authentication
if (m_cfg.HttpSSL)
{
request["uri"] = "https://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort;
}
else
{
request["uri"] = "http://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort;
}
request["recvkey"] = m_cfg.UserRecvKey;
request["sendkey"] = m_cfg.UserRecvKey;
// Package into an XMLRPC Request
ArrayList SendParams = new ArrayList();
SendParams.Add(request);
bool success = true;
string[] servers = m_cfg.UserServerURL.Split(' ');
// Send Request
foreach (string srv in servers)
{
try
{
XmlRpcRequest UserReq = new XmlRpcRequest(method, SendParams);
XmlRpcResponse UserResp = UserReq.Send(m_cfg.UserServerURL, 16000);
// Process Response
Hashtable UserRespData = (Hashtable)UserResp.Value;
// if we got a response, we were successful
if (!UserRespData.ContainsKey("responsestring"))
success = false;
}
catch
{
m_log.ErrorFormat("Unable to connect to server {0}. Server not running?", srv);
success = false;
}
}
return success;
}
}
}

View File

@ -0,0 +1,75 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Framework.Communications;
namespace OpenSim.Grid.MessagingServer
{
public class UserDataBaseService : UserManagerBase
{
/// <summary>
/// Constructor.
/// </summary>
/// Passing null to parent because we never use any function that requires an interservice inventory call.
public UserDataBaseService()
: base(null)
{
}
public UserAgentData GetUserAgentData(UUID AgentID)
{
UserProfileData userProfile = GetUserProfile(AgentID);
if (userProfile != null)
{
return userProfile.CurrentAgent;
}
return null;
}
public override UserProfileData SetupMasterUser(string firstName, string lastName)
{
//throw new Exception("The method or operation is not implemented.");
return null;
}
public override UserProfileData SetupMasterUser(string firstName, string lastName, string password)
{
//throw new Exception("The method or operation is not implemented.");
return null;
}
public override UserProfileData SetupMasterUser(UUID uuid)
{
//throw new Exception("The method or operation is not implemented.");
return null;
}
}
}