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