diff options
Diffstat (limited to 'OpenSim/Services/Connectors/Asset')
-rw-r--r-- | OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs | 21 | ||||
-rw-r--r-- | OpenSim/Services/Connectors/Asset/HGAssetServiceConnector.cs | 104 |
2 files changed, 87 insertions, 38 deletions
diff --git a/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs b/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs index 8b04d7f..32415e9 100644 --- a/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs +++ b/OpenSim/Services/Connectors/Asset/AssetServicesConnector.cs | |||
@@ -254,6 +254,27 @@ namespace OpenSim.Services.Connectors | |||
254 | return true; | 254 | return true; |
255 | } | 255 | } |
256 | 256 | ||
257 | public virtual bool[] AssetsExist(string[] ids) | ||
258 | { | ||
259 | string uri = m_ServerURI + "/get_assets_exist"; | ||
260 | |||
261 | bool[] exist = null; | ||
262 | try | ||
263 | { | ||
264 | exist = SynchronousRestObjectRequester.MakeRequest<string[], bool[]>("POST", uri, ids); | ||
265 | } | ||
266 | catch (Exception) | ||
267 | { | ||
268 | // This is most likely to happen because the server doesn't support this function, | ||
269 | // so just silently return "doesn't exist" for all the assets. | ||
270 | } | ||
271 | |||
272 | if (exist == null) | ||
273 | exist = new bool[ids.Length]; | ||
274 | |||
275 | return exist; | ||
276 | } | ||
277 | |||
257 | public string Store(AssetBase asset) | 278 | public string Store(AssetBase asset) |
258 | { | 279 | { |
259 | if (asset.Local) | 280 | if (asset.Local) |
diff --git a/OpenSim/Services/Connectors/Asset/HGAssetServiceConnector.cs b/OpenSim/Services/Connectors/Asset/HGAssetServiceConnector.cs index c395178..3710c86 100644 --- a/OpenSim/Services/Connectors/Asset/HGAssetServiceConnector.cs +++ b/OpenSim/Services/Connectors/Asset/HGAssetServiceConnector.cs | |||
@@ -36,6 +36,7 @@ using OpenSim.Framework; | |||
36 | using OpenSim.Services.Interfaces; | 36 | using OpenSim.Services.Interfaces; |
37 | using OpenSim.Services.Connectors.Hypergrid; | 37 | using OpenSim.Services.Connectors.Hypergrid; |
38 | using OpenSim.Services.Connectors.SimianGrid; | 38 | using OpenSim.Services.Connectors.SimianGrid; |
39 | using OpenMetaverse; | ||
39 | 40 | ||
40 | namespace OpenSim.Services.Connectors | 41 | namespace OpenSim.Services.Connectors |
41 | { | 42 | { |
@@ -83,39 +84,6 @@ namespace OpenSim.Services.Connectors | |||
83 | } | 84 | } |
84 | } | 85 | } |
85 | 86 | ||
86 | private bool StringToUrlAndAssetID(string id, out string url, out string assetID) | ||
87 | { | ||
88 | url = String.Empty; | ||
89 | assetID = String.Empty; | ||
90 | |||
91 | Uri assetUri; | ||
92 | |||
93 | if (Uri.TryCreate(id, UriKind.Absolute, out assetUri) && | ||
94 | assetUri.Scheme == Uri.UriSchemeHttp) | ||
95 | { | ||
96 | // Simian | ||
97 | if (assetUri.Query != string.Empty) | ||
98 | { | ||
99 | NameValueCollection qscoll = HttpUtility.ParseQueryString(assetUri.Query); | ||
100 | assetID = qscoll["id"]; | ||
101 | if (assetID != null) | ||
102 | url = id.Replace(assetID, ""); // Malformed again, as simian expects | ||
103 | else | ||
104 | url = id; // !!! best effort | ||
105 | } | ||
106 | else // robust | ||
107 | { | ||
108 | url = "http://" + assetUri.Authority; | ||
109 | assetID = assetUri.LocalPath.Trim(new char[] { '/' }); | ||
110 | } | ||
111 | |||
112 | return true; | ||
113 | } | ||
114 | |||
115 | m_log.DebugFormat("[HG ASSET SERVICE]: Malformed URL {0}", id); | ||
116 | return false; | ||
117 | } | ||
118 | |||
119 | private IAssetService GetConnector(string url) | 87 | private IAssetService GetConnector(string url) |
120 | { | 88 | { |
121 | IAssetService connector = null; | 89 | IAssetService connector = null; |
@@ -149,7 +117,7 @@ namespace OpenSim.Services.Connectors | |||
149 | string url = string.Empty; | 117 | string url = string.Empty; |
150 | string assetID = string.Empty; | 118 | string assetID = string.Empty; |
151 | 119 | ||
152 | if (StringToUrlAndAssetID(id, out url, out assetID)) | 120 | if (Util.ParseForeignAssetID(id, out url, out assetID)) |
153 | { | 121 | { |
154 | IAssetService connector = GetConnector(url); | 122 | IAssetService connector = GetConnector(url); |
155 | return connector.Get(assetID); | 123 | return connector.Get(assetID); |
@@ -163,7 +131,7 @@ namespace OpenSim.Services.Connectors | |||
163 | string url = string.Empty; | 131 | string url = string.Empty; |
164 | string assetID = string.Empty; | 132 | string assetID = string.Empty; |
165 | 133 | ||
166 | if (StringToUrlAndAssetID(id, out url, out assetID)) | 134 | if (Util.ParseForeignAssetID(id, out url, out assetID)) |
167 | { | 135 | { |
168 | IAssetService connector = GetConnector(url); | 136 | IAssetService connector = GetConnector(url); |
169 | return connector.GetCached(assetID); | 137 | return connector.GetCached(assetID); |
@@ -177,7 +145,7 @@ namespace OpenSim.Services.Connectors | |||
177 | string url = string.Empty; | 145 | string url = string.Empty; |
178 | string assetID = string.Empty; | 146 | string assetID = string.Empty; |
179 | 147 | ||
180 | if (StringToUrlAndAssetID(id, out url, out assetID)) | 148 | if (Util.ParseForeignAssetID(id, out url, out assetID)) |
181 | { | 149 | { |
182 | IAssetService connector = GetConnector(url); | 150 | IAssetService connector = GetConnector(url); |
183 | return connector.GetMetadata(assetID); | 151 | return connector.GetMetadata(assetID); |
@@ -196,7 +164,7 @@ namespace OpenSim.Services.Connectors | |||
196 | string url = string.Empty; | 164 | string url = string.Empty; |
197 | string assetID = string.Empty; | 165 | string assetID = string.Empty; |
198 | 166 | ||
199 | if (StringToUrlAndAssetID(id, out url, out assetID)) | 167 | if (Util.ParseForeignAssetID(id, out url, out assetID)) |
200 | { | 168 | { |
201 | IAssetService connector = GetConnector(url); | 169 | IAssetService connector = GetConnector(url); |
202 | return connector.Get(assetID, sender, handler); | 170 | return connector.Get(assetID, sender, handler); |
@@ -205,12 +173,72 @@ namespace OpenSim.Services.Connectors | |||
205 | return false; | 173 | return false; |
206 | } | 174 | } |
207 | 175 | ||
176 | |||
177 | private struct AssetAndIndex | ||
178 | { | ||
179 | public UUID assetID; | ||
180 | public int index; | ||
181 | |||
182 | public AssetAndIndex(UUID assetID, int index) | ||
183 | { | ||
184 | this.assetID = assetID; | ||
185 | this.index = index; | ||
186 | } | ||
187 | } | ||
188 | |||
189 | public virtual bool[] AssetsExist(string[] ids) | ||
190 | { | ||
191 | // This method is a bit complicated because it works even if the assets belong to different | ||
192 | // servers; that requires sending separate requests to each server. | ||
193 | |||
194 | // Group the assets by the server they belong to | ||
195 | |||
196 | var url2assets = new Dictionary<string, List<AssetAndIndex>>(); | ||
197 | |||
198 | for (int i = 0; i < ids.Length; i++) | ||
199 | { | ||
200 | string url = string.Empty; | ||
201 | string assetID = string.Empty; | ||
202 | |||
203 | if (Util.ParseForeignAssetID(ids[i], out url, out assetID)) | ||
204 | { | ||
205 | if (!url2assets.ContainsKey(url)) | ||
206 | url2assets.Add(url, new List<AssetAndIndex>()); | ||
207 | url2assets[url].Add(new AssetAndIndex(UUID.Parse(assetID), i)); | ||
208 | } | ||
209 | } | ||
210 | |||
211 | // Query each of the servers in turn | ||
212 | |||
213 | bool[] exist = new bool[ids.Length]; | ||
214 | |||
215 | foreach (string url in url2assets.Keys) | ||
216 | { | ||
217 | IAssetService connector = GetConnector(url); | ||
218 | lock (EndPointLock(connector)) | ||
219 | { | ||
220 | List<AssetAndIndex> curAssets = url2assets[url]; | ||
221 | string[] assetIDs = curAssets.ConvertAll(a => a.assetID.ToString()).ToArray(); | ||
222 | bool[] curExist = connector.AssetsExist(assetIDs); | ||
223 | |||
224 | int i = 0; | ||
225 | foreach (AssetAndIndex ai in curAssets) | ||
226 | { | ||
227 | exist[ai.index] = curExist[i]; | ||
228 | ++i; | ||
229 | } | ||
230 | } | ||
231 | } | ||
232 | |||
233 | return exist; | ||
234 | } | ||
235 | |||
208 | public string Store(AssetBase asset) | 236 | public string Store(AssetBase asset) |
209 | { | 237 | { |
210 | string url = string.Empty; | 238 | string url = string.Empty; |
211 | string assetID = string.Empty; | 239 | string assetID = string.Empty; |
212 | 240 | ||
213 | if (StringToUrlAndAssetID(asset.ID, out url, out assetID)) | 241 | if (Util.ParseForeignAssetID(asset.ID, out url, out assetID)) |
214 | { | 242 | { |
215 | IAssetService connector = GetConnector(url); | 243 | IAssetService connector = GetConnector(url); |
216 | // Restore the assetID to a simple UUID | 244 | // Restore the assetID to a simple UUID |