aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/AssetService
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/AssetService')
-rw-r--r--OpenSim/Services/AssetService/AssetService.cs51
-rw-r--r--OpenSim/Services/AssetService/Properties/AssemblyInfo.cs4
-rw-r--r--OpenSim/Services/AssetService/XAssetService.cs77
-rw-r--r--OpenSim/Services/AssetService/XAssetServiceBase.cs47
4 files changed, 117 insertions, 62 deletions
diff --git a/OpenSim/Services/AssetService/AssetService.cs b/OpenSim/Services/AssetService/AssetService.cs
index e7eb6fe..0aefa16 100644
--- a/OpenSim/Services/AssetService/AssetService.cs
+++ b/OpenSim/Services/AssetService/AssetService.cs
@@ -123,53 +123,54 @@ namespace OpenSim.Services.AssetService
123 public virtual AssetMetadata GetMetadata(string id) 123 public virtual AssetMetadata GetMetadata(string id)
124 { 124 {
125// m_log.DebugFormat("[ASSET SERVICE]: Get asset metadata for {0}", id); 125// m_log.DebugFormat("[ASSET SERVICE]: Get asset metadata for {0}", id);
126
127 UUID assetID;
128 126
129 if (!UUID.TryParse(id, out assetID)) 127 AssetBase asset = Get(id);
130 return null;
131 128
132 AssetBase asset = m_Database.GetAsset(assetID);
133 if (asset != null) 129 if (asset != null)
134 return asset.Metadata; 130 return asset.Metadata;
135 131 else
136 return null; 132 return null;
137 } 133 }
138 134
139 public virtual byte[] GetData(string id) 135 public virtual byte[] GetData(string id)
140 { 136 {
141// m_log.DebugFormat("[ASSET SERVICE]: Get asset data for {0}", id); 137// m_log.DebugFormat("[ASSET SERVICE]: Get asset data for {0}", id);
142
143 UUID assetID;
144 138
145 if (!UUID.TryParse(id, out assetID)) 139 AssetBase asset = Get(id);
146 return null;
147 140
148 AssetBase asset = m_Database.GetAsset(assetID); 141 if (asset != null)
149 return asset.Data; 142 return asset.Data;
143 else
144 return null;
150 } 145 }
151 146
152 public virtual bool Get(string id, Object sender, AssetRetrieved handler) 147 public virtual bool Get(string id, Object sender, AssetRetrieved handler)
153 { 148 {
154 //m_log.DebugFormat("[AssetService]: Get asset async {0}", id); 149 //m_log.DebugFormat("[AssetService]: Get asset async {0}", id);
155
156 UUID assetID;
157 150
158 if (!UUID.TryParse(id, out assetID)) 151 handler(id, sender, Get(id));
159 return false;
160
161 AssetBase asset = m_Database.GetAsset(assetID);
162
163 //m_log.DebugFormat("[AssetService]: Got asset {0}", asset);
164
165 handler(id, sender, asset);
166 152
167 return true; 153 return true;
168 } 154 }
169 155
156 public virtual bool[] AssetsExist(string[] ids)
157 {
158 try
159 {
160 UUID[] uuid = Array.ConvertAll(ids, id => UUID.Parse(id));
161 return m_Database.AssetsExist(uuid);
162 }
163 catch (Exception e)
164 {
165 m_log.Error("[ASSET SERVICE]: Exception getting assets ", e);
166 return new bool[ids.Length];
167 }
168 }
169
170 public virtual string Store(AssetBase asset) 170 public virtual string Store(AssetBase asset)
171 { 171 {
172 if (!m_Database.ExistsAsset(asset.FullID)) 172 bool exists = m_Database.AssetsExist(new[] { asset.FullID })[0];
173 if (!exists)
173 { 174 {
174// m_log.DebugFormat( 175// m_log.DebugFormat(
175// "[ASSET SERVICE]: Storing asset {0} {1}, bytes {2}", asset.Name, asset.FullID, asset.Data.Length); 176// "[ASSET SERVICE]: Storing asset {0} {1}, bytes {2}", asset.Name, asset.FullID, asset.Data.Length);
@@ -200,4 +201,4 @@ namespace OpenSim.Services.AssetService
200 return m_Database.Delete(id); 201 return m_Database.Delete(id);
201 } 202 }
202 } 203 }
203} \ No newline at end of file 204}
diff --git a/OpenSim/Services/AssetService/Properties/AssemblyInfo.cs b/OpenSim/Services/AssetService/Properties/AssemblyInfo.cs
index 1509400..63654a6 100644
--- a/OpenSim/Services/AssetService/Properties/AssemblyInfo.cs
+++ b/OpenSim/Services/AssetService/Properties/AssemblyInfo.cs
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
29// Build Number 29// Build Number
30// Revision 30// Revision
31// 31//
32[assembly: AssemblyVersion("0.7.5.*")] 32[assembly: AssemblyVersion("0.8.3.*")]
33[assembly: AssemblyFileVersion("1.0.0.0")] 33
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;
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>
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}
diff --git a/OpenSim/Services/AssetService/XAssetServiceBase.cs b/OpenSim/Services/AssetService/XAssetServiceBase.cs
index 0c5c2c3..c118c9d 100644
--- a/OpenSim/Services/AssetService/XAssetServiceBase.cs
+++ b/OpenSim/Services/AssetService/XAssetServiceBase.cs
@@ -27,9 +27,11 @@
27 27
28using System; 28using System;
29using System.Reflection; 29using System.Reflection;
30using log4net;
30using Nini.Config; 31using Nini.Config;
31using OpenSim.Framework; 32using OpenSim.Framework;
32using OpenSim.Data; 33using OpenSim.Data;
34using OpenSim.Server.Base;
33using OpenSim.Services.Interfaces; 35using OpenSim.Services.Interfaces;
34using OpenSim.Services.Base; 36using OpenSim.Services.Base;
35 37
@@ -37,10 +39,15 @@ namespace OpenSim.Services.AssetService
37{ 39{
38 public class XAssetServiceBase : ServiceBase 40 public class XAssetServiceBase : ServiceBase
39 { 41 {
40 protected IXAssetDataPlugin m_Database = null; 42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
41 protected IAssetLoader m_AssetLoader = null;
42 43
43 public XAssetServiceBase(IConfigSource config) : base(config) 44 protected IXAssetDataPlugin m_Database;
45 protected IAssetLoader m_AssetLoader;
46 protected IAssetService m_ChainedAssetService;
47
48 protected bool HasChainedAssetService { get { return m_ChainedAssetService != null; } }
49
50 public XAssetServiceBase(IConfigSource config, string configName) : base(config)
44 { 51 {
45 string dllName = String.Empty; 52 string dllName = String.Empty;
46 string connString = String.Empty; 53 string connString = String.Empty;
@@ -48,7 +55,7 @@ namespace OpenSim.Services.AssetService
48 // 55 //
49 // Try reading the [AssetService] section first, if it exists 56 // Try reading the [AssetService] section first, if it exists
50 // 57 //
51 IConfig assetConfig = config.Configs["AssetService"]; 58 IConfig assetConfig = config.Configs[configName];
52 if (assetConfig != null) 59 if (assetConfig != null)
53 { 60 {
54 dllName = assetConfig.GetString("StorageProvider", dllName); 61 dllName = assetConfig.GetString("StorageProvider", dllName);
@@ -77,17 +84,35 @@ namespace OpenSim.Services.AssetService
77 if (m_Database == null) 84 if (m_Database == null)
78 throw new Exception("Could not find a storage interface in the given module"); 85 throw new Exception("Could not find a storage interface in the given module");
79 86
80 m_Database.Initialise(connString); 87 string chainedAssetServiceDesignator = assetConfig.GetString("ChainedServiceModule", null);
88
89 if (chainedAssetServiceDesignator != null)
90 {
91 m_log.InfoFormat(
92 "[XASSET SERVICE BASE]: Loading chained asset service from {0}", chainedAssetServiceDesignator);
81 93
82 string loaderName = assetConfig.GetString("DefaultAssetLoader", 94 Object[] args = new Object[] { config, configName };
83 String.Empty); 95 m_ChainedAssetService = ServerUtils.LoadPlugin<IAssetService>(chainedAssetServiceDesignator, args);
84 96
85 if (loaderName != String.Empty) 97 if (!HasChainedAssetService)
98 throw new Exception(
99 String.Format("Failed to load ChainedAssetService from {0}", chainedAssetServiceDesignator));
100 }
101
102 m_Database.Initialise(connString);
103
104 if (HasChainedAssetService)
86 { 105 {
87 m_AssetLoader = LoadPlugin<IAssetLoader>(loaderName); 106 string loaderName = assetConfig.GetString("DefaultAssetLoader",
107 String.Empty);
108
109 if (loaderName != String.Empty)
110 {
111 m_AssetLoader = LoadPlugin<IAssetLoader>(loaderName);
88 112
89 if (m_AssetLoader == null) 113 if (m_AssetLoader == null)
90 throw new Exception("Asset loader could not be loaded"); 114 throw new Exception("Asset loader could not be loaded");
115 }
91 } 116 }
92 } 117 }
93 } 118 }