aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/AssetService
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/AssetService/AssetService.cs204
-rw-r--r--OpenSim/Services/AssetService/AssetServiceBase.cs103
-rw-r--r--OpenSim/Services/AssetService/Properties/AssemblyInfo.cs33
-rw-r--r--OpenSim/Services/AssetService/XAssetService.cs227
-rw-r--r--OpenSim/Services/AssetService/XAssetServiceBase.cs119
5 files changed, 686 insertions, 0 deletions
diff --git a/OpenSim/Services/AssetService/AssetService.cs b/OpenSim/Services/AssetService/AssetService.cs
new file mode 100644
index 0000000..0aefa16
--- /dev/null
+++ b/OpenSim/Services/AssetService/AssetService.cs
@@ -0,0 +1,204 @@
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 public class AssetService : AssetServiceBase, IAssetService
42 {
43 private static readonly ILog m_log =
44 LogManager.GetLogger(
45 MethodBase.GetCurrentMethod().DeclaringType);
46
47 protected static AssetService m_RootInstance;
48
49 public AssetService(IConfigSource config)
50 : this(config, "AssetService")
51 {
52 }
53
54 public AssetService(IConfigSource config, string configName) : base(config, configName)
55 {
56 if (m_RootInstance == null)
57 {
58 m_RootInstance = this;
59
60 if (m_AssetLoader != null)
61 {
62 IConfig assetConfig = config.Configs[m_ConfigName];
63 if (assetConfig == null)
64 throw new Exception("No " + m_ConfigName + " configuration");
65
66 string loaderArgs = assetConfig.GetString("AssetLoaderArgs",
67 String.Empty);
68
69 bool assetLoaderEnabled = assetConfig.GetBoolean("AssetLoaderEnabled", true);
70
71 if (assetLoaderEnabled)
72 {
73 m_log.DebugFormat("[ASSET SERVICE]: Loading default asset set from {0}", loaderArgs);
74
75 m_AssetLoader.ForEachDefaultXmlAsset(
76 loaderArgs,
77 delegate(AssetBase a)
78 {
79 AssetBase existingAsset = Get(a.ID);
80// AssetMetadata existingMetadata = GetMetadata(a.ID);
81
82 if (existingAsset == null || Util.SHA1Hash(existingAsset.Data) != Util.SHA1Hash(a.Data))
83 {
84// m_log.DebugFormat("[ASSET]: Storing {0} {1}", a.Name, a.ID);
85 Store(a);
86 }
87 });
88 }
89
90 m_log.Debug("[ASSET SERVICE]: Local asset service enabled");
91 }
92 }
93 }
94
95 public virtual AssetBase Get(string id)
96 {
97// m_log.DebugFormat("[ASSET SERVICE]: Get asset for {0}", id);
98
99 UUID assetID;
100
101 if (!UUID.TryParse(id, out assetID))
102 {
103 m_log.WarnFormat("[ASSET SERVICE]: Could not parse requested asset id {0}", id);
104 return null;
105 }
106
107 try
108 {
109 return m_Database.GetAsset(assetID);
110 }
111 catch (Exception e)
112 {
113 m_log.ErrorFormat("[ASSET SERVICE]: Exception getting asset {0} {1}", assetID, e);
114 return null;
115 }
116 }
117
118 public virtual AssetBase GetCached(string id)
119 {
120 return Get(id);
121 }
122
123 public virtual AssetMetadata GetMetadata(string id)
124 {
125// m_log.DebugFormat("[ASSET SERVICE]: Get asset metadata for {0}", id);
126
127 AssetBase asset = Get(id);
128
129 if (asset != null)
130 return asset.Metadata;
131 else
132 return null;
133 }
134
135 public virtual byte[] GetData(string id)
136 {
137// m_log.DebugFormat("[ASSET SERVICE]: Get asset data for {0}", id);
138
139 AssetBase asset = Get(id);
140
141 if (asset != null)
142 return asset.Data;
143 else
144 return null;
145 }
146
147 public virtual bool Get(string id, Object sender, AssetRetrieved handler)
148 {
149 //m_log.DebugFormat("[AssetService]: Get asset async {0}", id);
150
151 handler(id, sender, Get(id));
152
153 return true;
154 }
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)
171 {
172 bool exists = m_Database.AssetsExist(new[] { asset.FullID })[0];
173 if (!exists)
174 {
175// m_log.DebugFormat(
176// "[ASSET SERVICE]: Storing asset {0} {1}, bytes {2}", asset.Name, asset.FullID, asset.Data.Length);
177 m_Database.StoreAsset(asset);
178 }
179// else
180// {
181// m_log.DebugFormat(
182// "[ASSET SERVICE]: Not storing asset {0} {1}, bytes {2} as it already exists", asset.Name, asset.FullID, asset.Data.Length);
183// }
184
185 return asset.ID;
186 }
187
188 public bool UpdateContent(string id, byte[] data)
189 {
190 return false;
191 }
192
193 public virtual bool Delete(string id)
194 {
195// m_log.DebugFormat("[ASSET SERVICE]: Deleting asset {0}", id);
196
197 UUID assetID;
198 if (!UUID.TryParse(id, out assetID))
199 return false;
200
201 return m_Database.Delete(id);
202 }
203 }
204}
diff --git a/OpenSim/Services/AssetService/AssetServiceBase.cs b/OpenSim/Services/AssetService/AssetServiceBase.cs
new file mode 100644
index 0000000..58ab052
--- /dev/null
+++ b/OpenSim/Services/AssetService/AssetServiceBase.cs
@@ -0,0 +1,103 @@
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.Reflection;
30using Nini.Config;
31using OpenSim.Framework;
32using OpenSim.Data;
33using OpenSim.Services.Interfaces;
34using OpenSim.Services.Base;
35
36namespace OpenSim.Services.AssetService
37{
38 public class AssetServiceBase : ServiceBase
39 {
40 protected IAssetDataPlugin m_Database = null;
41 protected IAssetLoader m_AssetLoader = null;
42 protected string m_ConfigName = "AssetService";
43
44 public AssetServiceBase(IConfigSource config)
45 : this(config, "AssetService")
46 {
47 }
48
49 public AssetServiceBase(IConfigSource config, string configName) : base(config)
50 {
51 if (configName != string.Empty)
52 m_ConfigName = configName;
53
54 string dllName = String.Empty;
55 string connString = String.Empty;
56
57 //
58 // Try reading the [AssetService] section, if it exists
59 //
60 IConfig assetConfig = config.Configs[m_ConfigName];
61 if (assetConfig != null)
62 {
63 dllName = assetConfig.GetString("StorageProvider", dllName);
64 connString = assetConfig.GetString("ConnectionString", connString);
65 }
66
67 //
68 // Try reading the [DatabaseService] section, if it exists
69 //
70 IConfig dbConfig = config.Configs["DatabaseService"];
71 if (dbConfig != null)
72 {
73 if (dllName == String.Empty)
74 dllName = dbConfig.GetString("StorageProvider", String.Empty);
75 if (connString == String.Empty)
76 connString = dbConfig.GetString("ConnectionString", String.Empty);
77 }
78
79 //
80 // We tried, but this doesn't exist. We can't proceed.
81 //
82 if (dllName.Equals(String.Empty))
83 throw new Exception("No StorageProvider configured");
84
85 m_Database = LoadPlugin<IAssetDataPlugin>(dllName);
86 if (m_Database == null)
87 throw new Exception(string.Format("Could not find a storage interface in the module {0}", dllName));
88
89 m_Database.Initialise(connString);
90
91 string loaderName = assetConfig.GetString("DefaultAssetLoader",
92 String.Empty);
93
94 if (loaderName != String.Empty)
95 {
96 m_AssetLoader = LoadPlugin<IAssetLoader>(loaderName);
97
98 if (m_AssetLoader == null)
99 throw new Exception(string.Format("Asset loader could not be loaded from {0}", loaderName));
100 }
101 }
102 }
103}
diff --git a/OpenSim/Services/AssetService/Properties/AssemblyInfo.cs b/OpenSim/Services/AssetService/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..9717319
--- /dev/null
+++ b/OpenSim/Services/AssetService/Properties/AssemblyInfo.cs
@@ -0,0 +1,33 @@
1using System.Reflection;
2using System.Runtime.CompilerServices;
3using System.Runtime.InteropServices;
4
5// General Information about an assembly is controlled through the following
6// set of attributes. Change these attribute values to modify the information
7// associated with an assembly.
8[assembly: AssemblyTitle("OpenSim.Services.AssetService")]
9[assembly: AssemblyDescription("")]
10[assembly: AssemblyConfiguration("")]
11[assembly: AssemblyCompany("http://opensimulator.org")]
12[assembly: AssemblyProduct("OpenSim")]
13[assembly: AssemblyCopyright("OpenSimulator developers")]
14[assembly: AssemblyTrademark("")]
15[assembly: AssemblyCulture("")]
16
17// Setting ComVisible to false makes the types in this assembly not visible
18// to COM components. If you need to access a type in this assembly from
19// COM, set the ComVisible attribute to true on that type.
20[assembly: ComVisible(false)]
21
22// The following GUID is for the ID of the typelib if this project is exposed to COM
23[assembly: Guid("fe57c0df-6101-4c23-ae1a-7b3e937843f9")]
24
25// Version information for an assembly consists of the following four values:
26//
27// Major Version
28// Minor Version
29// Build Number
30// Revision
31//
32[assembly: AssemblyVersion("0.8.2.*")]
33
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}
diff --git a/OpenSim/Services/AssetService/XAssetServiceBase.cs b/OpenSim/Services/AssetService/XAssetServiceBase.cs
new file mode 100644
index 0000000..c118c9d
--- /dev/null
+++ b/OpenSim/Services/AssetService/XAssetServiceBase.cs
@@ -0,0 +1,119 @@
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.Reflection;
30using log4net;
31using Nini.Config;
32using OpenSim.Framework;
33using OpenSim.Data;
34using OpenSim.Server.Base;
35using OpenSim.Services.Interfaces;
36using OpenSim.Services.Base;
37
38namespace OpenSim.Services.AssetService
39{
40 public class XAssetServiceBase : ServiceBase
41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
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)
51 {
52 string dllName = String.Empty;
53 string connString = String.Empty;
54
55 //
56 // Try reading the [AssetService] section first, if it exists
57 //
58 IConfig assetConfig = config.Configs[configName];
59 if (assetConfig != null)
60 {
61 dllName = assetConfig.GetString("StorageProvider", dllName);
62 connString = assetConfig.GetString("ConnectionString", connString);
63 }
64
65 //
66 // Try reading the [DatabaseService] section, if it exists
67 //
68 IConfig dbConfig = config.Configs["DatabaseService"];
69 if (dbConfig != null)
70 {
71 if (dllName == String.Empty)
72 dllName = dbConfig.GetString("StorageProvider", String.Empty);
73 if (connString == String.Empty)
74 connString = dbConfig.GetString("ConnectionString", String.Empty);
75 }
76
77 //
78 // We tried, but this doesn't exist. We can't proceed.
79 //
80 if (dllName.Equals(String.Empty))
81 throw new Exception("No StorageProvider configured");
82
83 m_Database = LoadPlugin<IXAssetDataPlugin>(dllName);
84 if (m_Database == null)
85 throw new Exception("Could not find a storage interface in the given module");
86
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);
93
94 Object[] args = new Object[] { config, configName };
95 m_ChainedAssetService = ServerUtils.LoadPlugin<IAssetService>(chainedAssetServiceDesignator, args);
96
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)
105 {
106 string loaderName = assetConfig.GetString("DefaultAssetLoader",
107 String.Empty);
108
109 if (loaderName != String.Empty)
110 {
111 m_AssetLoader = LoadPlugin<IAssetLoader>(loaderName);
112
113 if (m_AssetLoader == null)
114 throw new Exception("Asset loader could not be loaded");
115 }
116 }
117 }
118 }
119} \ No newline at end of file