From a1c9349d4765833691e7816d7f4df7bd37b9ee36 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Mon, 4 Feb 2008 16:22:58 +0000 Subject: Refactor only: serve stats objects directly through StatsManager singleton --- OpenSim/Framework/Communications/LoginService.cs | 18 +++++--------- .../Framework/Communications/UserManagerBase.cs | 15 ++---------- OpenSim/Framework/Statistics/AssetStatsReporter.cs | 2 +- OpenSim/Framework/Statistics/StatsManager.cs | 28 ++++++++++++++++++---- OpenSim/Grid/AssetServer/Main.cs | 10 ++++---- OpenSim/Grid/AssetServer/RestService.cs | 14 ++++------- OpenSim/Grid/UserServer/Main.cs | 12 ++++------ OpenSim/Grid/UserServer/UserLoginService.cs | 4 ++-- OpenSim/Grid/UserServer/UserManager.cs | 11 +-------- OpenSim/Region/Application/OpenSimMain.cs | 6 ++--- .../Communications/Local/LocalLoginService.cs | 4 ++-- .../Communications/Local/LocalUserServices.cs | 5 ++-- OpenSim/Region/Examples/SimpleApp/Program.cs | 4 ++-- 13 files changed, 59 insertions(+), 74 deletions(-) diff --git a/OpenSim/Framework/Communications/LoginService.cs b/OpenSim/Framework/Communications/LoginService.cs index 1707607..865349f 100644 --- a/OpenSim/Framework/Communications/LoginService.cs +++ b/OpenSim/Framework/Communications/LoginService.cs @@ -46,9 +46,7 @@ namespace OpenSim.Framework.UserManagement { protected string m_welcomeMessage = "Welcome to OpenSim"; protected UserManagerBase m_userManager = null; - protected Mutex m_loginMutex = new Mutex(false); - - protected UserStatsReporter m_statsCollector; + protected Mutex m_loginMutex = new Mutex(false); /// /// Used during login to send the skeleton of the OpenSim Library to the client. @@ -60,16 +58,12 @@ namespace OpenSim.Framework.UserManagement /// /// /// - /// - /// An object for collecting statistical information. - /// Can be null if statistics are not required /// public LoginService(UserManagerBase userManager, LibraryRootFolder libraryRootFolder, - UserStatsReporter statsCollector, string welcomeMess) + string welcomeMess) { m_userManager = userManager; m_libraryRootFolder = libraryRootFolder; - m_statsCollector = statsCollector; if (welcomeMess != String.Empty) { @@ -226,8 +220,8 @@ namespace OpenSim.Framework.UserManagement CommitAgent(ref userProfile); // If we reach this point, then the login has successfully logged onto the grid - if (m_statsCollector != null) - m_statsCollector.AddSuccessfulLogin(); + if (StatsManager.UserStats != null) + StatsManager.UserStats.AddSuccessfulLogin(); return logResponse.ToXmlRpcResponse(); } @@ -358,8 +352,8 @@ namespace OpenSim.Framework.UserManagement CommitAgent(ref userProfile); // If we reach this point, then the login has successfully logged onto the grid - if (m_statsCollector != null) - m_statsCollector.AddSuccessfulLogin(); + if (StatsManager.UserStats != null) + StatsManager.UserStats.AddSuccessfulLogin(); return logResponse.ToLLSDResponse(); } diff --git a/OpenSim/Framework/Communications/UserManagerBase.cs b/OpenSim/Framework/Communications/UserManagerBase.cs index 4967cd9..3b1d837 100644 --- a/OpenSim/Framework/Communications/UserManagerBase.cs +++ b/OpenSim/Framework/Communications/UserManagerBase.cs @@ -45,17 +45,6 @@ namespace OpenSim.Framework.UserManagement { public UserConfig _config; private Dictionary _plugins = new Dictionary(); - protected UserStatsReporter _stats; - - /// - /// Constructor. - /// - /// Can be null if stats collection is not required. - /// - public UserManagerBase(UserStatsReporter statsCollector) - { - _stats = statsCollector; - } /// /// Adds a new user server plugin - user servers will be requested in the order they were loaded. @@ -435,8 +424,8 @@ namespace OpenSim.Framework.UserManagement /// public void LogOffUser(LLUUID userid, LLUUID regionid, ulong regionhandle, float posx, float posy, float posz) { - if (_stats != null) - _stats.AddLogout(); + if (StatsManager.UserStats != null) + StatsManager.UserStats.AddLogout(); UserProfileData userProfile; UserAgentData userAgent; diff --git a/OpenSim/Framework/Statistics/AssetStatsReporter.cs b/OpenSim/Framework/Statistics/AssetStatsReporter.cs index bcd3a75..4f2ef86 100644 --- a/OpenSim/Framework/Statistics/AssetStatsReporter.cs +++ b/OpenSim/Framework/Statistics/AssetStatsReporter.cs @@ -30,7 +30,7 @@ using System; using System.Text; using System.Timers; -namespace OpenSim.Grid.AssetServer +namespace OpenSim.Framework.Statistics { /// /// Collects and reports information on the requests made to the asset server diff --git a/OpenSim/Framework/Statistics/StatsManager.cs b/OpenSim/Framework/Statistics/StatsManager.cs index 35040e3..842f1f1 100644 --- a/OpenSim/Framework/Statistics/StatsManager.cs +++ b/OpenSim/Framework/Statistics/StatsManager.cs @@ -33,19 +33,39 @@ namespace OpenSim.Framework.Statistics /// public class StatsManager { + private static AssetStatsReporter assetStats; + private static UserStatsReporter userStats; private static SimExtraStatsReporter simExtraStats; + public static AssetStatsReporter AssetStats { get { return assetStats; } } + public static UserStatsReporter UserStats { get { return userStats; } } public static SimExtraStatsReporter SimExtraStats { get { return simExtraStats; } } - private StatsManager() + private StatsManager() {} + + /// + /// Start collecting statistics related to assets. + /// Should only be called once. + /// + public static void StartCollectingAssetStats() { + assetStats = new AssetStatsReporter(); } /// - /// Start recording statistics. Should only be called once - calling again will reset statistic - /// counts. + /// Start collecting statistics related to users. + /// Should only be called once. + /// + public static void StartCollectingUserStats() + { + userStats = new UserStatsReporter(); + } + + /// + /// Start collecting extra sim statistics apart from those collected for the client. + /// Should only be called once. /// - public static void StartCollecting() + public static void StartCollectingSimExtraStats() { simExtraStats = new SimExtraStatsReporter(); } diff --git a/OpenSim/Grid/AssetServer/Main.cs b/OpenSim/Grid/AssetServer/Main.cs index c9f7e8e..23b0afa 100644 --- a/OpenSim/Grid/AssetServer/Main.cs +++ b/OpenSim/Grid/AssetServer/Main.cs @@ -52,9 +52,7 @@ namespace OpenSim.Grid.AssetServer // Temporarily hardcoded - should be a plugin protected IAssetLoader assetLoader = new AssetLoaderFileSystem(); - private IAssetProvider m_assetProvider; - - protected AssetStatsReporter m_stats; + private IAssetProvider m_assetProvider; [STAThread] public static void Main(string[] args) @@ -101,9 +99,9 @@ namespace OpenSim.Grid.AssetServer m_console.Verbose("ASSET", "Starting HTTP process"); BaseHttpServer httpServer = new BaseHttpServer(m_config.HttpPort); - m_stats = new AssetStatsReporter(); + StatsManager.StartCollectingAssetStats(); - httpServer.AddStreamHandler(new GetAssetStreamHandler(this, m_assetProvider, m_stats)); + httpServer.AddStreamHandler(new GetAssetStreamHandler(this, m_assetProvider)); httpServer.AddStreamHandler(new PostAssetStreamHandler(this, m_assetProvider)); httpServer.Start(); @@ -184,7 +182,7 @@ namespace OpenSim.Grid.AssetServer break; case "stats": - m_console.Notice("STATS", Environment.NewLine + m_stats.Report()); + m_console.Notice("STATS", Environment.NewLine + StatsManager.AssetStats.Report()); break; case "shutdown": diff --git a/OpenSim/Grid/AssetServer/RestService.cs b/OpenSim/Grid/AssetServer/RestService.cs index 9b288a7..5c497b6 100644 --- a/OpenSim/Grid/AssetServer/RestService.cs +++ b/OpenSim/Grid/AssetServer/RestService.cs @@ -43,22 +43,18 @@ namespace OpenSim.Grid.AssetServer { private OpenAsset_Main m_assetManager; private IAssetProvider m_assetProvider; - private AssetStatsReporter m_stats; /// /// Constructor. /// /// /// - /// Can be null if stats collection isn't required - public GetAssetStreamHandler(OpenAsset_Main assetManager, IAssetProvider assetProvider, - AssetStatsReporter stats) + public GetAssetStreamHandler(OpenAsset_Main assetManager, IAssetProvider assetProvider) : base("GET", "/assets") { MainLog.Instance.Verbose("REST", "In Get Request"); m_assetManager = assetManager; m_assetProvider = assetProvider; - m_stats = stats; } public override byte[] Handle(string path, Stream request) @@ -80,8 +76,8 @@ namespace OpenSim.Grid.AssetServer return result; } - if (m_stats != null) - m_stats.AddRequest(); + if (StatsManager.AssetStats != null) + StatsManager.AssetStats.AddRequest(); AssetBase asset = m_assetProvider.FetchAsset(assetID); if (asset != null) @@ -107,8 +103,8 @@ namespace OpenSim.Grid.AssetServer } else { - if (m_stats != null) - m_stats.AddNotFoundRequest(); + if (StatsManager.AssetStats != null) + StatsManager.AssetStats.AddNotFoundRequest(); MainLog.Instance.Verbose("REST", "GET:/asset failed to find {0}", assetID); } diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs index 2650694..20828ba 100644 --- a/OpenSim/Grid/UserServer/Main.cs +++ b/OpenSim/Grid/UserServer/Main.cs @@ -46,9 +46,7 @@ namespace OpenSim.Grid.UserServer public UserManager m_userManager; public UserLoginService m_loginService; - public MessageServersConnector m_messagesService; - - protected UserStatsReporter m_stats; + public MessageServersConnector m_messagesService; private LogBase m_console; private LLUUID m_lastCreatedUser = LLUUID.Random(); @@ -89,15 +87,15 @@ namespace OpenSim.Grid.UserServer { Cfg = new UserConfig("USER SERVER", (Path.Combine(Util.configDir(), "UserServer_Config.xml"))); - m_stats = new UserStatsReporter(); + StatsManager.StartCollectingUserStats(); MainLog.Instance.Verbose("REGION", "Establishing data connection"); - m_userManager = new UserManager(m_stats); + m_userManager = new UserManager(); m_userManager._config = Cfg; m_userManager.AddPlugin(Cfg.DatabaseProvider); m_loginService = new UserLoginService( - m_userManager, new LibraryRootFolder(), m_stats, Cfg, Cfg.DefaultStartupMsg); + m_userManager, new LibraryRootFolder(), Cfg, Cfg.DefaultStartupMsg); m_messagesService = new MessageServersConnector(MainLog.Instance); @@ -199,7 +197,7 @@ namespace OpenSim.Grid.UserServer break; case "stats": - MainLog.Instance.Notice("STATS", Environment.NewLine + m_stats.Report()); + MainLog.Instance.Notice("STATS", Environment.NewLine + StatsManager.UserStats.Report()); break; case "test-inventory": diff --git a/OpenSim/Grid/UserServer/UserLoginService.cs b/OpenSim/Grid/UserServer/UserLoginService.cs index 0f02ad2..10f9468 100644 --- a/OpenSim/Grid/UserServer/UserLoginService.cs +++ b/OpenSim/Grid/UserServer/UserLoginService.cs @@ -55,8 +55,8 @@ namespace OpenSim.Grid.UserServer public UserLoginService( UserManagerBase userManager, LibraryRootFolder libraryRootFolder, - UserStatsReporter statsCollector, UserConfig config, string welcomeMess) - : base(userManager, libraryRootFolder, statsCollector, welcomeMess) + UserConfig config, string welcomeMess) + : base(userManager, libraryRootFolder, welcomeMess) { m_config = config; } diff --git a/OpenSim/Grid/UserServer/UserManager.cs b/OpenSim/Grid/UserServer/UserManager.cs index 778aec1..c36de7f 100644 --- a/OpenSim/Grid/UserServer/UserManager.cs +++ b/OpenSim/Grid/UserServer/UserManager.cs @@ -38,16 +38,7 @@ using OpenSim.Framework.UserManagement; namespace OpenSim.Grid.UserServer { public class UserManager : UserManagerBase - { - /// - /// Constructor. - /// - /// Can be null if stats collection is not required. - /// - public UserManager(UserStatsReporter statsCollector) : base(statsCollector) - { - } - + { /// /// Deletes an active agent session /// diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs index 1754f7e..da4cf3e 100644 --- a/OpenSim/Region/Application/OpenSimMain.cs +++ b/OpenSim/Region/Application/OpenSimMain.cs @@ -304,7 +304,7 @@ namespace OpenSim m_log = CreateLog(); MainLog.Instance = m_log; - StatsManager.StartCollecting(); + StatsManager.StartCollectingSimExtraStats(); // Do baseclass startup sequence: OpenSim.Region.ClientStack.RegionApplicationBase.StartUp // TerrainManager, StorageManager, HTTP Server @@ -320,7 +320,7 @@ namespace OpenSim LocalUserServices userService = new LocalUserServices(m_networkServersInfo, m_networkServersInfo.DefaultHomeLocX, - m_networkServersInfo.DefaultHomeLocY, inventoryService, null); + m_networkServersInfo.DefaultHomeLocY, inventoryService); userService.AddPlugin(m_standaloneUserPlugin); LocalBackEndServices backendService = new LocalBackEndServices(); @@ -333,7 +333,7 @@ namespace OpenSim // TODO No user stats collection yet for standalone m_loginService = new LocalLoginService(userService, m_standaloneWelcomeMessage, localComms, m_networkServersInfo, - null, m_standaloneAuthenticate); + m_standaloneAuthenticate); m_loginService.OnLoginToRegion += backendService.AddNewSession; // XMLRPC action diff --git a/OpenSim/Region/Communications/Local/LocalLoginService.cs b/OpenSim/Region/Communications/Local/LocalLoginService.cs index 7dee2cb..2848b8a 100644 --- a/OpenSim/Region/Communications/Local/LocalLoginService.cs +++ b/OpenSim/Region/Communications/Local/LocalLoginService.cs @@ -55,8 +55,8 @@ namespace OpenSim.Region.Communications.Local public LocalLoginService(UserManagerBase userManager, string welcomeMess, CommunicationsLocal parent, NetworkServersInfo serversInfo, - UserStatsReporter statsCollector, bool authenticate) - : base(userManager, parent.UserProfileCacheService.libraryRoot, statsCollector, welcomeMess) + bool authenticate) + : base(userManager, parent.UserProfileCacheService.libraryRoot, welcomeMess) { m_Parent = parent; this.serversInfo = serversInfo; diff --git a/OpenSim/Region/Communications/Local/LocalUserServices.cs b/OpenSim/Region/Communications/Local/LocalUserServices.cs index 8a4d4e7..6192a7a 100644 --- a/OpenSim/Region/Communications/Local/LocalUserServices.cs +++ b/OpenSim/Region/Communications/Local/LocalUserServices.cs @@ -52,8 +52,7 @@ namespace OpenSim.Region.Communications.Local /// /// Can be null if stats collection is not required. public LocalUserServices(NetworkServersInfo serversInfo, uint defaultHomeLocX, uint defaultHomeLocY, - IInventoryServices inventoryService, UserStatsReporter statsCollector) - : base(statsCollector) + IInventoryServices inventoryService) { m_serversInfo = serversInfo; @@ -103,4 +102,4 @@ namespace OpenSim.Region.Communications.Local return data; } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/Examples/SimpleApp/Program.cs b/OpenSim/Region/Examples/SimpleApp/Program.cs index ff29b11..6c18540 100644 --- a/OpenSim/Region/Examples/SimpleApp/Program.cs +++ b/OpenSim/Region/Examples/SimpleApp/Program.cs @@ -77,7 +77,7 @@ namespace SimpleApp LocalUserServices userService = new LocalUserServices(m_networkServersInfo, m_networkServersInfo.DefaultHomeLocX, - m_networkServersInfo.DefaultHomeLocY, inventoryService, null); + m_networkServersInfo.DefaultHomeLocY, inventoryService); userService.AddPlugin(m_userPlugin); LocalBackEndServices backendService = new LocalBackEndServices(); @@ -89,7 +89,7 @@ namespace SimpleApp LocalLoginService loginService = new LocalLoginService( - userService, String.Empty, localComms, m_networkServersInfo, null, false); + userService, String.Empty, localComms, m_networkServersInfo, false); loginService.OnLoginToRegion += backendService.AddNewSession; m_httpServer.AddXmlRPCHandler("login_to_simulator", loginService.XmlRpcLoginMethod); -- cgit v1.1