aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs
diff options
context:
space:
mode:
authorMelanie Thielker2009-05-10 14:03:06 +0000
committerMelanie Thielker2009-05-10 14:03:06 +0000
commit1a910b6e1dbace70b27581c51148a8732b46de79 (patch)
treec13e58aa932b0db95ca895cd0ff1275c0014ca9f /OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs
parentAdd some asset cache plumbing. Change the generic cache from UUID to string (diff)
downloadopensim-SC_OLD-1a910b6e1dbace70b27581c51148a8732b46de79.zip
opensim-SC_OLD-1a910b6e1dbace70b27581c51148a8732b46de79.tar.gz
opensim-SC_OLD-1a910b6e1dbace70b27581c51148a8732b46de79.tar.bz2
opensim-SC_OLD-1a910b6e1dbace70b27581c51148a8732b46de79.tar.xz
Connect up the new asset cache and introduce an asynchronous call path
for asset retrieval (full asset only) to ease migration to the new system
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs100
1 files changed, 83 insertions, 17 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs
index 835678d..667840f 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectors/Asset/RemoteAssetServiceConnector.cs
@@ -49,8 +49,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
49 49
50 private bool m_Enabled = false; 50 private bool m_Enabled = false;
51 private string m_ServerURI = String.Empty; 51 private string m_ServerURI = String.Empty;
52 private Dictionary<Scene, IImprovedAssetCache> m_AssetCache = 52 private IImprovedAssetCache m_Cache = null;
53 new Dictionary<Scene, IImprovedAssetCache>();
54 53
55 public string Name 54 public string Name
56 { 55 {
@@ -106,10 +105,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
106 105
107 public void RemoveRegion(Scene scene) 106 public void RemoveRegion(Scene scene)
108 { 107 {
109 if (!m_Enabled)
110 return;
111
112 m_AssetCache.Remove(scene);
113 } 108 }
114 109
115 public void RegionLoaded(Scene scene) 110 public void RegionLoaded(Scene scene)
@@ -117,12 +112,20 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
117 if (!m_Enabled) 112 if (!m_Enabled)
118 return; 113 return;
119 114
120 m_AssetCache[scene] = 115 if (m_Cache == null)
121 scene.RequestModuleInterface<IImprovedAssetCache>(); 116 {
117 m_Cache = scene.RequestModuleInterface<IImprovedAssetCache>();
118
119 // Since we are a shared module and scene data is not
120 // available for every method, the cache must be shared, too
121 //
122 if (!(m_Cache is ISharedRegionModule))
123 m_Cache = null;
124 }
122 125
123 m_log.InfoFormat("[ASSET CONNECTOR]: Enabled remote assets for region {0}", scene.RegionInfo.RegionName); 126 m_log.InfoFormat("[ASSET CONNECTOR]: Enabled remote assets for region {0}", scene.RegionInfo.RegionName);
124 127
125 if (m_AssetCache[scene] != null) 128 if (m_Cache != null)
126 { 129 {
127 m_log.InfoFormat("[ASSET CONNECTOR]: Enabled asset caching for region {0}", scene.RegionInfo.RegionName); 130 m_log.InfoFormat("[ASSET CONNECTOR]: Enabled asset caching for region {0}", scene.RegionInfo.RegionName);
128 } 131 }
@@ -132,13 +135,31 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
132 { 135 {
133 string uri = m_ServerURI + "/assets/" + id; 136 string uri = m_ServerURI + "/assets/" + id;
134 137
135 AssetBase asset = SynchronousRestObjectPoster. 138 AssetBase asset = null;
136 BeginPostObject<int, AssetBase>("GET", uri, 0); 139 if (m_Cache != null)
140 asset = m_Cache.Get(id);
141
142 if (asset == null)
143 {
144 asset = SynchronousRestObjectPoster.
145 BeginPostObject<int, AssetBase>("GET", uri, 0);
146
147 if (m_Cache != null)
148 m_Cache.Cache(asset);
149 }
137 return asset; 150 return asset;
138 } 151 }
139 152
140 public AssetMetadata GetMetadata(string id) 153 public AssetMetadata GetMetadata(string id)
141 { 154 {
155 if (m_Cache != null)
156 {
157 AssetBase fullAsset = m_Cache.Get(id);
158
159 if (fullAsset != null)
160 return fullAsset.Metadata;
161 }
162
142 string uri = m_ServerURI + "/assets/" + id + "/metadata"; 163 string uri = m_ServerURI + "/assets/" + id + "/metadata";
143 164
144 AssetMetadata asset = SynchronousRestObjectPoster. 165 AssetMetadata asset = SynchronousRestObjectPoster.
@@ -148,6 +169,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
148 169
149 public byte[] GetData(string id) 170 public byte[] GetData(string id)
150 { 171 {
172 if (m_Cache != null)
173 {
174 AssetBase fullAsset = m_Cache.Get(id);
175
176 if (fullAsset != null)
177 return fullAsset.Data;
178 }
179
151 RestClient rc = new RestClient(m_ServerURI); 180 RestClient rc = new RestClient(m_ServerURI);
152 rc.AddResourcePath("assets"); 181 rc.AddResourcePath("assets");
153 rc.AddResourcePath(id); 182 rc.AddResourcePath(id);
@@ -171,33 +200,70 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
171 return null; 200 return null;
172 } 201 }
173 202
203 public bool Get(string id, Object sender, AssetRetrieved handler)
204 {
205 AssetBase asset = Get(id);
206 handler(id, sender, asset);
207 return true;
208 }
174 public string Store(AssetBase asset) 209 public string Store(AssetBase asset)
175 { 210 {
176 string uri = m_ServerURI + "/assets/"; 211 string uri = m_ServerURI + "/assets/";
177 212
178 string newID = SynchronousRestObjectPoster. 213 string newID = SynchronousRestObjectPoster.
179 BeginPostObject<AssetBase, string>("POST", uri, asset); 214 BeginPostObject<AssetBase, string>("POST", uri, asset);
215
216 if (newID != String.Empty)
217 {
218 if (m_Cache != null)
219 m_Cache.Cache(asset);
220 }
180 return newID; 221 return newID;
181 } 222 }
182 223
183 public bool UpdateContent(string id, byte[] data) 224 public bool UpdateContent(string id, byte[] data)
184 { 225 {
185 AssetBase asset = new AssetBase(); 226 AssetBase asset = null;
186 asset.ID = id; 227
228 if (m_Cache != null)
229 asset = m_Cache.Get(id);
230
231 if (asset == null)
232 {
233 AssetMetadata metadata = GetMetadata(id);
234 if (metadata == null)
235 return false;
236
237 asset = new AssetBase();
238 asset.Metadata = metadata;
239 }
187 asset.Data = data; 240 asset.Data = data;
188 241
189 string uri = m_ServerURI + "/assets/" + id; 242 string uri = m_ServerURI + "/assets/" + id;
190 243
191 return SynchronousRestObjectPoster. 244 if (SynchronousRestObjectPoster.
192 BeginPostObject<AssetBase, bool>("POST", uri, asset); 245 BeginPostObject<AssetBase, bool>("POST", uri, asset))
246 {
247 if (m_Cache != null)
248 m_Cache.Cache(asset);
249
250 return true;
251 }
252 return false;
193 } 253 }
194 254
195 public bool Delete(string id) 255 public bool Delete(string id)
196 { 256 {
197 string uri = m_ServerURI + "/assets/" + id; 257 string uri = m_ServerURI + "/assets/" + id;
198 258
199 return SynchronousRestObjectPoster. 259 if (SynchronousRestObjectPoster.
200 BeginPostObject<int, bool>("DELETE", uri, 0); 260 BeginPostObject<int, bool>("DELETE", uri, 0))
261 {
262 if (m_Cache != null)
263 m_Cache.Expire(id);
264
265 return true;
266 }
201 return false; 267 return false;
202 } 268 }
203 } 269 }