diff options
Diffstat (limited to 'OpenSim/Services/AssetService/XAssetService.cs')
-rw-r--r-- | OpenSim/Services/AssetService/XAssetService.cs | 77 |
1 files changed, 53 insertions, 24 deletions
diff --git a/OpenSim/Services/AssetService/XAssetService.cs b/OpenSim/Services/AssetService/XAssetService.cs index a1d10ed..b1e5184 100644 --- a/OpenSim/Services/AssetService/XAssetService.cs +++ b/OpenSim/Services/AssetService/XAssetService.cs | |||
@@ -39,16 +39,18 @@ using OpenMetaverse; | |||
39 | namespace OpenSim.Services.AssetService | 39 | namespace OpenSim.Services.AssetService |
40 | { | 40 | { |
41 | /// <summary> | 41 | /// <summary> |
42 | /// This will be developed into a de-duplicating asset service. | 42 | /// A de-duplicating asset service. |
43 | /// XXX: Currently it's a just a copy of the existing AssetService. so please don't attempt to use it. | ||
44 | /// </summary> | 43 | /// </summary> |
44 | [Obsolete] | ||
45 | public class XAssetService : XAssetServiceBase, IAssetService | 45 | public class XAssetService : XAssetServiceBase, IAssetService |
46 | { | 46 | { |
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
48 | 48 | ||
49 | protected static XAssetService m_RootInstance; | 49 | protected static XAssetService m_RootInstance; |
50 | 50 | ||
51 | public XAssetService(IConfigSource config) : base(config) | 51 | public XAssetService(IConfigSource config) : this(config, "AssetService") {} |
52 | |||
53 | public XAssetService(IConfigSource config, string configName) : base(config, configName) | ||
52 | { | 54 | { |
53 | if (m_RootInstance == null) | 55 | if (m_RootInstance == null) |
54 | { | 56 | { |
@@ -56,22 +58,21 @@ namespace OpenSim.Services.AssetService | |||
56 | 58 | ||
57 | if (m_AssetLoader != null) | 59 | if (m_AssetLoader != null) |
58 | { | 60 | { |
59 | IConfig assetConfig = config.Configs["AssetService"]; | 61 | IConfig assetConfig = config.Configs[configName]; |
60 | if (assetConfig == null) | 62 | if (assetConfig == null) |
61 | throw new Exception("No AssetService configuration"); | 63 | throw new Exception("No AssetService configuration"); |
62 | 64 | ||
63 | string loaderArgs = assetConfig.GetString("AssetLoaderArgs", | 65 | string loaderArgs = assetConfig.GetString("AssetLoaderArgs", String.Empty); |
64 | String.Empty); | ||
65 | 66 | ||
66 | bool assetLoaderEnabled = assetConfig.GetBoolean("AssetLoaderEnabled", true); | 67 | bool assetLoaderEnabled = assetConfig.GetBoolean("AssetLoaderEnabled", true); |
67 | 68 | ||
68 | if (assetLoaderEnabled) | 69 | if (assetLoaderEnabled && !HasChainedAssetService) |
69 | { | 70 | { |
70 | m_log.DebugFormat("[XASSET SERVICE]: Loading default asset set from {0}", loaderArgs); | 71 | m_log.DebugFormat("[XASSET SERVICE]: Loading default asset set from {0}", loaderArgs); |
71 | 72 | ||
72 | m_AssetLoader.ForEachDefaultXmlAsset( | 73 | m_AssetLoader.ForEachDefaultXmlAsset( |
73 | loaderArgs, | 74 | loaderArgs, |
74 | delegate(AssetBase a) | 75 | a => |
75 | { | 76 | { |
76 | AssetBase existingAsset = Get(a.ID); | 77 | AssetBase existingAsset = Get(a.ID); |
77 | // AssetMetadata existingMetadata = GetMetadata(a.ID); | 78 | // AssetMetadata existingMetadata = GetMetadata(a.ID); |
@@ -85,6 +86,7 @@ namespace OpenSim.Services.AssetService | |||
85 | } | 86 | } |
86 | 87 | ||
87 | m_log.Debug("[XASSET SERVICE]: Local asset service enabled"); | 88 | m_log.Debug("[XASSET SERVICE]: Local asset service enabled"); |
89 | m_log.Error("[XASSET SERVICE]: THIS ASSET SERVICE HAS BEEN MARKED OBSOLETE. PLEASE USE FSAssetService"); | ||
88 | } | 90 | } |
89 | } | 91 | } |
90 | } | 92 | } |
@@ -103,7 +105,23 @@ namespace OpenSim.Services.AssetService | |||
103 | 105 | ||
104 | try | 106 | try |
105 | { | 107 | { |
106 | return m_Database.GetAsset(assetID); | 108 | AssetBase asset = m_Database.GetAsset(assetID); |
109 | |||
110 | if (asset != null) | ||
111 | { | ||
112 | return asset; | ||
113 | } | ||
114 | else if (HasChainedAssetService) | ||
115 | { | ||
116 | asset = m_ChainedAssetService.Get(id); | ||
117 | |||
118 | if (asset != null) | ||
119 | MigrateFromChainedService(asset); | ||
120 | |||
121 | return asset; | ||
122 | } | ||
123 | |||
124 | return null; | ||
107 | } | 125 | } |
108 | catch (Exception e) | 126 | catch (Exception e) |
109 | { | 127 | { |
@@ -120,30 +138,25 @@ namespace OpenSim.Services.AssetService | |||
120 | public virtual AssetMetadata GetMetadata(string id) | 138 | public virtual AssetMetadata GetMetadata(string id) |
121 | { | 139 | { |
122 | // m_log.DebugFormat("[XASSET SERVICE]: Get asset metadata for {0}", id); | 140 | // m_log.DebugFormat("[XASSET SERVICE]: Get asset metadata for {0}", id); |
123 | |||
124 | UUID assetID; | ||
125 | 141 | ||
126 | if (!UUID.TryParse(id, out assetID)) | 142 | AssetBase asset = Get(id); |
127 | return null; | ||
128 | 143 | ||
129 | AssetBase asset = m_Database.GetAsset(assetID); | ||
130 | if (asset != null) | 144 | if (asset != null) |
131 | return asset.Metadata; | 145 | return asset.Metadata; |
132 | 146 | else | |
133 | return null; | 147 | return null; |
134 | } | 148 | } |
135 | 149 | ||
136 | public virtual byte[] GetData(string id) | 150 | public virtual byte[] GetData(string id) |
137 | { | 151 | { |
138 | // m_log.DebugFormat("[XASSET SERVICE]: Get asset data for {0}", id); | 152 | // m_log.DebugFormat("[XASSET SERVICE]: Get asset data for {0}", id); |
139 | 153 | ||
140 | UUID assetID; | 154 | AssetBase asset = Get(id); |
141 | 155 | ||
142 | if (!UUID.TryParse(id, out assetID)) | 156 | if (asset != null) |
157 | return asset.Data; | ||
158 | else | ||
143 | return null; | 159 | return null; |
144 | |||
145 | AssetBase asset = m_Database.GetAsset(assetID); | ||
146 | return asset.Data; | ||
147 | } | 160 | } |
148 | 161 | ||
149 | public virtual bool Get(string id, Object sender, AssetRetrieved handler) | 162 | public virtual bool Get(string id, Object sender, AssetRetrieved handler) |
@@ -155,7 +168,7 @@ namespace OpenSim.Services.AssetService | |||
155 | if (!UUID.TryParse(id, out assetID)) | 168 | if (!UUID.TryParse(id, out assetID)) |
156 | return false; | 169 | return false; |
157 | 170 | ||
158 | AssetBase asset = m_Database.GetAsset(assetID); | 171 | AssetBase asset = Get(id); |
159 | 172 | ||
160 | //m_log.DebugFormat("[XASSET SERVICE]: Got asset {0}", asset); | 173 | //m_log.DebugFormat("[XASSET SERVICE]: Got asset {0}", asset); |
161 | 174 | ||
@@ -164,9 +177,16 @@ namespace OpenSim.Services.AssetService | |||
164 | return true; | 177 | return true; |
165 | } | 178 | } |
166 | 179 | ||
180 | public virtual bool[] AssetsExist(string[] ids) | ||
181 | { | ||
182 | UUID[] uuid = Array.ConvertAll(ids, id => UUID.Parse(id)); | ||
183 | return m_Database.AssetsExist(uuid); | ||
184 | } | ||
185 | |||
167 | public virtual string Store(AssetBase asset) | 186 | public virtual string Store(AssetBase asset) |
168 | { | 187 | { |
169 | if (!m_Database.ExistsAsset(asset.FullID)) | 188 | bool exists = m_Database.AssetsExist(new[] { asset.FullID })[0]; |
189 | if (!exists) | ||
170 | { | 190 | { |
171 | // m_log.DebugFormat( | 191 | // m_log.DebugFormat( |
172 | // "[XASSET SERVICE]: Storing asset {0} {1}, bytes {2}", asset.Name, asset.FullID, asset.Data.Length); | 192 | // "[XASSET SERVICE]: Storing asset {0} {1}, bytes {2}", asset.Name, asset.FullID, asset.Data.Length); |
@@ -194,7 +214,16 @@ namespace OpenSim.Services.AssetService | |||
194 | if (!UUID.TryParse(id, out assetID)) | 214 | if (!UUID.TryParse(id, out assetID)) |
195 | return false; | 215 | return false; |
196 | 216 | ||
217 | if (HasChainedAssetService) | ||
218 | m_ChainedAssetService.Delete(id); | ||
219 | |||
197 | return m_Database.Delete(id); | 220 | return m_Database.Delete(id); |
198 | } | 221 | } |
222 | |||
223 | private void MigrateFromChainedService(AssetBase asset) | ||
224 | { | ||
225 | Store(asset); | ||
226 | m_ChainedAssetService.Delete(asset.ID); | ||
227 | } | ||
199 | } | 228 | } |
200 | } \ No newline at end of file | 229 | } |