aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJohn Hurliman2010-04-05 14:52:25 -0700
committerJohn Hurliman2010-04-05 14:52:25 -0700
commitf302224cafa9ffe8f47cce2274022e1ee2ed37d6 (patch)
tree3a8337e5b26c80cc94eb61572f4d60ae5534a40a
parentcheck group membership and powers with the groups module rather than just the... (diff)
downloadopensim-SC_OLD-f302224cafa9ffe8f47cce2274022e1ee2ed37d6.zip
opensim-SC_OLD-f302224cafa9ffe8f47cce2274022e1ee2ed37d6.tar.gz
opensim-SC_OLD-f302224cafa9ffe8f47cce2274022e1ee2ed37d6.tar.bz2
opensim-SC_OLD-f302224cafa9ffe8f47cce2274022e1ee2ed37d6.tar.xz
* In the async asset fetch method, cache check before firing any async code. This should alleviate some "thread storm" issues when regions are starting up that hit Mono especially hard
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs109
1 files changed, 62 insertions, 47 deletions
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs
index 27434ad..4a7522f 100644
--- a/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianAssetServiceConnector.cs
@@ -112,59 +112,15 @@ namespace OpenSim.Services.Connectors.SimianGrid
112 112
113 public AssetBase Get(string id) 113 public AssetBase Get(string id)
114 { 114 {
115 AssetBase asset = null;
116
117 // Cache fetch 115 // Cache fetch
118 if (m_cache != null) 116 if (m_cache != null)
119 { 117 {
120 asset = m_cache.Get(id); 118 AssetBase asset = m_cache.Get(id);
121 if (asset != null) 119 if (asset != null)
122 return asset; 120 return asset;
123 } 121 }
124 122
125 Uri url; 123 return GetRemote(id);
126
127 // Determine if id is an absolute URL or a grid-relative UUID
128 if (!Uri.TryCreate(id, UriKind.Absolute, out url))
129 url = new Uri(m_serverUrl + id);
130
131 try
132 {
133 HttpWebRequest request = UntrustedHttpWebRequest.Create(url);
134
135 using (WebResponse response = request.GetResponse())
136 {
137 using (Stream responseStream = response.GetResponseStream())
138 {
139 string creatorID = response.Headers.GetOne("X-Asset-Creator-Id") ?? String.Empty;
140
141 // Create the asset object
142 asset = new AssetBase(id, String.Empty, SLUtil.ContentTypeToSLAssetType(response.ContentType), creatorID);
143
144 UUID assetID;
145 if (UUID.TryParse(id, out assetID))
146 asset.FullID = assetID;
147
148 // Grab the asset data from the response stream
149 using (MemoryStream stream = new MemoryStream())
150 {
151 responseStream.CopyTo(stream, Int32.MaxValue);
152 asset.Data = stream.ToArray();
153 }
154 }
155 }
156
157 // Cache store
158 if (m_cache != null && asset != null)
159 m_cache.Cache(asset);
160
161 return asset;
162 }
163 catch (Exception ex)
164 {
165 m_log.Warn("[SIMIAN ASSET CONNECTOR]: Asset GET from " + url + " failed: " + ex.Message);
166 return null;
167 }
168 } 124 }
169 125
170 /// <summary> 126 /// <summary>
@@ -245,10 +201,21 @@ namespace OpenSim.Services.Connectors.SimianGrid
245 /// <returns>True if the id was parseable, false otherwise</returns> 201 /// <returns>True if the id was parseable, false otherwise</returns>
246 public bool Get(string id, Object sender, AssetRetrieved handler) 202 public bool Get(string id, Object sender, AssetRetrieved handler)
247 { 203 {
204 // Cache fetch
205 if (m_cache != null)
206 {
207 AssetBase asset = m_cache.Get(id);
208 if (asset != null)
209 {
210 Util.FireAndForget(delegate(object o) { handler(id, sender, asset); });
211 return true;
212 }
213 }
214
248 Util.FireAndForget( 215 Util.FireAndForget(
249 delegate(object o) 216 delegate(object o)
250 { 217 {
251 AssetBase asset = Get(id); 218 AssetBase asset = GetRemote(id);
252 handler(id, sender, asset); 219 handler(id, sender, asset);
253 } 220 }
254 ); 221 );
@@ -406,5 +373,53 @@ namespace OpenSim.Services.Connectors.SimianGrid
406 } 373 }
407 374
408 #endregion IAssetService 375 #endregion IAssetService
376
377 private AssetBase GetRemote(string id)
378 {
379 AssetBase asset = null;
380 Uri url;
381
382 // Determine if id is an absolute URL or a grid-relative UUID
383 if (!Uri.TryCreate(id, UriKind.Absolute, out url))
384 url = new Uri(m_serverUrl + id);
385
386 try
387 {
388 HttpWebRequest request = UntrustedHttpWebRequest.Create(url);
389
390 using (WebResponse response = request.GetResponse())
391 {
392 using (Stream responseStream = response.GetResponseStream())
393 {
394 string creatorID = response.Headers.GetOne("X-Asset-Creator-Id") ?? String.Empty;
395
396 // Create the asset object
397 asset = new AssetBase(id, String.Empty, SLUtil.ContentTypeToSLAssetType(response.ContentType), creatorID);
398
399 UUID assetID;
400 if (UUID.TryParse(id, out assetID))
401 asset.FullID = assetID;
402
403 // Grab the asset data from the response stream
404 using (MemoryStream stream = new MemoryStream())
405 {
406 responseStream.CopyTo(stream, Int32.MaxValue);
407 asset.Data = stream.ToArray();
408 }
409 }
410 }
411
412 // Cache store
413 if (m_cache != null && asset != null)
414 m_cache.Cache(asset);
415
416 return asset;
417 }
418 catch (Exception ex)
419 {
420 m_log.Warn("[SIMIAN ASSET CONNECTOR]: Asset GET from " + url + " failed: " + ex.Message);
421 return null;
422 }
423 }
409 } 424 }
410} 425}