diff options
author | Mike Mazur | 2009-02-16 02:27:34 +0000 |
---|---|---|
committer | Mike Mazur | 2009-02-16 02:27:34 +0000 |
commit | 529dd66ed01f598696ef8d20b465b911931d6fe8 (patch) | |
tree | 5bde49aaa0be88479d118b09c465af13538f1139 /OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs | |
parent | - asset server functionality works with OpenSim's HttpServer (diff) | |
download | opensim-SC-529dd66ed01f598696ef8d20b465b911931d6fe8.zip opensim-SC-529dd66ed01f598696ef8d20b465b911931d6fe8.tar.gz opensim-SC-529dd66ed01f598696ef8d20b465b911931d6fe8.tar.bz2 opensim-SC-529dd66ed01f598696ef8d20b465b911931d6fe8.tar.xz |
- remove dependency on ExtensionLoader.dll (DBConnString.cs can go)
- bring config system in line with other servers
- add new plugin filter class which filters on ID
- update AssetInventoryServer.ini file
Diffstat (limited to 'OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs')
-rw-r--r-- | OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs | 155 |
1 files changed, 25 insertions, 130 deletions
diff --git a/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs b/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs index bd05d59..f6d46e8 100644 --- a/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs +++ b/OpenSim/Grid/AssetInventoryServer/AssetInventoryServer.cs | |||
@@ -32,11 +32,6 @@ using System.Collections.Generic; | |||
32 | using System.IO; | 32 | using System.IO; |
33 | using System.Net; | 33 | using System.Net; |
34 | using System.Reflection; | 34 | using System.Reflection; |
35 | using System.Security.Cryptography.X509Certificates; | ||
36 | using System.ServiceProcess; | ||
37 | using ExtensionLoader; | ||
38 | using ExtensionLoader.Config; | ||
39 | //using HttpServer; | ||
40 | using log4net; | 35 | using log4net; |
41 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
42 | using OpenSim.Framework.Servers; | 37 | using OpenSim.Framework.Servers; |
@@ -44,12 +39,11 @@ using OpenSim.Framework.Console; | |||
44 | 39 | ||
45 | namespace OpenSim.Grid.AssetInventoryServer | 40 | namespace OpenSim.Grid.AssetInventoryServer |
46 | { | 41 | { |
47 | public class AssetInventoryServer : BaseOpenSimServer//ServiceBase | 42 | public class AssetInventoryServer : BaseOpenSimServer |
48 | { | 43 | { |
49 | public const string CONFIG_FILE = "AssetInventoryServer.ini"; | 44 | public const string CONFIG_FILE = "AssetInventoryServer.ini"; |
50 | 45 | ||
51 | //public WebServer HttpServer; | 46 | public AssetInventoryConfig ConfigFile; |
52 | public IniConfigSource ConfigFile; | ||
53 | 47 | ||
54 | public IAssetStorageProvider StorageProvider; | 48 | public IAssetStorageProvider StorageProvider; |
55 | public IInventoryStorageProvider InventoryProvider; | 49 | public IInventoryStorageProvider InventoryProvider; |
@@ -57,72 +51,39 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
57 | public IAuthorizationProvider AuthorizationProvider; | 51 | public IAuthorizationProvider AuthorizationProvider; |
58 | public IMetricsProvider MetricsProvider; | 52 | public IMetricsProvider MetricsProvider; |
59 | 53 | ||
60 | private List<IAssetInventoryServerPlugin> frontends = new List<IAssetInventoryServerPlugin>(); | 54 | private List<IAssetInventoryServerPlugin> m_frontends = new List<IAssetInventoryServerPlugin>(); |
61 | private List<IAssetInventoryServerPlugin> backends = new List<IAssetInventoryServerPlugin>(); | 55 | private List<IAssetInventoryServerPlugin> m_backends = new List<IAssetInventoryServerPlugin>(); |
62 | 56 | ||
63 | public AssetInventoryServer() | 57 | public AssetInventoryServer() |
64 | { | 58 | { |
65 | m_console = new ConsoleBase("Asset"); | 59 | m_console = new ConsoleBase("Asset"); |
66 | MainConsole.Instance = m_console; | 60 | MainConsole.Instance = m_console; |
67 | //this.ServiceName = "OpenSimAssetInventoryServer"; | ||
68 | } | 61 | } |
69 | 62 | ||
70 | public bool Start() | 63 | public bool Start() |
71 | { | 64 | { |
72 | Logger.Log.Info("Starting Asset Server"); | 65 | Logger.Log.Info("Starting Asset Server"); |
73 | List<string> extensionList = null; | 66 | uint port = 0; |
74 | int port = 0; | ||
75 | X509Certificate2 serverCert = null; | ||
76 | 67 | ||
77 | try { ConfigFile = new IniConfigSource(CONFIG_FILE); } | 68 | try { ConfigFile = new AssetInventoryConfig("AssetInventory Server", (Path.Combine(Util.configDir(), "AssetInventoryServer.ini"))); } |
78 | catch (Exception) | 69 | catch (Exception) |
79 | { | 70 | { |
80 | Logger.Log.Error("Failed to load the config file " + CONFIG_FILE); | 71 | Logger.Log.Error("Failed to load the config file " + CONFIG_FILE); |
81 | return false; | 72 | return false; |
82 | } | 73 | } |
83 | 74 | ||
84 | try | 75 | StorageProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/StorageProvider", ConfigFile.AssetStorageProvider) as IAssetStorageProvider; |
85 | { | 76 | m_backends.Add(StorageProvider); |
86 | IConfig extensionConfig = ConfigFile.Configs["Config"]; | ||
87 | |||
88 | // Load the port number to listen on | ||
89 | port = extensionConfig.GetInt("ListenPort"); | ||
90 | |||
91 | // Load the server certificate file | ||
92 | string certFile = extensionConfig.GetString("SSLCertFile"); | ||
93 | if (!String.IsNullOrEmpty(certFile)) | ||
94 | serverCert = new X509Certificate2(certFile); | ||
95 | } | ||
96 | catch (Exception) | ||
97 | { | ||
98 | Logger.Log.Error("Failed to load [Config] section from " + CONFIG_FILE); | ||
99 | return false; | ||
100 | } | ||
101 | |||
102 | try | ||
103 | { | ||
104 | // Load the extension list (and ordering) from our config file | ||
105 | IConfig extensionConfig = ConfigFile.Configs["Extensions"]; | ||
106 | extensionList = new List<string>(extensionConfig.GetKeys()); | ||
107 | } | ||
108 | catch (Exception) | ||
109 | { | ||
110 | Logger.Log.Error("Failed to load [Extensions] section from " + CONFIG_FILE); | ||
111 | return false; | ||
112 | } | ||
113 | |||
114 | StorageProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/StorageProvider", "OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.dll") as IAssetStorageProvider; | ||
115 | backends.Add(StorageProvider); | ||
116 | 77 | ||
117 | InventoryProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/InventoryProvider", "OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim.dll") as IInventoryStorageProvider; | 78 | InventoryProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/InventoryProvider", ConfigFile.InventoryStorageProvider) as IInventoryStorageProvider; |
118 | backends.Add(InventoryProvider); | 79 | m_backends.Add(InventoryProvider); |
119 | 80 | ||
120 | MetricsProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/MetricsProvider", String.Empty) as IMetricsProvider; | 81 | MetricsProvider = LoadAssetInventoryServerPlugins("/OpenSim/AssetInventoryServer/MetricsProvider", ConfigFile.MetricsProvider) as IMetricsProvider; |
121 | backends.Add(MetricsProvider); | 82 | m_backends.Add(MetricsProvider); |
122 | 83 | ||
123 | try | 84 | try |
124 | { | 85 | { |
125 | InitHttpServer(port, serverCert); | 86 | InitHttpServer(ConfigFile.HttpPort); |
126 | } | 87 | } |
127 | catch (Exception ex) | 88 | catch (Exception ex) |
128 | { | 89 | { |
@@ -131,13 +92,13 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
131 | return false; | 92 | return false; |
132 | } | 93 | } |
133 | 94 | ||
134 | frontends.AddRange(LoadAssetInventoryServerPlugins("/OpenSim/AssetInventoryServer/Frontend", String.Empty)); | 95 | AuthenticationProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/AuthenticationProvider", ConfigFile.AuthenticationProvider) as IAuthenticationProvider; |
96 | m_backends.Add(AuthenticationProvider); | ||
135 | 97 | ||
136 | AuthenticationProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/AuthenticationProvider", String.Empty) as IAuthenticationProvider; | 98 | AuthorizationProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/AuthorizationProvider", ConfigFile.AuthorizationProvider) as IAuthorizationProvider; |
137 | backends.Add(AuthenticationProvider); | 99 | m_backends.Add(AuthorizationProvider); |
138 | 100 | ||
139 | AuthorizationProvider = LoadAssetInventoryServerPlugin("/OpenSim/AssetInventoryServer/AuthorizationProvider", String.Empty) as IAuthorizationProvider; | 101 | m_frontends.AddRange(LoadAssetInventoryServerPlugins("/OpenSim/AssetInventoryServer/Frontend", ConfigFile.Frontends)); |
140 | backends.Add(AuthorizationProvider); | ||
141 | 102 | ||
142 | return true; | 103 | return true; |
143 | } | 104 | } |
@@ -154,7 +115,7 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
154 | 115 | ||
155 | public override void ShutdownSpecific() | 116 | public override void ShutdownSpecific() |
156 | { | 117 | { |
157 | foreach (IAssetInventoryServerPlugin plugin in frontends) | 118 | foreach (IAssetInventoryServerPlugin plugin in m_frontends) |
158 | { | 119 | { |
159 | Logger.Log.Debug("Disposing plugin " + plugin.Name); | 120 | Logger.Log.Debug("Disposing plugin " + plugin.Name); |
160 | try { plugin.Dispose(); } | 121 | try { plugin.Dispose(); } |
@@ -162,7 +123,7 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
162 | { Logger.Log.ErrorFormat("Failure shutting down plugin {0}: {1}", plugin.Name, ex.Message); } | 123 | { Logger.Log.ErrorFormat("Failure shutting down plugin {0}: {1}", plugin.Name, ex.Message); } |
163 | } | 124 | } |
164 | 125 | ||
165 | foreach (IAssetInventoryServerPlugin plugin in backends) | 126 | foreach (IAssetInventoryServerPlugin plugin in m_backends) |
166 | { | 127 | { |
167 | Logger.Log.Debug("Disposing plugin " + plugin.Name); | 128 | Logger.Log.Debug("Disposing plugin " + plugin.Name); |
168 | try { plugin.Dispose(); } | 129 | try { plugin.Dispose(); } |
@@ -174,47 +135,14 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
174 | HttpServer.Stop(); | 135 | HttpServer.Stop(); |
175 | } | 136 | } |
176 | 137 | ||
177 | void InitHttpServer(int port, X509Certificate serverCert) | 138 | void InitHttpServer(uint port) |
178 | { | 139 | { |
179 | //if (serverCert != null) | 140 | m_httpServer = new BaseHttpServer(port); |
180 | // HttpServer = new WebServer(IPAddress.Any, port, serverCert, null, false); | 141 | m_httpServer.Start(); |
181 | //else | ||
182 | // HttpServer = new WebServer(IPAddress.Any, port); | ||
183 | |||
184 | //HttpServer.LogWriter = new log4netLogWriter(Logger.Log); | ||
185 | |||
186 | //HttpServer.Set404Handler( | ||
187 | // delegate(IHttpClientContext client, IHttpRequest request, IHttpResponse response) | ||
188 | // { | ||
189 | // Logger.Log.Warn("Requested page was not found: " + request.Uri.PathAndQuery); | ||
190 | |||
191 | // string notFoundString = "<html><head><title>Page Not Found</title></head><body>The requested page or method was not found</body></html>"; | ||
192 | // byte[] buffer = System.Text.Encoding.UTF8.GetBytes(notFoundString); | ||
193 | // response.Body.Write(buffer, 0, buffer.Length); | ||
194 | // response.Status = HttpStatusCode.NotFound; | ||
195 | // return true; | ||
196 | // } | ||
197 | //); | ||
198 | |||
199 | m_httpServer = new BaseHttpServer(8003); | ||
200 | HttpServer.Start(); | ||
201 | 142 | ||
202 | Logger.Log.Info("Asset server is listening on port " + port); | 143 | Logger.Log.Info("Asset server is listening on port " + port); |
203 | } | 144 | } |
204 | 145 | ||
205 | #region ServiceBase Overrides | ||
206 | |||
207 | //protected override void OnStart(string[] args) | ||
208 | //{ | ||
209 | // Start(); | ||
210 | //} | ||
211 | //protected override void OnStop() | ||
212 | //{ | ||
213 | // Shutdown(); | ||
214 | //} | ||
215 | |||
216 | #endregion | ||
217 | |||
218 | private IAssetInventoryServerPlugin LoadAssetInventoryServerPlugin(string addinPath, string provider) | 146 | private IAssetInventoryServerPlugin LoadAssetInventoryServerPlugin(string addinPath, string provider) |
219 | { | 147 | { |
220 | PluginLoader<IAssetInventoryServerPlugin> loader = new PluginLoader<IAssetInventoryServerPlugin>(new AssetInventoryServerPluginInitialiser(this)); | 148 | PluginLoader<IAssetInventoryServerPlugin> loader = new PluginLoader<IAssetInventoryServerPlugin>(new AssetInventoryServerPluginInitialiser(this)); |
@@ -222,7 +150,7 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
222 | if (provider == String.Empty) | 150 | if (provider == String.Empty) |
223 | loader.Add(addinPath); | 151 | loader.Add(addinPath); |
224 | else | 152 | else |
225 | loader.Add(addinPath, new PluginProviderFilter(provider)); | 153 | loader.Add(addinPath, new PluginIdFilter(provider)); |
226 | //loader.Add(addinPath, new PluginCountConstraint(1)); | 154 | //loader.Add(addinPath, new PluginCountConstraint(1)); |
227 | 155 | ||
228 | loader.Load(); | 156 | loader.Load(); |
@@ -237,7 +165,7 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
237 | if (provider == String.Empty) | 165 | if (provider == String.Empty) |
238 | loader.Add(addinPath); | 166 | loader.Add(addinPath); |
239 | else | 167 | else |
240 | loader.Add(addinPath, new PluginProviderFilter(provider)); | 168 | loader.Add(addinPath, new PluginIdFilter(provider)); |
241 | //loader.Add(addinPath, new PluginCountConstraint(1)); | 169 | //loader.Add(addinPath, new PluginCountConstraint(1)); |
242 | 170 | ||
243 | loader.Load(); | 171 | loader.Load(); |
@@ -245,37 +173,4 @@ namespace OpenSim.Grid.AssetInventoryServer | |||
245 | return loader.Plugins; | 173 | return loader.Plugins; |
246 | } | 174 | } |
247 | } | 175 | } |
248 | |||
249 | //public class log4netLogWriter : ILogWriter | ||
250 | //{ | ||
251 | // ILog Log; | ||
252 | |||
253 | // public log4netLogWriter(ILog log) | ||
254 | // { | ||
255 | // Log = log; | ||
256 | // } | ||
257 | |||
258 | // public void Write(object source, LogPrio prio, string message) | ||
259 | // { | ||
260 | // switch (prio) | ||
261 | // { | ||
262 | // case LogPrio.Trace: | ||
263 | // case LogPrio.Debug: | ||
264 | // Log.DebugFormat("{0}: {1}", source, message); | ||
265 | // break; | ||
266 | // case LogPrio.Info: | ||
267 | // Log.InfoFormat("{0}: {1}", source, message); | ||
268 | // break; | ||
269 | // case LogPrio.Warning: | ||
270 | // Log.WarnFormat("{0}: {1}", source, message); | ||
271 | // break; | ||
272 | // case LogPrio.Error: | ||
273 | // Log.ErrorFormat("{0}: {1}", source, message); | ||
274 | // break; | ||
275 | // case LogPrio.Fatal: | ||
276 | // Log.FatalFormat("{0}: {1}", source, message); | ||
277 | // break; | ||
278 | // } | ||
279 | // } | ||
280 | //} | ||
281 | } | 176 | } |