From 39f340e6875c55927fc9dbeb51af2357c7d28c04 Mon Sep 17 00:00:00 2001 From: Johan Berntsson Date: Mon, 24 Mar 2008 01:37:00 +0000 Subject: [PATCH] XmlRpcCommand refactoring --- OpenSim/Framework/Util.cs | 13 +++++++ OpenSim/Grid/GridServer/GridServerBase.cs | 2 +- OpenSim/Region/Application/OpenSimMain.cs | 37 +------------------ .../3Di/LoadBalancer/LoadBalancerPlugin.cs | 30 +++++++-------- 4 files changed, 31 insertions(+), 51 deletions(-) diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 6c95c8804d..a184f8989f 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -35,6 +35,7 @@ using System.Security.Cryptography; using System.Text; using libsecondlife; using Nini.Config; +using Nwc.XmlRpc; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; @@ -605,5 +606,17 @@ namespace OpenSim.Framework } return returnstring; } + + static public XmlRpcResponse XmlRpcCommand(string url, string methodName, params object[] args) + { + return SendXmlRpcCommand(url, methodName, args); + } + + static public XmlRpcResponse SendXmlRpcCommand(string url, string methodName, object[] args) + { + XmlRpcRequest client = new XmlRpcRequest(methodName, args); + return client.Send(url, 6000); + } + } } diff --git a/OpenSim/Grid/GridServer/GridServerBase.cs b/OpenSim/Grid/GridServer/GridServerBase.cs index c29924ba2f..acefe3f34e 100644 --- a/OpenSim/Grid/GridServer/GridServerBase.cs +++ b/OpenSim/Grid/GridServer/GridServerBase.cs @@ -48,7 +48,7 @@ namespace OpenSim.Grid.GridServer protected BaseHttpServer httpServer; protected List m_plugins = new List(); - public BaseHttpServer + public BaseHttpServer HttpServer { get { return httpServer; } } diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs index aa5a432a83..35f146dd63 100644 --- a/OpenSim/Region/Application/OpenSimMain.cs +++ b/OpenSim/Region/Application/OpenSimMain.cs @@ -461,7 +461,7 @@ namespace OpenSim { // set proxy url to RegionInfo regionInfo.proxyUrl = proxyUrl; - ProxyCommand(proxyUrl, "AddPort", port, port + proxyOffset, regionInfo.ExternalHostName); + Util.XmlRpcCommand(proxyUrl, "AddPort", port, port + proxyOffset, regionInfo.ExternalHostName); } UDPServer udpServer; @@ -618,7 +618,7 @@ namespace OpenSim /// public virtual void Shutdown() { - ProxyCommand(proxyUrl, "Stop"); + Util.XmlRpcCommand(proxyUrl, "Stop"); if (m_startupCommandsFile != String.Empty) { @@ -1200,39 +1200,6 @@ namespace OpenSim #endregion - // TODO: remove me!! (almost same as XmlRpcCommand) - public object ProxyCommand(string url, string methodName, params object[] args) - { - if(proxyUrl.Length==0) return null; - return SendXmlRpcCommand(url, methodName, args); - } - - public object XmlRpcCommand(uint port, string methodName, params object[] args) - { - return SendXmlRpcCommand("http://localhost:"+port, methodName, args); - } - - public object XmlRpcCommand(string url, string methodName, params object[] args) - { - return SendXmlRpcCommand(url, methodName, args); - } - - private object SendXmlRpcCommand(string url, string methodName, object[] args) - { - try { - //MainLog.Instance.Verbose("XMLRPC", "Sending command {0} to {1}", methodName, url); - XmlRpcRequest client = new XmlRpcRequest(methodName, args); - //MainLog.Instance.Verbose("XMLRPC", client.ToString()); - XmlRpcResponse response = client.Send(url, 6000); - if(!response.IsFault) return response.Value; - } - catch(Exception e) - { - m_log.ErrorFormat("XMLRPC Failed to send command {0} to {1}: {2}", methodName, url, e.Message); - } - return null; - } - /// /// Get the start time and up time of Region server /// diff --git a/ThirdParty/3Di/LoadBalancer/LoadBalancerPlugin.cs b/ThirdParty/3Di/LoadBalancer/LoadBalancerPlugin.cs index 325385a71c..b552d62747 100644 --- a/ThirdParty/3Di/LoadBalancer/LoadBalancerPlugin.cs +++ b/ThirdParty/3Di/LoadBalancer/LoadBalancerPlugin.cs @@ -296,7 +296,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer return; } - simMain.ProxyCommand(src_region.proxyUrl, "BlockClientMessages", src_url, src_port + proxyOffset); + Util.XmlRpcCommand(src_region.proxyUrl, "BlockClientMessages", src_url, src_port + proxyOffset); // serialization of origin region's data SerializeRegion(src_region, serializeDir); @@ -313,8 +313,8 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer // import the source region's data dst_region = DeserializeRegion(dst_port, true, serializeDir); - simMain.ProxyCommand(dst_region.proxyUrl, "ChangeRegion", src_port + proxyOffset, src_url, dst_port + proxyOffset, dst_url); - simMain.ProxyCommand(dst_region.proxyUrl, "UnblockClientMessages", dst_url, dst_port + proxyOffset); + Util.XmlRpcCommand(dst_region.proxyUrl, "ChangeRegion", src_port + proxyOffset, src_url, dst_port + proxyOffset, dst_url); + Util.XmlRpcCommand(dst_region.proxyUrl, "UnblockClientMessages", dst_url, dst_port + proxyOffset); } private void DeserializeRegion_Clone(int src_port, int dst_port, string src_url, string dst_url) @@ -331,11 +331,11 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer // Decide who is in charge for each section int[] port = new int[] { src_port, dst_port }; string[] url = new string[] { "http://" + src_url + ":" + commandServer.Port, "http://" + dst_url + ":" + commandServer.Port }; - for(int i=0; i<2; i++) simMain.XmlRpcCommand(url[i], "SplitRegion", i, 2, port[0], port[1], url[0], url[1]); + for(int i=0; i<2; i++) Util.XmlRpcCommand(url[i], "SplitRegion", i, 2, port[0], port[1], url[0], url[1]); // Enable the proxy - simMain.ProxyCommand(dst_region.proxyUrl, "AddRegion", src_port + proxyOffset, src_url, dst_port + proxyOffset, dst_url); - simMain.ProxyCommand(dst_region.proxyUrl, "UnblockClientMessages", dst_url, dst_port + proxyOffset); + Util.XmlRpcCommand(dst_region.proxyUrl, "AddRegion", src_port + proxyOffset, src_url, dst_port + proxyOffset, dst_url); + Util.XmlRpcCommand(dst_region.proxyUrl, "UnblockClientMessages", dst_url, dst_port + proxyOffset); } private void TerminateRegion(object param) @@ -758,7 +758,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer ++i; } } - + scene.splitID = myID; scene.SynchronizeScene = new Scene.SynchronizeSceneHandler(SynchronizeScenes); isSplit = true; @@ -789,7 +789,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer RegionInfo region = SearchRegionFromPortNum(src_port); - simMain.ProxyCommand(region.proxyUrl, "BlockClientMessages", src_url, src_port + proxyOffset); + Util.XmlRpcCommand(region.proxyUrl, "BlockClientMessages", src_url, src_port + proxyOffset); Scene scene; if (sceneManager.TryGetScene(region.RegionID, out scene)) @@ -815,12 +815,12 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer for(int i=1; i