aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/AssetService/XAssetService.cs
diff options
context:
space:
mode:
authorUbitUmarov2015-09-01 11:43:07 +0100
committerUbitUmarov2015-09-01 11:43:07 +0100
commitfb78b182520fc9bb0f971afd0322029c70278ea6 (patch)
treeb4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Services/AssetService/XAssetService.cs
parentlixo (diff)
parentMantis #7713: fixed bug introduced by 1st MOSES patch. (diff)
downloadopensim-SC_OLD-fb78b182520fc9bb0f971afd0322029c70278ea6.zip
opensim-SC_OLD-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz
opensim-SC_OLD-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2
opensim-SC_OLD-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Services/AssetService/XAssetService.cs')
-rw-r--r--OpenSim/Services/AssetService/XAssetService.cs227
1 files changed, 227 insertions, 0 deletions
diff --git a/OpenSim/Services/AssetService/XAssetService.cs b/OpenSim/Services/AssetService/XAssetService.cs
new file mode 100644
index 0000000..f58b769
--- /dev/null
+++ b/OpenSim/Services/AssetService/XAssetService.cs
@@ -0,0 +1,227 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using Nini.Config;
33using log4net;
34using OpenSim.Framework;
35using OpenSim.Data;
36using OpenSim.Services.Interfaces;
37using OpenMetaverse;
38
39namespace OpenSim.Services.AssetService
40{
41 /// <summary>
42 /// A de-duplicating asset service.
43 /// </summary>
44 public class XAssetService : XAssetServiceBase, IAssetService
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 protected static XAssetService m_RootInstance;
49
50 public XAssetService(IConfigSource config) : this(config, "AssetService") {}
51
52 public XAssetService(IConfigSource config, string configName) : base(config, configName)
53 {
54 if (m_RootInstance == null)
55 {
56 m_RootInstance = this;
57
58 if (m_AssetLoader != null)
59 {
60 IConfig assetConfig = config.Configs[configName];
61 if (assetConfig == null)
62 throw new Exception("No AssetService configuration");
63
64 string loaderArgs = assetConfig.GetString("AssetLoaderArgs", String.Empty);
65
66 bool assetLoaderEnabled = assetConfig.GetBoolean("AssetLoaderEnabled", true);
67
68 if (assetLoaderEnabled && !HasChainedAssetService)
69 {
70 m_log.DebugFormat("[XASSET SERVICE]: Loading default asset set from {0}", loaderArgs);
71
72 m_AssetLoader.ForEachDefaultXmlAsset(
73 loaderArgs,
74 a =>
75 {
76 AssetBase existingAsset = Get(a.ID);
77// AssetMetadata existingMetadata = GetMetadata(a.ID);
78
79 if (existingAsset == null || Util.SHA1Hash(existingAsset.Data) != Util.SHA1Hash(a.Data))
80 {
81// m_log.DebugFormat("[ASSET]: Storing {0} {1}", a.Name, a.ID);
82 Store(a);
83 }
84 });
85 }
86
87 m_log.Debug("[XASSET SERVICE]: Local asset service enabled");
88 }
89 }
90 }
91
92 public virtual AssetBase Get(string id)
93 {
94// m_log.DebugFormat("[ASSET SERVICE]: Get asset for {0}", id);
95
96 UUID assetID;
97
98 if (!UUID.TryParse(id, out assetID))
99 {
100 m_log.WarnFormat("[XASSET SERVICE]: Could not parse requested asset id {0}", id);
101 return null;
102 }
103
104 try
105 {
106 AssetBase asset = m_Database.GetAsset(assetID);
107
108 if (asset != null)
109 {
110 return asset;
111 }
112 else if (HasChainedAssetService)
113 {
114 asset = m_ChainedAssetService.Get(id);
115
116 if (asset != null)
117 MigrateFromChainedService(asset);
118
119 return asset;
120 }
121
122 return null;
123 }
124 catch (Exception e)
125 {
126 m_log.ErrorFormat("[XASSET SERVICE]: Exception getting asset {0} {1}", assetID, e);
127 return null;
128 }
129 }
130
131 public virtual AssetBase GetCached(string id)
132 {
133 return Get(id);
134 }
135
136 public virtual AssetMetadata GetMetadata(string id)
137 {
138// m_log.DebugFormat("[XASSET SERVICE]: Get asset metadata for {0}", id);
139
140 AssetBase asset = Get(id);
141
142 if (asset != null)
143 return asset.Metadata;
144 else
145 return null;
146 }
147
148 public virtual byte[] GetData(string id)
149 {
150// m_log.DebugFormat("[XASSET SERVICE]: Get asset data for {0}", id);
151
152 AssetBase asset = Get(id);
153
154 if (asset != null)
155 return asset.Data;
156 else
157 return null;
158 }
159
160 public virtual bool Get(string id, Object sender, AssetRetrieved handler)
161 {
162 //m_log.DebugFormat("[XASSET SERVICE]: Get asset async {0}", id);
163
164 UUID assetID;
165
166 if (!UUID.TryParse(id, out assetID))
167 return false;
168
169 AssetBase asset = Get(id);
170
171 //m_log.DebugFormat("[XASSET SERVICE]: Got asset {0}", asset);
172
173 handler(id, sender, asset);
174
175 return true;
176 }
177
178 public virtual bool[] AssetsExist(string[] ids)
179 {
180 UUID[] uuid = Array.ConvertAll(ids, id => UUID.Parse(id));
181 return m_Database.AssetsExist(uuid);
182 }
183
184 public virtual string Store(AssetBase asset)
185 {
186 bool exists = m_Database.AssetsExist(new[] { asset.FullID })[0];
187 if (!exists)
188 {
189// m_log.DebugFormat(
190// "[XASSET SERVICE]: Storing asset {0} {1}, bytes {2}", asset.Name, asset.FullID, asset.Data.Length);
191 m_Database.StoreAsset(asset);
192 }
193// else
194// {
195// m_log.DebugFormat(
196// "[XASSET SERVICE]: Not storing asset {0} {1}, bytes {2} as it already exists", asset.Name, asset.FullID, asset.Data.Length);
197// }
198
199 return asset.ID;
200 }
201
202 public bool UpdateContent(string id, byte[] data)
203 {
204 return false;
205 }
206
207 public virtual bool Delete(string id)
208 {
209// m_log.DebugFormat("[XASSET SERVICE]: Deleting asset {0}", id);
210
211 UUID assetID;
212 if (!UUID.TryParse(id, out assetID))
213 return false;
214
215 if (HasChainedAssetService)
216 m_ChainedAssetService.Delete(id);
217
218 return m_Database.Delete(id);
219 }
220
221 private void MigrateFromChainedService(AssetBase asset)
222 {
223 Store(asset);
224 m_ChainedAssetService.Delete(asset.ID);
225 }
226 }
227}