31 using System.Collections.Generic;
32 using System.Collections.Specialized;
33 using System.Reflection;
35 using OpenSim.Framework;
36 using OpenSim.Services.Interfaces;
37 using OpenSim.Services.Connectors.Hypergrid;
38 using OpenSim.Services.Connectors.SimianGrid;
41 namespace OpenSim.Services.Connectors
45 private static readonly ILog m_log =
47 MethodBase.GetCurrentMethod().DeclaringType);
49 private Dictionary<IAssetService, object> m_endpointSerializer =
new Dictionary<IAssetService, object>();
52 lock (m_endpointSerializer)
56 if (! m_endpointSerializer.TryGetValue(connector, out eplock))
58 eplock =
new object();
59 m_endpointSerializer.Add(connector, eplock);
67 private Dictionary<string, IAssetService> m_connectors =
new Dictionary<string, IAssetService>();
71 IConfig moduleConfig = source.Configs[
"Modules"];
72 if (moduleConfig != null)
76 IConfig assetConfig = source.Configs[
"AssetService"];
77 if (assetConfig == null)
79 m_log.Error(
"[HG ASSET SERVICE]: AssetService missing from OpenSim.ini");
83 m_log.Info(
"[HG ASSET SERVICE]: HG asset service enabled");
92 if (m_connectors.ContainsKey(url))
94 connector = m_connectors[url];
100 string connectorType =
new HeloServicesConnector(url).Helo();
101 m_log.DebugFormat(
"[HG ASSET SERVICE]: HELO returned {0}", connectorType);
102 if (connectorType ==
"opensim-simian")
107 connector =
new AssetServicesConnector(url);
109 m_connectors.Add(url, connector);
117 string url = string.Empty;
118 string assetID = string.Empty;
120 if (Util.ParseForeignAssetID(
id, out url, out assetID))
123 return connector.Get(assetID);
131 string url = string.Empty;
132 string assetID = string.Empty;
134 if (Util.ParseForeignAssetID(
id, out url, out assetID))
137 return connector.GetCached(assetID);
145 string url = string.Empty;
146 string assetID = string.Empty;
148 if (Util.ParseForeignAssetID(
id, out url, out assetID))
151 return connector.GetMetadata(assetID);
164 string url = string.Empty;
165 string assetID = string.Empty;
167 if (Util.ParseForeignAssetID(
id, out url, out assetID))
170 return connector.Get(assetID, sender, handler);
177 private struct AssetAndIndex
182 public AssetAndIndex(UUID assetID,
int index)
184 this.assetID = assetID;
196 var url2assets =
new Dictionary<string, List<AssetAndIndex>>();
198 for (
int i = 0; i < ids.Length; i++)
200 string url = string.Empty;
201 string assetID = string.Empty;
203 if (Util.ParseForeignAssetID(ids[i], out url, out assetID))
205 if (!url2assets.ContainsKey(url))
206 url2assets.Add(url,
new List<AssetAndIndex>());
207 url2assets[url].Add(
new AssetAndIndex(UUID.Parse(assetID), i));
213 bool[] exist =
new bool[ids.Length];
215 foreach (
string url
in url2assets.Keys)
218 lock (EndPointLock(connector))
220 List<AssetAndIndex> curAssets = url2assets[url];
221 string[] assetIDs = curAssets.ConvertAll(a => a.assetID.ToString()).ToArray();
222 bool[] curExist = connector.AssetsExist(assetIDs);
225 foreach (AssetAndIndex ai
in curAssets)
227 exist[ai.index] = curExist[i];
238 string url = string.Empty;
239 string assetID = string.Empty;
241 if (Util.ParseForeignAssetID(asset.
ID, out url, out assetID))
246 lock (EndPointLock(connector))
247 return connector.Store(asset);
bool Delete(string id)
Delete an asset
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...
HGAssetServiceConnector(IConfigSource source)
AssetBase GetCached(string id)
Synchronously fetches an asset from the local cache only.
Asset class. All Assets are reference by this class or a class derived from this class ...
byte[] GetData(string id)
Get an asset's data, ignoring the metadata.
AssetBase Get(string id)
Get an asset synchronously.
bool UpdateContent(string id, byte[] data)
Update an asset's content
virtual bool[] AssetsExist(string[] ids)
Check if assets exist in the database.
string Store(AssetBase asset)
Creates a new asset
delegate void AssetRetrieved(string id, Object sender, AssetBase asset)
string ID
Asset MetaData ID (transferring from UUID to string ID)
Connects to the SimianGrid asset service
AssetMetadata GetMetadata(string id)
Get an asset's metadata