diff options
author | Melanie Thielker | 2009-05-18 11:43:37 +0000 |
---|---|---|
committer | Melanie Thielker | 2009-05-18 11:43:37 +0000 |
commit | cb2ce61876c8953ad56b9eb6dfd79dcd26e8ec40 (patch) | |
tree | 268e2332a35ce9de3cff6ff573f4ad2b807d0d20 /OpenSim/Servers | |
parent | From: Alan Webb <alan_webb@us.ibm.com> (diff) | |
download | opensim-SC-cb2ce61876c8953ad56b9eb6dfd79dcd26e8ec40.zip opensim-SC-cb2ce61876c8953ad56b9eb6dfd79dcd26e8ec40.tar.gz opensim-SC-cb2ce61876c8953ad56b9eb6dfd79dcd26e8ec40.tar.bz2 opensim-SC-cb2ce61876c8953ad56b9eb6dfd79dcd26e8ec40.tar.xz |
Move the connectors under services for reasons of application logic. Remove
the user server skeleton in preparation for introducing a generic server
Diffstat (limited to 'OpenSim/Servers')
-rw-r--r-- | OpenSim/Servers/Base/ServicesServerBase.cs | 5 | ||||
-rw-r--r-- | OpenSim/Servers/Connectors/Asset/AssetServiceConnector.cs | 260 | ||||
-rw-r--r-- | OpenSim/Servers/UserServer/UserServerConnector.cs | 57 | ||||
-rw-r--r-- | OpenSim/Servers/UserServer/UserServerMain.cs | 49 |
4 files changed, 4 insertions, 367 deletions
diff --git a/OpenSim/Servers/Base/ServicesServerBase.cs b/OpenSim/Servers/Base/ServicesServerBase.cs index b090e8c..6129407 100644 --- a/OpenSim/Servers/Base/ServicesServerBase.cs +++ b/OpenSim/Servers/Base/ServicesServerBase.cs | |||
@@ -125,7 +125,10 @@ namespace OpenSim.Servers.Base | |||
125 | 125 | ||
126 | // Refresh the startupConfig post merge | 126 | // Refresh the startupConfig post merge |
127 | // | 127 | // |
128 | startupConfig = argvConfig.Configs["Startup"]; | 128 | if (m_Config.Configs["Startup"] != null) |
129 | { | ||
130 | startupConfig = m_Config.Configs["Startup"]; | ||
131 | } | ||
129 | 132 | ||
130 | // Allow derived classes to load config before the console is | 133 | // Allow derived classes to load config before the console is |
131 | // opened. | 134 | // opened. |
diff --git a/OpenSim/Servers/Connectors/Asset/AssetServiceConnector.cs b/OpenSim/Servers/Connectors/Asset/AssetServiceConnector.cs deleted file mode 100644 index df9507a..0000000 --- a/OpenSim/Servers/Connectors/Asset/AssetServiceConnector.cs +++ /dev/null | |||
@@ -1,260 +0,0 @@ | |||
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 log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | |||
39 | namespace OpenSim.Servers.Connectors | ||
40 | { | ||
41 | public class AssetServicesConnector : IAssetService | ||
42 | { | ||
43 | private static readonly ILog m_log = | ||
44 | LogManager.GetLogger( | ||
45 | MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | private string m_ServerURI = String.Empty; | ||
48 | private IImprovedAssetCache m_Cache = null; | ||
49 | |||
50 | public AssetServicesConnector() | ||
51 | { | ||
52 | } | ||
53 | |||
54 | public AssetServicesConnector(string serverURI) | ||
55 | { | ||
56 | m_ServerURI = serverURI; | ||
57 | } | ||
58 | |||
59 | public AssetServicesConnector(IConfigSource source) | ||
60 | { | ||
61 | Initialise(source); | ||
62 | } | ||
63 | |||
64 | public virtual void Initialise(IConfigSource source) | ||
65 | { | ||
66 | IConfig assetConfig = source.Configs["AssetService"]; | ||
67 | if (assetConfig == null) | ||
68 | { | ||
69 | m_log.Error("[ASSET CONNECTOR]: AssetService missing from OpanSim.ini"); | ||
70 | throw new Exception("Asset connector init error"); | ||
71 | } | ||
72 | |||
73 | string serviceURI = assetConfig.GetString("AssetServerURI", | ||
74 | String.Empty); | ||
75 | |||
76 | if (serviceURI == String.Empty) | ||
77 | { | ||
78 | m_log.Error("[ASSET CONNECTOR]: No Server URI named in section AssetService"); | ||
79 | throw new Exception("Asset connector init error"); | ||
80 | } | ||
81 | m_ServerURI = serviceURI; | ||
82 | } | ||
83 | |||
84 | protected void SetCache(IImprovedAssetCache cache) | ||
85 | { | ||
86 | m_Cache = cache; | ||
87 | } | ||
88 | |||
89 | public AssetBase Get(string id) | ||
90 | { | ||
91 | string uri = m_ServerURI + "/assets/" + id; | ||
92 | |||
93 | AssetBase asset = null; | ||
94 | if (m_Cache != null) | ||
95 | asset = m_Cache.Get(id); | ||
96 | |||
97 | if (asset == null) | ||
98 | { | ||
99 | asset = SynchronousRestObjectRequester. | ||
100 | MakeRequest<int, AssetBase>("GET", uri, 0); | ||
101 | |||
102 | if (m_Cache != null) | ||
103 | m_Cache.Cache(asset); | ||
104 | } | ||
105 | return asset; | ||
106 | } | ||
107 | |||
108 | public AssetMetadata GetMetadata(string id) | ||
109 | { | ||
110 | if (m_Cache != null) | ||
111 | { | ||
112 | AssetBase fullAsset = m_Cache.Get(id); | ||
113 | |||
114 | if (fullAsset != null) | ||
115 | return fullAsset.Metadata; | ||
116 | } | ||
117 | |||
118 | string uri = m_ServerURI + "/assets/" + id + "/metadata"; | ||
119 | |||
120 | AssetMetadata asset = SynchronousRestObjectRequester. | ||
121 | MakeRequest<int, AssetMetadata>("GET", uri, 0); | ||
122 | return asset; | ||
123 | } | ||
124 | |||
125 | public byte[] GetData(string id) | ||
126 | { | ||
127 | if (m_Cache != null) | ||
128 | { | ||
129 | AssetBase fullAsset = m_Cache.Get(id); | ||
130 | |||
131 | if (fullAsset != null) | ||
132 | return fullAsset.Data; | ||
133 | } | ||
134 | |||
135 | RestClient rc = new RestClient(m_ServerURI); | ||
136 | rc.AddResourcePath("assets"); | ||
137 | rc.AddResourcePath(id); | ||
138 | rc.AddResourcePath("data"); | ||
139 | |||
140 | rc.RequestMethod = "GET"; | ||
141 | |||
142 | Stream s = rc.Request(); | ||
143 | |||
144 | if (s == null) | ||
145 | return null; | ||
146 | |||
147 | if (s.Length > 0) | ||
148 | { | ||
149 | byte[] ret = new byte[s.Length]; | ||
150 | s.Read(ret, 0, (int)s.Length); | ||
151 | |||
152 | return ret; | ||
153 | } | ||
154 | |||
155 | return null; | ||
156 | } | ||
157 | |||
158 | public bool Get(string id, Object sender, AssetRetrieved handler) | ||
159 | { | ||
160 | string uri = m_ServerURI + "/assets/" + id; | ||
161 | |||
162 | AssetBase asset = null; | ||
163 | if (m_Cache != null) | ||
164 | asset = m_Cache.Get(id); | ||
165 | |||
166 | if (asset == null) | ||
167 | { | ||
168 | AsynchronousRestObjectRequester. | ||
169 | MakeRequest<int, AssetBase>("GET", uri, 0, | ||
170 | delegate(AssetBase a) | ||
171 | { | ||
172 | if (m_Cache != null) | ||
173 | m_Cache.Cache(a); | ||
174 | handler(id, sender, a); | ||
175 | }); | ||
176 | |||
177 | } | ||
178 | else | ||
179 | { | ||
180 | handler(id, sender, asset); | ||
181 | } | ||
182 | |||
183 | return true; | ||
184 | } | ||
185 | |||
186 | public string Store(AssetBase asset) | ||
187 | { | ||
188 | if (asset.Temporary || asset.Local) | ||
189 | { | ||
190 | if (m_Cache != null) | ||
191 | m_Cache.Cache(asset); | ||
192 | |||
193 | return asset.ID; | ||
194 | } | ||
195 | |||
196 | string uri = m_ServerURI + "/assets/"; | ||
197 | |||
198 | string newID = SynchronousRestObjectRequester. | ||
199 | MakeRequest<AssetBase, string>("POST", uri, asset); | ||
200 | |||
201 | if (newID != String.Empty) | ||
202 | { | ||
203 | // Placing this here, so that this work with old asset servers that don't send any reply back | ||
204 | // SynchronousRestObjectRequester returns somethins that is not an empty string | ||
205 | if (newID != null) | ||
206 | asset.ID = newID; | ||
207 | |||
208 | if (m_Cache != null) | ||
209 | m_Cache.Cache(asset); | ||
210 | } | ||
211 | return newID; | ||
212 | } | ||
213 | |||
214 | public bool UpdateContent(string id, byte[] data) | ||
215 | { | ||
216 | AssetBase asset = null; | ||
217 | |||
218 | if (m_Cache != null) | ||
219 | asset = m_Cache.Get(id); | ||
220 | |||
221 | if (asset == null) | ||
222 | { | ||
223 | AssetMetadata metadata = GetMetadata(id); | ||
224 | if (metadata == null) | ||
225 | return false; | ||
226 | |||
227 | asset = new AssetBase(); | ||
228 | asset.Metadata = metadata; | ||
229 | } | ||
230 | asset.Data = data; | ||
231 | |||
232 | string uri = m_ServerURI + "/assets/" + id; | ||
233 | |||
234 | if (SynchronousRestObjectRequester. | ||
235 | MakeRequest<AssetBase, bool>("POST", uri, asset)) | ||
236 | { | ||
237 | if (m_Cache != null) | ||
238 | m_Cache.Cache(asset); | ||
239 | |||
240 | return true; | ||
241 | } | ||
242 | return false; | ||
243 | } | ||
244 | |||
245 | public bool Delete(string id) | ||
246 | { | ||
247 | string uri = m_ServerURI + "/assets/" + id; | ||
248 | |||
249 | if (SynchronousRestObjectRequester. | ||
250 | MakeRequest<int, bool>("DELETE", uri, 0)) | ||
251 | { | ||
252 | if (m_Cache != null) | ||
253 | m_Cache.Expire(id); | ||
254 | |||
255 | return true; | ||
256 | } | ||
257 | return false; | ||
258 | } | ||
259 | } | ||
260 | } | ||
diff --git a/OpenSim/Servers/UserServer/UserServerConnector.cs b/OpenSim/Servers/UserServer/UserServerConnector.cs deleted file mode 100644 index 15b09bc..0000000 --- a/OpenSim/Servers/UserServer/UserServerConnector.cs +++ /dev/null | |||
@@ -1,57 +0,0 @@ | |||
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 Nini.Config; | ||
30 | using OpenSim.Servers.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | ||
33 | |||
34 | namespace OpenSim.Servers.UserServer | ||
35 | { | ||
36 | public class UserServiceConnector | ||
37 | { | ||
38 | private IUserService m_UserService; | ||
39 | |||
40 | public UserServiceConnector(IConfigSource config, IHttpServer server) | ||
41 | { | ||
42 | IConfig serverConfig = config.Configs["UserService"]; | ||
43 | if (serverConfig == null) | ||
44 | throw new Exception("No section 'Server' in config file"); | ||
45 | |||
46 | string userService = serverConfig.GetString("LocalServiceModule", | ||
47 | String.Empty); | ||
48 | |||
49 | if (userService == String.Empty) | ||
50 | throw new Exception("No UserService in config file"); | ||
51 | |||
52 | Object[] args = new Object[] { config }; | ||
53 | m_UserService = | ||
54 | ServerUtils.LoadPlugin<IUserService>(userService, args); | ||
55 | } | ||
56 | } | ||
57 | } | ||
diff --git a/OpenSim/Servers/UserServer/UserServerMain.cs b/OpenSim/Servers/UserServer/UserServerMain.cs deleted file mode 100644 index 7dea5d7..0000000 --- a/OpenSim/Servers/UserServer/UserServerMain.cs +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
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 OpenSim.Servers.Base; | ||
30 | |||
31 | namespace OpenSim.Servers.UserServer | ||
32 | { | ||
33 | public class UserServer | ||
34 | { | ||
35 | protected static HttpServerBase m_Server = null; | ||
36 | |||
37 | protected static UserServiceConnector m_UserServiceConnector; | ||
38 | |||
39 | static int Main(string[] args) | ||
40 | { | ||
41 | m_Server = new HttpServerBase("User", args); | ||
42 | |||
43 | m_UserServiceConnector = new UserServiceConnector(m_Server.Config, | ||
44 | m_Server.HttpServer); | ||
45 | |||
46 | return m_Server.Run(); | ||
47 | } | ||
48 | } | ||
49 | } | ||