32 using System.Collections.Generic;
33 using System.Reflection;
34 using OpenSim.Framework;
36 using OpenSim.Server.Base;
37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Region.Framework.Scenes;
39 using OpenSim.Services.Interfaces;
44 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"HGAssetBroker")]
47 private static readonly ILog m_log =
49 MethodBase.GetCurrentMethod().DeclaringType);
55 private Scene m_aScene;
56 private string m_LocalAssetServiceURI;
58 private bool m_Enabled =
false;
62 public Type ReplaceableInterface
69 get {
return "HGAssetBroker"; }
81 IConfig moduleConfig = source.Configs[
"Modules"];
82 if (moduleConfig != null)
84 string name = moduleConfig.GetString(
"AssetServices",
"");
87 IConfig assetConfig = source.Configs[
"AssetService"];
88 if (assetConfig == null)
90 m_log.Error(
"[HG ASSET CONNECTOR]: AssetService missing from OpenSim.ini");
94 string localDll = assetConfig.GetString(
"LocalGridAssetService",
96 string HGDll = assetConfig.GetString(
"HypergridAssetService",
99 if (localDll ==
String.Empty)
101 m_log.Error(
"[HG ASSET CONNECTOR]: No LocalGridAssetService named in section AssetService");
105 if (HGDll ==
String.Empty)
107 m_log.Error(
"[HG ASSET CONNECTOR]: No HypergridAssetService named in section AssetService");
120 if (m_GridService == null)
122 m_log.Error(
"[HG ASSET CONNECTOR]: Can't load local asset service");
125 if (m_HGService == null)
127 m_log.Error(
"[HG ASSET CONNECTOR]: Can't load hypergrid asset service");
131 m_LocalAssetServiceURI = assetConfig.GetString(
"AssetServerURI", string.Empty);
132 if (m_LocalAssetServiceURI ==
string.Empty)
134 IConfig netConfig = source.Configs[
"Network"];
135 m_LocalAssetServiceURI = netConfig.GetString(
"asset_server_url", string.Empty);
138 if (m_LocalAssetServiceURI !=
string.Empty)
139 m_LocalAssetServiceURI = m_LocalAssetServiceURI.Trim(
'/');
141 IConfig hgConfig = source.Configs[
"HGAssetService"];
145 m_log.Info(
"[HG ASSET CONNECTOR]: HG asset broker enabled");
186 m_log.InfoFormat(
"[HG ASSET CONNECTOR]: Enabled hypergrid asset broker for region {0}", scene.RegionInfo.RegionName);
190 m_log.InfoFormat(
"[HG ASSET CONNECTOR]: Enabled asset caching for region {0}", scene.RegionInfo.RegionName);
194 private bool IsHG(
string id)
198 if (Uri.TryCreate(
id, UriKind.Absolute, out assetUri) &&
199 assetUri.Scheme == Uri.UriSchemeHttp)
212 asset = m_Cache.Get(id);
220 asset = m_HGService.Get(id);
224 if (m_AssetPerms.AllowedImport(asset.
Type))
225 m_GridService.Store(asset);
231 asset = m_GridService.Get(id);
234 m_Cache.Cache(asset);
242 return m_Cache.Get(id);
257 return asset.Metadata;
263 metadata = m_HGService.GetMetadata(
id);
265 metadata = m_GridService.GetMetadata(id);
284 return m_HGService.GetData(
id);
286 return m_GridService.GetData(id);
295 asset = m_Cache.Get(id);
299 Util.FireAndForget(delegate { handler(
id, sender, asset); }, null,
"HGAssetBroker.GotFromCache");
305 return m_HGService.Get(id, sender, delegate (
string assetID,
Object s,
AssetBase a)
309 handler(assetID, s, a);
314 return m_GridService.Get(id, sender, delegate (
string assetID,
Object s,
AssetBase a)
318 handler(assetID, s, a);
326 foreach (
string id in ids)
333 return m_GridService.AssetsExist(ids);
334 else if (numHG == ids.Length)
335 return m_HGService.AssetsExist(ids);
337 throw new Exception(
"[HG ASSET CONNECTOR]: AssetsExist: all the assets must be either local or foreign");
345 m_Cache.Cache(asset);
349 bool isHG = IsHG(asset.
ID);
350 if ((m_Cache != null) && !isHG)
354 m_Cache.Cache(asset);
359 if (m_AssetPerms.AllowedExport(asset.
Type))
360 id = m_HGService.Store(asset);
365 id = m_GridService.Store(asset);
367 if (
String.IsNullOrEmpty(
id))
373 m_Cache.Cache(asset);
383 asset = m_Cache.Get(id);
388 m_Cache.Cache(asset);
392 return m_HGService.UpdateContent(
id, data);
394 return m_GridService.UpdateContent(id, data);
404 result = m_HGService.Delete(
id);
406 result = m_GridService.Delete(id);
408 if (result && m_Cache != null)
HGAssetBroker(IConfigSource config)
byte[] GetData(string id)
Get an asset's data, ignoring the metadata.
bool Delete(string id)
Delete an asset
AssetBase GetCached(string id)
Synchronously fetches an asset from the local cache only.
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
sbyte Type
(sbyte) AssetType enum
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
bool Get(string id, Object sender, AssetRetrieved handler)
Get an asset synchronously or asynchronously (depending on whether it is locally cached) and fire a c...
string Store(AssetBase asset)
Creates a new asset
bool Local
Is this a region only asset, or does this exist on the asset server also
virtual bool[] AssetsExist(string[] ids)
Check if assets exist in the database.
Asset class. All Assets are reference by this class or a class derived from this class ...
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
bool UpdateContent(string id, byte[] data)
Update an asset's content
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
Interactive OpenSim region server
AssetBase Get(string id)
Get an asset synchronously.
AssetMetadata GetMetadata(string id)
Get an asset's metadata
delegate void AssetRetrieved(string id, Object sender, AssetBase asset)
string ID
Asset MetaData ID (transferring from UUID to string ID)
bool Temporary
Is this asset going to be saved to the asset database?