From 5c48d7a378ff066f59b9cee02f2803ebe1616481 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Thu, 22 Nov 2012 04:05:09 +0000
Subject: factor out common HandleShow code for "show uptime"
---
OpenSim/Framework/Console/CommandConsole.cs | 2 +-
OpenSim/Framework/Console/ConsoleBase.cs | 10 +-----
OpenSim/Framework/Console/MockConsole.cs | 7 +++-
OpenSim/Framework/ICommandConsole.cs | 5 +++
OpenSim/Framework/IConsole.cs | 2 +-
OpenSim/Framework/Servers/BaseOpenSimServer.cs | 39 +++-----------------
OpenSim/Framework/Servers/ServerBase.cs | 50 ++++++++++++++++++++++++++
OpenSim/Region/Application/OpenSimBase.cs | 2 +-
OpenSim/Server/Base/ServicesServerBase.cs | 18 ++--------
9 files changed, 72 insertions(+), 63 deletions(-)
diff --git a/OpenSim/Framework/Console/CommandConsole.cs b/OpenSim/Framework/Console/CommandConsole.cs
index bd23d1c..d1e29b4 100644
--- a/OpenSim/Framework/Console/CommandConsole.cs
+++ b/OpenSim/Framework/Console/CommandConsole.cs
@@ -711,7 +711,7 @@ namespace OpenSim.Framework.Console
///
public void Prompt()
{
- string line = ReadLine(m_defaultPrompt + "# ", true, true);
+ string line = ReadLine(DefaultPrompt + "# ", true, true);
if (line != String.Empty)
Output("Invalid command");
diff --git a/OpenSim/Framework/Console/ConsoleBase.cs b/OpenSim/Framework/Console/ConsoleBase.cs
index 4b375d9..2d8e723 100755
--- a/OpenSim/Framework/Console/ConsoleBase.cs
+++ b/OpenSim/Framework/Console/ConsoleBase.cs
@@ -43,15 +43,7 @@ namespace OpenSim.Framework.Console
public object ConsoleScene { get; set; }
- ///
- /// The default prompt text.
- ///
- public string DefaultPrompt
- {
- set { m_defaultPrompt = value; }
- get { return m_defaultPrompt; }
- }
- protected string m_defaultPrompt;
+ public string DefaultPrompt { get; set; }
public ConsoleBase(string defaultPrompt)
{
diff --git a/OpenSim/Framework/Console/MockConsole.cs b/OpenSim/Framework/Console/MockConsole.cs
index b489f93..8ba58e4 100644
--- a/OpenSim/Framework/Console/MockConsole.cs
+++ b/OpenSim/Framework/Console/MockConsole.cs
@@ -46,13 +46,18 @@ namespace OpenSim.Framework.Console
public ICommands Commands { get { return m_commands; } }
+ public string DefaultPrompt { get; set; }
+
public void Prompt() {}
public void RunCommand(string cmd) {}
public string ReadLine(string p, bool isCommand, bool e) { return ""; }
- public object ConsoleScene { get { return null; } }
+ public object ConsoleScene {
+ get { return null; }
+ set {}
+ }
public void Output(string text, string level) {}
public void Output(string text) {}
diff --git a/OpenSim/Framework/ICommandConsole.cs b/OpenSim/Framework/ICommandConsole.cs
index 8cd20da..a6573f8 100644
--- a/OpenSim/Framework/ICommandConsole.cs
+++ b/OpenSim/Framework/ICommandConsole.cs
@@ -83,6 +83,11 @@ namespace OpenSim.Framework
ICommands Commands { get; }
///
+ /// The default prompt text.
+ ///
+ string DefaultPrompt { get; set; }
+
+ ///
/// Display a command prompt on the console and wait for user input
///
void Prompt();
diff --git a/OpenSim/Framework/IConsole.cs b/OpenSim/Framework/IConsole.cs
index 33024b2..79560d8 100644
--- a/OpenSim/Framework/IConsole.cs
+++ b/OpenSim/Framework/IConsole.cs
@@ -32,7 +32,7 @@ namespace OpenSim.Framework
{
public interface IConsole
{
- object ConsoleScene { get; }
+ object ConsoleScene { get; set; }
void Output(string text, string level);
void Output(string text);
diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
index 6346279..4f9ac08 100644
--- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs
+++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
@@ -62,7 +62,6 @@ namespace OpenSim.Framework.Servers
///
private Timer m_periodicDiagnosticsTimer = new Timer(60 * 60 * 1000);
- protected CommandConsole m_console;
protected OpenSimAppender m_consoleAppender;
protected IAppender m_logFileAppender = null;
@@ -139,7 +138,8 @@ namespace OpenSim.Framework.Servers
}
else
{
- m_consoleAppender.Console = m_console;
+ // FIXME: This should be done through an interface rather than casting.
+ m_consoleAppender.Console = (ConsoleBase)m_console;
// If there is no threshold set then the threshold is effectively everything.
if (null == m_consoleAppender.Threshold)
@@ -367,8 +367,10 @@ namespace OpenSim.Framework.Servers
}
}
- public virtual void HandleShow(string module, string[] cmd)
+ public override void HandleShow(string module, string[] cmd)
{
+ base.HandleShow(module, cmd);
+
List args = new List(cmd);
args.RemoveAt(0);
@@ -385,10 +387,6 @@ namespace OpenSim.Framework.Servers
Notice(GetThreadsReport());
break;
- case "uptime":
- Notice(GetUptimeReport());
- break;
-
case "version":
Notice(GetVersionText());
break;
@@ -430,33 +428,6 @@ namespace OpenSim.Framework.Servers
}
///
- /// Console output is only possible if a console has been established.
- /// That is something that cannot be determined within this class. So
- /// all attempts to use the console MUST be verified.
- ///
- ///
- protected void Notice(string msg)
- {
- if (m_console != null)
- {
- m_console.Output(msg);
- }
- }
-
- ///
- /// Console output is only possible if a console has been established.
- /// That is something that cannot be determined within this class. So
- /// all attempts to use the console MUST be verified.
- ///
- ///
- ///
- protected void Notice(string format, params string[] components)
- {
- if (m_console != null)
- m_console.OutputFormat(format, components);
- }
-
- ///
/// Enhance the version string with extra information if it's available.
///
protected void EnhanceVersionInformation()
diff --git a/OpenSim/Framework/Servers/ServerBase.cs b/OpenSim/Framework/Servers/ServerBase.cs
index d19234b..afe1f73 100644
--- a/OpenSim/Framework/Servers/ServerBase.cs
+++ b/OpenSim/Framework/Servers/ServerBase.cs
@@ -26,13 +26,20 @@
*/
using System;
+using System.Collections.Generic;
using System.Text;
+using OpenSim.Framework.Console;
namespace OpenSim.Framework.Servers
{
public class ServerBase
{
///
+ /// Console to be used for any command line output. Can be null, in which case there should be no output.
+ ///
+ protected ICommandConsole m_console;
+
+ ///
/// Time at which this server was started
///
protected DateTime m_startuptime;
@@ -42,6 +49,22 @@ namespace OpenSim.Framework.Servers
m_startuptime = DateTime.Now;
}
+ public virtual void HandleShow(string module, string[] cmd)
+ {
+ List args = new List(cmd);
+
+ args.RemoveAt(0);
+
+ string[] showParams = args.ToArray();
+
+ switch (showParams[0])
+ {
+ case "uptime":
+ Notice(GetUptimeReport());
+ break;
+ }
+ }
+
///
/// Return a report about the uptime of this server
///
@@ -54,5 +77,32 @@ namespace OpenSim.Framework.Servers
return sb.ToString();
}
+
+ ///
+ /// Console output is only possible if a console has been established.
+ /// That is something that cannot be determined within this class. So
+ /// all attempts to use the console MUST be verified.
+ ///
+ ///
+ protected void Notice(string msg)
+ {
+ if (m_console != null)
+ {
+ m_console.Output(msg);
+ }
+ }
+
+ ///
+ /// Console output is only possible if a console has been established.
+ /// That is something that cannot be determined within this class. So
+ /// all attempts to use the console MUST be verified.
+ ///
+ ///
+ ///
+ protected void Notice(string format, params string[] components)
+ {
+ if (m_console != null)
+ m_console.OutputFormat(format, components);
+ }
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs
index 808c760..618ce0a 100644
--- a/OpenSim/Region/Application/OpenSimBase.cs
+++ b/OpenSim/Region/Application/OpenSimBase.cs
@@ -242,7 +242,7 @@ namespace OpenSim
}
}
- protected virtual void AddPluginCommands(CommandConsole console)
+ protected virtual void AddPluginCommands(ICommandConsole console)
{
List topics = GetHelpTopics();
diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs
index 56bb7ae..7b49ac9 100644
--- a/OpenSim/Server/Base/ServicesServerBase.cs
+++ b/OpenSim/Server/Base/ServicesServerBase.cs
@@ -174,6 +174,8 @@ namespace OpenSim.Server.Base
MainConsole.Instance = new LocalConsole(prompt);
}
+ m_console = MainConsole.Instance;
+
// Configure the appenders for log4net
//
OpenSimAppender consoleAppender = null;
@@ -351,21 +353,5 @@ namespace OpenSim.Server.Base
{
}
}
-
- public virtual void HandleShow(string module, string[] cmd)
- {
- List args = new List(cmd);
-
- args.RemoveAt(0);
-
- string[] showParams = args.ToArray();
-
- switch (showParams[0])
- {
- case "uptime":
- MainConsole.Instance.Output(GetUptimeReport());
- break;
- }
- }
}
}
\ No newline at end of file
--
cgit v1.1
From cf03d6ea9223e71c27ca91633a30abcf1368ec58 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Thu, 22 Nov 2012 04:11:03 +0000
Subject: Factor out common registration of "show uptime" command
---
OpenSim/Framework/Servers/BaseOpenSimServer.cs | 130 ++++++++++++-------------
OpenSim/Framework/Servers/ServerBase.cs | 12 +++
OpenSim/Server/Base/ServicesServerBase.cs | 7 +-
3 files changed, 78 insertions(+), 71 deletions(-)
diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
index 4f9ac08..019b68b 100644
--- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs
+++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
@@ -118,78 +118,76 @@ namespace OpenSim.Framework.Servers
///
protected virtual void StartupSpecific()
{
- if (m_console != null)
- {
- ILoggerRepository repository = LogManager.GetRepository();
- IAppender[] appenders = repository.GetAppenders();
+ if (m_console == null)
+ return;
- foreach (IAppender appender in appenders)
- {
- if (appender.Name == "Console")
- {
- m_consoleAppender = (OpenSimAppender)appender;
- break;
- }
- }
+ ILoggerRepository repository = LogManager.GetRepository();
+ IAppender[] appenders = repository.GetAppenders();
- if (null == m_consoleAppender)
- {
- Notice("No appender named Console found (see the log4net config file for this executable)!");
- }
- else
+ foreach (IAppender appender in appenders)
+ {
+ if (appender.Name == "Console")
{
- // FIXME: This should be done through an interface rather than casting.
- m_consoleAppender.Console = (ConsoleBase)m_console;
-
- // If there is no threshold set then the threshold is effectively everything.
- if (null == m_consoleAppender.Threshold)
- m_consoleAppender.Threshold = Level.All;
-
- Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
+ m_consoleAppender = (OpenSimAppender)appender;
+ break;
}
+ }
+
+ if (null == m_consoleAppender)
+ {
+ Notice("No appender named Console found (see the log4net config file for this executable)!");
+ }
+ else
+ {
+ // FIXME: This should be done through an interface rather than casting.
+ m_consoleAppender.Console = (ConsoleBase)m_console;
- m_console.Commands.AddCommand("General", false, "quit",
- "quit",
- "Quit the application", HandleQuit);
-
- m_console.Commands.AddCommand("General", false, "shutdown",
- "shutdown",
- "Quit the application", HandleQuit);
-
- m_console.Commands.AddCommand("General", false, "set log level",
- "set log level ",
- "Set the console logging level", HandleLogLevel);
-
- m_console.Commands.AddCommand("General", false, "show info",
- "show info",
- "Show general information about the server", HandleShow);
-
- m_console.Commands.AddCommand("General", false, "show threads",
- "show threads",
- "Show thread status", HandleShow);
-
- m_console.Commands.AddCommand("General", false, "show uptime",
- "show uptime",
- "Show server uptime", HandleShow);
-
- m_console.Commands.AddCommand("General", false, "show version",
- "show version",
- "Show server version", HandleShow);
-
- m_console.Commands.AddCommand("General", false, "threads abort",
- "threads abort ",
- "Abort a managed thread. Use \"show threads\" to find possible threads.", HandleThreadsAbort);
-
- m_console.Commands.AddCommand("General", false, "threads show",
- "threads show",
- "Show thread status. Synonym for \"show threads\"",
- (string module, string[] args) => Notice(GetThreadsReport()));
-
- m_console.Commands.AddCommand("General", false, "force gc",
- "force gc",
- "Manually invoke runtime garbage collection. For debugging purposes",
- HandleForceGc);
+ // If there is no threshold set then the threshold is effectively everything.
+ if (null == m_consoleAppender.Threshold)
+ m_consoleAppender.Threshold = Level.All;
+
+ Notice(String.Format("Console log level is {0}", m_consoleAppender.Threshold));
}
+
+ RegisterCommonCommands();
+
+ m_console.Commands.AddCommand("General", false, "quit",
+ "quit",
+ "Quit the application", HandleQuit);
+
+ m_console.Commands.AddCommand("General", false, "shutdown",
+ "shutdown",
+ "Quit the application", HandleQuit);
+
+ m_console.Commands.AddCommand("General", false, "set log level",
+ "set log level ",
+ "Set the console logging level", HandleLogLevel);
+
+ m_console.Commands.AddCommand("General", false, "show info",
+ "show info",
+ "Show general information about the server", HandleShow);
+
+ m_console.Commands.AddCommand("General", false, "show threads",
+ "show threads",
+ "Show thread status", HandleShow);
+
+ m_console.Commands.AddCommand("General", false, "show version",
+ "show version",
+ "Show server version", HandleShow);
+
+ m_console.Commands.AddCommand("General", false, "threads abort",
+ "threads abort ",
+ "Abort a managed thread. Use \"show threads\" to find possible threads.", HandleThreadsAbort);
+
+ m_console.Commands.AddCommand("General", false, "threads show",
+ "threads show",
+ "Show thread status. Synonym for \"show threads\"",
+ (string module, string[] args) => Notice(GetThreadsReport()));
+
+ m_console.Commands.AddCommand("General", false, "force gc",
+ "force gc",
+ "Manually invoke runtime garbage collection. For debugging purposes",
+ HandleForceGc);
}
private void HandleForceGc(string module, string[] args)
diff --git a/OpenSim/Framework/Servers/ServerBase.cs b/OpenSim/Framework/Servers/ServerBase.cs
index afe1f73..0835aad 100644
--- a/OpenSim/Framework/Servers/ServerBase.cs
+++ b/OpenSim/Framework/Servers/ServerBase.cs
@@ -49,6 +49,18 @@ namespace OpenSim.Framework.Servers
m_startuptime = DateTime.Now;
}
+ ///
+ /// Register common commands once m_console has been set if it is going to be set
+ ///
+ public void RegisterCommonCommands()
+ {
+ if (m_console == null)
+ return;
+
+ m_console.Commands.AddCommand(
+ "General", false, "show uptime", "show uptime", "Show server uptime", HandleShow);
+ }
+
public virtual void HandleShow(string module, string[] cmd)
{
List args = new List(cmd);
diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs
index 7b49ac9..285168c 100644
--- a/OpenSim/Server/Base/ServicesServerBase.cs
+++ b/OpenSim/Server/Base/ServicesServerBase.cs
@@ -239,6 +239,8 @@ namespace OpenSim.Server.Base
CreatePIDFile(startupConfig.GetString("PIDFile"));
}
+ RegisterCommonCommands();
+
// Register the quit command
//
MainConsole.Instance.Commands.AddCommand("General", false, "quit",
@@ -254,11 +256,6 @@ namespace OpenSim.Server.Base
"command-script