aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/AssetService/XAssetService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/AssetService/XAssetService.cs')
-rw-r--r--OpenSim/Services/AssetService/XAssetService.cs63
1 files changed, 41 insertions, 22 deletions
diff --git a/OpenSim/Services/AssetService/XAssetService.cs b/OpenSim/Services/AssetService/XAssetService.cs
index a1d10ed..8a2ca7c 100644
--- a/OpenSim/Services/AssetService/XAssetService.cs
+++ b/OpenSim/Services/AssetService/XAssetService.cs
@@ -39,8 +39,7 @@ using OpenMetaverse;
39namespace OpenSim.Services.AssetService 39namespace 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>
45 public class XAssetService : XAssetServiceBase, IAssetService 44 public class XAssetService : XAssetServiceBase, IAssetService
46 { 45 {
@@ -48,7 +47,9 @@ namespace OpenSim.Services.AssetService
48 47
49 protected static XAssetService m_RootInstance; 48 protected static XAssetService m_RootInstance;
50 49
51 public XAssetService(IConfigSource config) : base(config) 50 public XAssetService(IConfigSource config) : this(config, "AssetService") {}
51
52 public XAssetService(IConfigSource config, string configName) : base(config, configName)
52 { 53 {
53 if (m_RootInstance == null) 54 if (m_RootInstance == null)
54 { 55 {
@@ -56,22 +57,21 @@ namespace OpenSim.Services.AssetService
56 57
57 if (m_AssetLoader != null) 58 if (m_AssetLoader != null)
58 { 59 {
59 IConfig assetConfig = config.Configs["AssetService"]; 60 IConfig assetConfig = config.Configs[configName];
60 if (assetConfig == null) 61 if (assetConfig == null)
61 throw new Exception("No AssetService configuration"); 62 throw new Exception("No AssetService configuration");
62 63
63 string loaderArgs = assetConfig.GetString("AssetLoaderArgs", 64 string loaderArgs = assetConfig.GetString("AssetLoaderArgs", String.Empty);
64 String.Empty);
65 65
66 bool assetLoaderEnabled = assetConfig.GetBoolean("AssetLoaderEnabled", true); 66 bool assetLoaderEnabled = assetConfig.GetBoolean("AssetLoaderEnabled", true);
67 67
68 if (assetLoaderEnabled) 68 if (assetLoaderEnabled && !HasChainedAssetService)
69 { 69 {
70 m_log.DebugFormat("[XASSET SERVICE]: Loading default asset set from {0}", loaderArgs); 70 m_log.DebugFormat("[XASSET SERVICE]: Loading default asset set from {0}", loaderArgs);
71 71
72 m_AssetLoader.ForEachDefaultXmlAsset( 72 m_AssetLoader.ForEachDefaultXmlAsset(
73 loaderArgs, 73 loaderArgs,
74 delegate(AssetBase a) 74 a =>
75 { 75 {
76 AssetBase existingAsset = Get(a.ID); 76 AssetBase existingAsset = Get(a.ID);
77// AssetMetadata existingMetadata = GetMetadata(a.ID); 77// AssetMetadata existingMetadata = GetMetadata(a.ID);
@@ -103,7 +103,23 @@ namespace OpenSim.Services.AssetService
103 103
104 try 104 try
105 { 105 {
106 return m_Database.GetAsset(assetID); 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;
107 } 123 }
108 catch (Exception e) 124 catch (Exception e)
109 { 125 {
@@ -120,30 +136,25 @@ namespace OpenSim.Services.AssetService
120 public virtual AssetMetadata GetMetadata(string id) 136 public virtual AssetMetadata GetMetadata(string id)
121 { 137 {
122// m_log.DebugFormat("[XASSET SERVICE]: Get asset metadata for {0}", id); 138// m_log.DebugFormat("[XASSET SERVICE]: Get asset metadata for {0}", id);
123
124 UUID assetID;
125 139
126 if (!UUID.TryParse(id, out assetID)) 140 AssetBase asset = Get(id);
127 return null;
128 141
129 AssetBase asset = m_Database.GetAsset(assetID);
130 if (asset != null) 142 if (asset != null)
131 return asset.Metadata; 143 return asset.Metadata;
132 144 else
133 return null; 145 return null;
134 } 146 }
135 147
136 public virtual byte[] GetData(string id) 148 public virtual byte[] GetData(string id)
137 { 149 {
138// m_log.DebugFormat("[XASSET SERVICE]: Get asset data for {0}", id); 150// m_log.DebugFormat("[XASSET SERVICE]: Get asset data for {0}", id);
139 151
140 UUID assetID; 152 AssetBase asset = Get(id);
141 153
142 if (!UUID.TryParse(id, out assetID)) 154 if (asset != null)
155 return asset.Data;
156 else
143 return null; 157 return null;
144
145 AssetBase asset = m_Database.GetAsset(assetID);
146 return asset.Data;
147 } 158 }
148 159
149 public virtual bool Get(string id, Object sender, AssetRetrieved handler) 160 public virtual bool Get(string id, Object sender, AssetRetrieved handler)
@@ -155,7 +166,7 @@ namespace OpenSim.Services.AssetService
155 if (!UUID.TryParse(id, out assetID)) 166 if (!UUID.TryParse(id, out assetID))
156 return false; 167 return false;
157 168
158 AssetBase asset = m_Database.GetAsset(assetID); 169 AssetBase asset = Get(id);
159 170
160 //m_log.DebugFormat("[XASSET SERVICE]: Got asset {0}", asset); 171 //m_log.DebugFormat("[XASSET SERVICE]: Got asset {0}", asset);
161 172
@@ -194,7 +205,15 @@ namespace OpenSim.Services.AssetService
194 if (!UUID.TryParse(id, out assetID)) 205 if (!UUID.TryParse(id, out assetID))
195 return false; 206 return false;
196 207
208 // Don't bother deleting from a chained asset service. This isn't a big deal since deleting happens
209 // very rarely.
210
197 return m_Database.Delete(id); 211 return m_Database.Delete(id);
198 } 212 }
213
214 private void MigrateFromChainedService(AssetBase asset)
215 {
216 Util.FireAndForget(o => { Store(asset); m_ChainedAssetService.Delete(asset.ID); });
217 }
199 } 218 }
200} \ No newline at end of file 219} \ No newline at end of file