diff options
author | Justin Clarke Casey | 2008-08-16 20:42:43 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2008-08-16 20:42:43 +0000 |
commit | 992b04a23e19d3e5a4f88169ce33c9b2ddb4f4de (patch) | |
tree | d816d9da2663ab3f26380d4ac52daae61948cf25 /OpenSim/Framework | |
parent | * minor: rip out userserver stress project which never got filled out (diff) | |
download | opensim-SC-992b04a23e19d3e5a4f88169ce33c9b2ddb4f4de.zip opensim-SC-992b04a23e19d3e5a4f88169ce33c9b2ddb4f4de.tar.gz opensim-SC-992b04a23e19d3e5a4f88169ce33c9b2ddb4f4de.tar.bz2 opensim-SC-992b04a23e19d3e5a4f88169ce33c9b2ddb4f4de.tar.xz |
* Move GridInfoService into Framework.Communications and eliminate Common.Communications for now (since this was the only class in that project)
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/Communications/GridInfoService.cs | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/OpenSim/Framework/Communications/GridInfoService.cs b/OpenSim/Framework/Communications/GridInfoService.cs new file mode 100644 index 0000000..d51bc59 --- /dev/null +++ b/OpenSim/Framework/Communications/GridInfoService.cs | |||
@@ -0,0 +1,155 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using log4net; | ||
34 | using Nini.Config; | ||
35 | using Nwc.XmlRpc; | ||
36 | using OpenSim.Framework.Servers; | ||
37 | using OpenSim.Framework; | ||
38 | |||
39 | namespace OpenSim.Framework.Communications | ||
40 | { | ||
41 | public class GridInfoService | ||
42 | { | ||
43 | private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | private Hashtable _info = new Hashtable(); | ||
46 | |||
47 | /// <summary> | ||
48 | /// Instantiate a GridInfoService object. | ||
49 | /// </summary> | ||
50 | /// <param name="configPath">path to config path containing | ||
51 | /// grid information</param> | ||
52 | /// <remarks> | ||
53 | /// GridInfoService uses the [GridInfo] section of the | ||
54 | /// standard OpenSim.ini file --- which is not optimal, but | ||
55 | /// anything else requires a general redesign of the config | ||
56 | /// system. | ||
57 | /// </remarks> | ||
58 | public GridInfoService(string configPath) | ||
59 | { | ||
60 | _info["platform"] = "OpenSim"; | ||
61 | if (File.Exists(configPath)) | ||
62 | { | ||
63 | try | ||
64 | { | ||
65 | IConfigSource _configSource = new IniConfigSource(configPath); | ||
66 | IConfig startupCfg = _configSource.Configs["Startup"]; | ||
67 | IConfig gridCfg = _configSource.Configs["GridInfo"]; | ||
68 | IConfig netCfg = _configSource.Configs["Network"]; | ||
69 | |||
70 | bool grid = startupCfg.GetBoolean("gridmode", false); | ||
71 | |||
72 | if (grid) | ||
73 | _info["mode"] = "grid"; | ||
74 | else | ||
75 | _info["mode"] = "standalone"; | ||
76 | |||
77 | |||
78 | if (null != gridCfg) | ||
79 | { | ||
80 | foreach (string k in gridCfg.GetKeys()) | ||
81 | { | ||
82 | _info[k] = gridCfg.GetString(k); | ||
83 | } | ||
84 | } | ||
85 | else if (null != netCfg) | ||
86 | { | ||
87 | if (grid) | ||
88 | _info["login"] = netCfg.GetString("user_server_url"); | ||
89 | else | ||
90 | _info["login"] = String.Format("http://127.0.0.1:{0}/", netCfg.GetString("http_listener_port")); | ||
91 | IssueWarning(); | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | _info["login"] = "http://127.0.0.1:9000/"; | ||
96 | IssueWarning(); | ||
97 | } | ||
98 | } | ||
99 | catch (Exception) | ||
100 | { | ||
101 | _log.DebugFormat("[GridInfoService] cannot get grid info from {0}, using minimal defaults", configPath); | ||
102 | } | ||
103 | } | ||
104 | _log.InfoFormat("[GridInfoService] Grid info service initialized with {0} keys", _info.Count); | ||
105 | } | ||
106 | |||
107 | /// <summary> | ||
108 | /// Default constructor, uses OpenSim.ini. | ||
109 | /// </summary> | ||
110 | public GridInfoService() : this(Path.Combine(Util.configDir(), "OpenSim.ini")) | ||
111 | { | ||
112 | } | ||
113 | |||
114 | private void IssueWarning() | ||
115 | { | ||
116 | _log.Warn("[GridInfoService] found no [GridInfo] section in your OpenSim.ini"); | ||
117 | _log.Warn("[GridInfoService] trying to guess sensible defaults, you might want to provide better ones:"); | ||
118 | foreach (string k in _info.Keys) | ||
119 | { | ||
120 | _log.WarnFormat("[GridInfoService] {0}: {1}", k, _info[k]); | ||
121 | } | ||
122 | } | ||
123 | |||
124 | public XmlRpcResponse XmlRpcGridInfoMethod(XmlRpcRequest request) | ||
125 | { | ||
126 | XmlRpcResponse response = new XmlRpcResponse(); | ||
127 | Hashtable responseData = new Hashtable(); | ||
128 | |||
129 | _log.Info("[GridInfo]: Request for grid info"); | ||
130 | |||
131 | foreach (string k in _info.Keys) | ||
132 | { | ||
133 | responseData[k] = _info[k]; | ||
134 | } | ||
135 | response.Value = responseData; | ||
136 | |||
137 | return response; | ||
138 | } | ||
139 | |||
140 | public string RestGetGridInfoMethod(string request, string path, string param, | ||
141 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
142 | { | ||
143 | StringBuilder sb = new StringBuilder(); | ||
144 | |||
145 | sb.Append("<gridinfo>\n"); | ||
146 | foreach (string k in _info.Keys) | ||
147 | { | ||
148 | sb.AppendFormat("<{0}>{1}</{0}>\n", k, _info[k]); | ||
149 | } | ||
150 | sb.Append("</gridinfo>\n"); | ||
151 | |||
152 | return sb.ToString(); | ||
153 | } | ||
154 | } | ||
155 | } | ||