clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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  
28 using System;
29 using System.Collections.Generic;
30 using System.IO;
31 using System.Reflection;
32 using System.Text;
33 using System.Text.RegularExpressions;
34 using System.Threading;
35 using System.Timers;
36 using log4net;
37 using log4net.Appender;
38 using log4net.Core;
39 using log4net.Repository;
40 using OpenMetaverse;
41 using OpenMetaverse.StructuredData;
42 using OpenSim.Framework;
43 using OpenSim.Framework.Console;
44 using OpenSim.Framework.Monitoring;
45 using OpenSim.Framework.Servers;
46 using OpenSim.Framework.Servers.HttpServer;
47 using Timer=System.Timers.Timer;
48 using Nini.Config;
49  
50 namespace OpenSim.Framework.Servers
51 {
52 /// <summary>
53 /// Common base for the main OpenSimServers (user, grid, inventory, region, etc)
54 /// </summary>
55 public abstract class BaseOpenSimServer : ServerBase
56 {
57 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
58  
59 /// <summary>
60 /// Used by tests to suppress Environment.Exit(0) so that post-run operations are possible.
61 /// </summary>
62 public bool SuppressExit { get; set; }
63  
64 /// <summary>
65 /// This will control a periodic log printout of the current 'show stats' (if they are active) for this
66 /// server.
67 /// </summary>
68 private int m_periodDiagnosticTimerMS = 60 * 60 * 1000;
69 private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000);
70  
71 /// <summary>
72 /// Random uuid for private data
73 /// </summary>
74 protected string m_osSecret = String.Empty;
75  
76 protected BaseHttpServer m_httpServer;
77 public BaseHttpServer HttpServer
78 {
79 get { return m_httpServer; }
80 }
81  
82 public BaseOpenSimServer() : base()
83 {
84 // Random uuid for private data
85 m_osSecret = UUID.Random().ToString();
86  
87 }
88  
89 /// <summary>
90 /// Must be overriden by child classes for their own server specific startup behaviour.
91 /// </summary>
92 protected virtual void StartupSpecific()
93 {
94 StatsManager.SimExtraStats = new SimExtraStatsCollector();
95 RegisterCommonCommands();
96 RegisterCommonComponents(Config);
97  
98 IConfig startupConfig = Config.Configs["Startup"];
99 int logShowStatsSeconds = startupConfig.GetInt("LogShowStatsSeconds", m_periodDiagnosticTimerMS / 1000);
100 m_periodDiagnosticTimerMS = logShowStatsSeconds * 1000;
101 m_periodicDiagnosticsTimer.Elapsed += new ElapsedEventHandler(LogDiagnostics);
102 if (m_periodDiagnosticTimerMS != 0)
103 {
104 m_periodicDiagnosticsTimer.Interval = m_periodDiagnosticTimerMS;
105 m_periodicDiagnosticsTimer.Enabled = true;
106 }
107 }
108  
109 protected override void ShutdownSpecific()
110 {
111 m_log.Info("[SHUTDOWN]: Shutdown processing on main thread complete. Exiting...");
112  
113 RemovePIDFile();
114  
115 base.ShutdownSpecific();
116  
117 if (!SuppressExit)
118 Environment.Exit(0);
119 }
120  
121 /// <summary>
122 /// Provides a list of help topics that are available. Overriding classes should append their topics to the
123 /// information returned when the base method is called.
124 /// </summary>
125 ///
126 /// <returns>
127 /// A list of strings that represent different help topics on which more information is available
128 /// </returns>
129 protected virtual List<string> GetHelpTopics() { return new List<string>(); }
130  
131 /// <summary>
132 /// Print statistics to the logfile, if they are active
133 /// </summary>
134 protected void LogDiagnostics(object source, ElapsedEventArgs e)
135 {
136 StringBuilder sb = new StringBuilder("DIAGNOSTICS\n\n");
137 sb.Append(GetUptimeReport());
138 sb.Append(StatsManager.SimExtraStats.Report());
139 sb.Append(Environment.NewLine);
140 sb.Append(GetThreadsReport());
141  
142 m_log.Debug(sb);
143 }
144  
145 /// <summary>
146 /// Performs initialisation of the scene, such as loading configuration from disk.
147 /// </summary>
148 public virtual void Startup()
149 {
150 StartupSpecific();
151  
152 TimeSpan timeTaken = DateTime.Now - m_startuptime;
153  
154 MainConsole.Instance.OutputFormat(
155 "PLEASE WAIT FOR LOGINS TO BE ENABLED ON REGIONS ONCE SCRIPTS HAVE STARTED. Non-script portion of startup took {0}m {1}s.",
156 timeTaken.Minutes, timeTaken.Seconds);
157 }
158  
159 public string osSecret
160 {
161 // Secret uuid for the simulator
162 get { return m_osSecret; }
163 }
164  
165 public string StatReport(IOSHttpRequest httpRequest)
166 {
167 // If we catch a request for "callback", wrap the response in the value for jsonp
168 if (httpRequest.Query.ContainsKey("callback"))
169 {
170 return httpRequest.Query["callback"].ToString() + "(" + StatsManager.SimExtraStats.XReport((DateTime.Now - m_startuptime).ToString() , m_version) + ");";
171 }
172 else
173 {
174 return StatsManager.SimExtraStats.XReport((DateTime.Now - m_startuptime).ToString() , m_version);
175 }
176 }
177 }
178 }