aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectors/Asset/LocalAssetServiceConnector.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectors/Asset/LocalAssetServiceConnector.cs120
1 files changed, 106 insertions, 14 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectors/Asset/LocalAssetServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectors/Asset/LocalAssetServiceConnector.cs
index 0a0f634..6f0a7f8 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectors/Asset/LocalAssetServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectors/Asset/LocalAssetServiceConnector.cs
@@ -30,6 +30,7 @@ using Nini.Config;
30using System; 30using System;
31using System.Collections.Generic; 31using System.Collections.Generic;
32using System.Reflection; 32using System.Reflection;
33using OpenSim.Framework;
33using OpenSim.Servers.Base; 34using OpenSim.Servers.Base;
34using OpenSim.Region.Framework.Interfaces; 35using OpenSim.Region.Framework.Interfaces;
35using OpenSim.Region.Framework.Scenes; 36using OpenSim.Region.Framework.Scenes;
@@ -37,14 +38,14 @@ using OpenSim.Services.Interfaces;
37 38
38namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset 39namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
39{ 40{
40 public class LocalAssetServicesConnector : ISharedRegionModule 41 public class LocalAssetServicesConnector :
42 ISharedRegionModule, IAssetService
41 { 43 {
42 private static readonly ILog m_log = 44 private static readonly ILog m_log =
43 LogManager.GetLogger( 45 LogManager.GetLogger(
44 MethodBase.GetCurrentMethod().DeclaringType); 46 MethodBase.GetCurrentMethod().DeclaringType);
45 47
46 private Dictionary<Scene, IImprovedAssetCache> m_AssetCache = 48 private IImprovedAssetCache m_Cache = null;
47 new Dictionary<Scene, IImprovedAssetCache>();
48 49
49 private IAssetService m_AssetService; 50 private IAssetService m_AssetService;
50 51
@@ -108,15 +109,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
108 if (!m_Enabled) 109 if (!m_Enabled)
109 return; 110 return;
110 111
111 scene.RegisterModuleInterface<IAssetService>(m_AssetService); 112 scene.RegisterModuleInterface<IAssetService>(this);
112 } 113 }
113 114
114 public void RemoveRegion(Scene scene) 115 public void RemoveRegion(Scene scene)
115 { 116 {
116 if (!m_Enabled)
117 return;
118
119 m_AssetCache.Remove(scene);
120 } 117 }
121 118
122 public void RegionLoaded(Scene scene) 119 public void RegionLoaded(Scene scene)
@@ -124,18 +121,113 @@ namespace OpenSim.Region.CoreModules.ServiceConnectors.Asset
124 if (!m_Enabled) 121 if (!m_Enabled)
125 return; 122 return;
126 123
127 m_AssetCache[scene] = 124 if (m_Cache == null)
128 scene.RequestModuleInterface<IImprovedAssetCache>(); 125 {
126 m_Cache = scene.RequestModuleInterface<IImprovedAssetCache>();
127
128 if (!(m_Cache is ISharedRegionModule))
129 m_Cache = null;
130 }
129 131
130 m_log.InfoFormat("[ASSET CONNECTOR]: Enabled local assets for region {0}", scene.RegionInfo.RegionName); 132 m_log.InfoFormat("[ASSET CONNECTOR]: Enabled local assets for region {0}", scene.RegionInfo.RegionName);
131 133
132 m_AssetCache[scene] = 134 if (m_Cache != null)
133 scene.RequestModuleInterface<IImprovedAssetCache>();
134
135 if (m_AssetCache[scene] != null)
136 { 135 {
137 m_log.InfoFormat("[ASSET CONNECTOR]: Enabled asset caching for region {0}", scene.RegionInfo.RegionName); 136 m_log.InfoFormat("[ASSET CONNECTOR]: Enabled asset caching for region {0}", scene.RegionInfo.RegionName);
138 } 137 }
138 else
139 {
140 // Short-circuit directly to storage layer
141 //
142 scene.UnregisterModuleInterface<IAssetService>(this);
143 scene.RegisterModuleInterface<IAssetService>(m_AssetService);
144 }
145 }
146
147 public AssetBase Get(string id)
148 {
149 AssetBase asset = m_Cache.Get(id);
150
151 if (asset == null)
152 return m_AssetService.Get(id);
153 return asset;
154 }
155
156 public AssetMetadata GetMetadata(string id)
157 {
158 AssetBase asset = m_Cache.Get(id);
159
160 if (asset != null)
161 return asset.Metadata;
162
163 asset = m_AssetService.Get(id);
164 if (asset != null)
165 {
166 m_Cache.Cache(asset);
167 return asset.Metadata;
168 }
169
170 return null;
171 }
172
173 public byte[] GetData(string id)
174 {
175 AssetBase asset = m_Cache.Get(id);
176
177 if (asset != null)
178 return asset.Data;
179
180 asset = m_AssetService.Get(id);
181 if (asset != null)
182 {
183 m_Cache.Cache(asset);
184 return asset.Data;
185 }
186
187 return null;
188 }
189
190 public bool Get(string id, Object sender, AssetRetrieved handler)
191 {
192 AssetBase asset = m_Cache.Get(id);
193
194 if (asset != null)
195 {
196 handler(id, sender, asset);
197 return true;
198 }
199
200 return m_AssetService.Get(id, sender, delegate (string assetID, Object s, AssetBase a)
201 {
202 if (a != null)
203 m_Cache.Cache(a);
204 handler(assetID, s, a);
205 });
206 }
207
208 public string Store(AssetBase asset)
209 {
210 m_Cache.Cache(asset);
211 return m_AssetService.Store(asset);
212 }
213
214 public bool UpdateContent(string id, byte[] data)
215 {
216 AssetBase asset = m_Cache.Get(id);
217 if (asset != null)
218 {
219 asset.Data = data;
220 m_Cache.Cache(asset);
221 }
222
223 return m_AssetService.UpdateContent(id, data);
224 }
225
226 public bool Delete(string id)
227 {
228 m_Cache.Expire(id);
229
230 return m_AssetService.Delete(id);
139 } 231 }
140 } 232 }
141} 233}