Refactor only: serve stats objects directly through StatsManager singleton

ThreadPoolClientBranch
Justin Clarke Casey 2008-02-04 16:22:58 +00:00
parent ffaf160362
commit a1c9349d47
13 changed files with 59 additions and 74 deletions

View File

@ -48,8 +48,6 @@ namespace OpenSim.Framework.UserManagement
protected UserManagerBase m_userManager = null; protected UserManagerBase m_userManager = null;
protected Mutex m_loginMutex = new Mutex(false); protected Mutex m_loginMutex = new Mutex(false);
protected UserStatsReporter m_statsCollector;
/// <summary> /// <summary>
/// Used during login to send the skeleton of the OpenSim Library to the client. /// Used during login to send the skeleton of the OpenSim Library to the client.
/// </summary> /// </summary>
@ -60,16 +58,12 @@ namespace OpenSim.Framework.UserManagement
/// </summary> /// </summary>
/// <param name="userManager"></param> /// <param name="userManager"></param>
/// <param name="libraryRootFolder"></param> /// <param name="libraryRootFolder"></param>
/// <param name="statsCollector">
/// An object for collecting statistical information.
/// Can be null if statistics are not required</param>
/// <param name="welcomeMess"></param> /// <param name="welcomeMess"></param>
public LoginService(UserManagerBase userManager, LibraryRootFolder libraryRootFolder, public LoginService(UserManagerBase userManager, LibraryRootFolder libraryRootFolder,
UserStatsReporter statsCollector, string welcomeMess) string welcomeMess)
{ {
m_userManager = userManager; m_userManager = userManager;
m_libraryRootFolder = libraryRootFolder; m_libraryRootFolder = libraryRootFolder;
m_statsCollector = statsCollector;
if (welcomeMess != String.Empty) if (welcomeMess != String.Empty)
{ {
@ -226,8 +220,8 @@ namespace OpenSim.Framework.UserManagement
CommitAgent(ref userProfile); CommitAgent(ref userProfile);
// If we reach this point, then the login has successfully logged onto the grid // If we reach this point, then the login has successfully logged onto the grid
if (m_statsCollector != null) if (StatsManager.UserStats != null)
m_statsCollector.AddSuccessfulLogin(); StatsManager.UserStats.AddSuccessfulLogin();
return logResponse.ToXmlRpcResponse(); return logResponse.ToXmlRpcResponse();
} }
@ -358,8 +352,8 @@ namespace OpenSim.Framework.UserManagement
CommitAgent(ref userProfile); CommitAgent(ref userProfile);
// If we reach this point, then the login has successfully logged onto the grid // If we reach this point, then the login has successfully logged onto the grid
if (m_statsCollector != null) if (StatsManager.UserStats != null)
m_statsCollector.AddSuccessfulLogin(); StatsManager.UserStats.AddSuccessfulLogin();
return logResponse.ToLLSDResponse(); return logResponse.ToLLSDResponse();
} }

View File

@ -45,17 +45,6 @@ namespace OpenSim.Framework.UserManagement
{ {
public UserConfig _config; public UserConfig _config;
private Dictionary<string, IUserData> _plugins = new Dictionary<string, IUserData>(); private Dictionary<string, IUserData> _plugins = new Dictionary<string, IUserData>();
protected UserStatsReporter _stats;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="statsCollector">Can be null if stats collection is not required.
/// </param>
public UserManagerBase(UserStatsReporter statsCollector)
{
_stats = statsCollector;
}
/// <summary> /// <summary>
/// Adds a new user server plugin - user servers will be requested in the order they were loaded. /// 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
/// <param name="posz"></param> /// <param name="posz"></param>
public void LogOffUser(LLUUID userid, LLUUID regionid, ulong regionhandle, float posx, float posy, float posz) public void LogOffUser(LLUUID userid, LLUUID regionid, ulong regionhandle, float posx, float posy, float posz)
{ {
if (_stats != null) if (StatsManager.UserStats != null)
_stats.AddLogout(); StatsManager.UserStats.AddLogout();
UserProfileData userProfile; UserProfileData userProfile;
UserAgentData userAgent; UserAgentData userAgent;

View File

@ -30,7 +30,7 @@ using System;
using System.Text; using System.Text;
using System.Timers; using System.Timers;
namespace OpenSim.Grid.AssetServer namespace OpenSim.Framework.Statistics
{ {
/// <summary> /// <summary>
/// Collects and reports information on the requests made to the asset server /// Collects and reports information on the requests made to the asset server

View File

@ -33,19 +33,39 @@ namespace OpenSim.Framework.Statistics
/// </summary> /// </summary>
public class StatsManager public class StatsManager
{ {
private static AssetStatsReporter assetStats;
private static UserStatsReporter userStats;
private static SimExtraStatsReporter simExtraStats; 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; } } public static SimExtraStatsReporter SimExtraStats { get { return simExtraStats; } }
private StatsManager() private StatsManager() {}
/// <summary>
/// Start collecting statistics related to assets.
/// Should only be called once.
/// </summary>
public static void StartCollectingAssetStats()
{ {
assetStats = new AssetStatsReporter();
} }
/// <summary> /// <summary>
/// Start recording statistics. Should only be called once - calling again will reset statistic /// Start collecting statistics related to users.
/// counts. /// Should only be called once.
/// </summary> /// </summary>
public static void StartCollecting() public static void StartCollectingUserStats()
{
userStats = new UserStatsReporter();
}
/// <summary>
/// Start collecting extra sim statistics apart from those collected for the client.
/// Should only be called once.
/// </summary>
public static void StartCollectingSimExtraStats()
{ {
simExtraStats = new SimExtraStatsReporter(); simExtraStats = new SimExtraStatsReporter();
} }

View File

@ -54,8 +54,6 @@ namespace OpenSim.Grid.AssetServer
private IAssetProvider m_assetProvider; private IAssetProvider m_assetProvider;
protected AssetStatsReporter m_stats;
[STAThread] [STAThread]
public static void Main(string[] args) public static void Main(string[] args)
{ {
@ -101,9 +99,9 @@ namespace OpenSim.Grid.AssetServer
m_console.Verbose("ASSET", "Starting HTTP process"); m_console.Verbose("ASSET", "Starting HTTP process");
BaseHttpServer httpServer = new BaseHttpServer(m_config.HttpPort); 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.AddStreamHandler(new PostAssetStreamHandler(this, m_assetProvider));
httpServer.Start(); httpServer.Start();
@ -184,7 +182,7 @@ namespace OpenSim.Grid.AssetServer
break; break;
case "stats": case "stats":
m_console.Notice("STATS", Environment.NewLine + m_stats.Report()); m_console.Notice("STATS", Environment.NewLine + StatsManager.AssetStats.Report());
break; break;
case "shutdown": case "shutdown":

View File

@ -43,22 +43,18 @@ namespace OpenSim.Grid.AssetServer
{ {
private OpenAsset_Main m_assetManager; private OpenAsset_Main m_assetManager;
private IAssetProvider m_assetProvider; private IAssetProvider m_assetProvider;
private AssetStatsReporter m_stats;
/// <summary> /// <summary>
/// Constructor. /// Constructor.
/// </summary> /// </summary>
/// <param name="assetManager"></param> /// <param name="assetManager"></param>
/// <param name="assetProvider"></param> /// <param name="assetProvider"></param>
/// <param name="stats">Can be null if stats collection isn't required</param> public GetAssetStreamHandler(OpenAsset_Main assetManager, IAssetProvider assetProvider)
public GetAssetStreamHandler(OpenAsset_Main assetManager, IAssetProvider assetProvider,
AssetStatsReporter stats)
: base("GET", "/assets") : base("GET", "/assets")
{ {
MainLog.Instance.Verbose("REST", "In Get Request"); MainLog.Instance.Verbose("REST", "In Get Request");
m_assetManager = assetManager; m_assetManager = assetManager;
m_assetProvider = assetProvider; m_assetProvider = assetProvider;
m_stats = stats;
} }
public override byte[] Handle(string path, Stream request) public override byte[] Handle(string path, Stream request)
@ -80,8 +76,8 @@ namespace OpenSim.Grid.AssetServer
return result; return result;
} }
if (m_stats != null) if (StatsManager.AssetStats != null)
m_stats.AddRequest(); StatsManager.AssetStats.AddRequest();
AssetBase asset = m_assetProvider.FetchAsset(assetID); AssetBase asset = m_assetProvider.FetchAsset(assetID);
if (asset != null) if (asset != null)
@ -107,8 +103,8 @@ namespace OpenSim.Grid.AssetServer
} }
else else
{ {
if (m_stats != null) if (StatsManager.AssetStats != null)
m_stats.AddNotFoundRequest(); StatsManager.AssetStats.AddNotFoundRequest();
MainLog.Instance.Verbose("REST", "GET:/asset failed to find {0}", assetID); MainLog.Instance.Verbose("REST", "GET:/asset failed to find {0}", assetID);
} }

View File

@ -48,8 +48,6 @@ namespace OpenSim.Grid.UserServer
public UserLoginService m_loginService; public UserLoginService m_loginService;
public MessageServersConnector m_messagesService; public MessageServersConnector m_messagesService;
protected UserStatsReporter m_stats;
private LogBase m_console; private LogBase m_console;
private LLUUID m_lastCreatedUser = LLUUID.Random(); 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"))); 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"); MainLog.Instance.Verbose("REGION", "Establishing data connection");
m_userManager = new UserManager(m_stats); m_userManager = new UserManager();
m_userManager._config = Cfg; m_userManager._config = Cfg;
m_userManager.AddPlugin(Cfg.DatabaseProvider); m_userManager.AddPlugin(Cfg.DatabaseProvider);
m_loginService = new UserLoginService( 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); m_messagesService = new MessageServersConnector(MainLog.Instance);
@ -199,7 +197,7 @@ namespace OpenSim.Grid.UserServer
break; break;
case "stats": case "stats":
MainLog.Instance.Notice("STATS", Environment.NewLine + m_stats.Report()); MainLog.Instance.Notice("STATS", Environment.NewLine + StatsManager.UserStats.Report());
break; break;
case "test-inventory": case "test-inventory":

View File

@ -55,8 +55,8 @@ namespace OpenSim.Grid.UserServer
public UserLoginService( public UserLoginService(
UserManagerBase userManager, LibraryRootFolder libraryRootFolder, UserManagerBase userManager, LibraryRootFolder libraryRootFolder,
UserStatsReporter statsCollector, UserConfig config, string welcomeMess) UserConfig config, string welcomeMess)
: base(userManager, libraryRootFolder, statsCollector, welcomeMess) : base(userManager, libraryRootFolder, welcomeMess)
{ {
m_config = config; m_config = config;
} }

View File

@ -39,15 +39,6 @@ namespace OpenSim.Grid.UserServer
{ {
public class UserManager : UserManagerBase public class UserManager : UserManagerBase
{ {
/// <summary>
/// Constructor.
/// </summary>
/// <param name="statsCollector">Can be null if stats collection is not required.
/// </param>
public UserManager(UserStatsReporter statsCollector) : base(statsCollector)
{
}
/// <summary> /// <summary>
/// Deletes an active agent session /// Deletes an active agent session
/// </summary> /// </summary>

View File

@ -304,7 +304,7 @@ namespace OpenSim
m_log = CreateLog(); m_log = CreateLog();
MainLog.Instance = m_log; MainLog.Instance = m_log;
StatsManager.StartCollecting(); StatsManager.StartCollectingSimExtraStats();
// Do baseclass startup sequence: OpenSim.Region.ClientStack.RegionApplicationBase.StartUp // Do baseclass startup sequence: OpenSim.Region.ClientStack.RegionApplicationBase.StartUp
// TerrainManager, StorageManager, HTTP Server // TerrainManager, StorageManager, HTTP Server
@ -320,7 +320,7 @@ namespace OpenSim
LocalUserServices userService = LocalUserServices userService =
new LocalUserServices(m_networkServersInfo, m_networkServersInfo.DefaultHomeLocX, new LocalUserServices(m_networkServersInfo, m_networkServersInfo.DefaultHomeLocX,
m_networkServersInfo.DefaultHomeLocY, inventoryService, null); m_networkServersInfo.DefaultHomeLocY, inventoryService);
userService.AddPlugin(m_standaloneUserPlugin); userService.AddPlugin(m_standaloneUserPlugin);
LocalBackEndServices backendService = new LocalBackEndServices(); LocalBackEndServices backendService = new LocalBackEndServices();
@ -333,7 +333,7 @@ namespace OpenSim
// TODO No user stats collection yet for standalone // TODO No user stats collection yet for standalone
m_loginService = m_loginService =
new LocalLoginService(userService, m_standaloneWelcomeMessage, localComms, m_networkServersInfo, new LocalLoginService(userService, m_standaloneWelcomeMessage, localComms, m_networkServersInfo,
null, m_standaloneAuthenticate); m_standaloneAuthenticate);
m_loginService.OnLoginToRegion += backendService.AddNewSession; m_loginService.OnLoginToRegion += backendService.AddNewSession;
// XMLRPC action // XMLRPC action

View File

@ -55,8 +55,8 @@ namespace OpenSim.Region.Communications.Local
public LocalLoginService(UserManagerBase userManager, string welcomeMess, public LocalLoginService(UserManagerBase userManager, string welcomeMess,
CommunicationsLocal parent, NetworkServersInfo serversInfo, CommunicationsLocal parent, NetworkServersInfo serversInfo,
UserStatsReporter statsCollector, bool authenticate) bool authenticate)
: base(userManager, parent.UserProfileCacheService.libraryRoot, statsCollector, welcomeMess) : base(userManager, parent.UserProfileCacheService.libraryRoot, welcomeMess)
{ {
m_Parent = parent; m_Parent = parent;
this.serversInfo = serversInfo; this.serversInfo = serversInfo;

View File

@ -52,8 +52,7 @@ namespace OpenSim.Region.Communications.Local
/// <param name="inventoryService"></param> /// <param name="inventoryService"></param>
/// <param name="statsCollector">Can be null if stats collection is not required.</param> /// <param name="statsCollector">Can be null if stats collection is not required.</param>
public LocalUserServices(NetworkServersInfo serversInfo, uint defaultHomeLocX, uint defaultHomeLocY, public LocalUserServices(NetworkServersInfo serversInfo, uint defaultHomeLocX, uint defaultHomeLocY,
IInventoryServices inventoryService, UserStatsReporter statsCollector) IInventoryServices inventoryService)
: base(statsCollector)
{ {
m_serversInfo = serversInfo; m_serversInfo = serversInfo;

View File

@ -77,7 +77,7 @@ namespace SimpleApp
LocalUserServices userService = LocalUserServices userService =
new LocalUserServices(m_networkServersInfo, m_networkServersInfo.DefaultHomeLocX, new LocalUserServices(m_networkServersInfo, m_networkServersInfo.DefaultHomeLocX,
m_networkServersInfo.DefaultHomeLocY, inventoryService, null); m_networkServersInfo.DefaultHomeLocY, inventoryService);
userService.AddPlugin(m_userPlugin); userService.AddPlugin(m_userPlugin);
LocalBackEndServices backendService = new LocalBackEndServices(); LocalBackEndServices backendService = new LocalBackEndServices();
@ -89,7 +89,7 @@ namespace SimpleApp
LocalLoginService loginService = LocalLoginService loginService =
new LocalLoginService( new LocalLoginService(
userService, String.Empty, localComms, m_networkServersInfo, null, false); userService, String.Empty, localComms, m_networkServersInfo, false);
loginService.OnLoginToRegion += backendService.AddNewSession; loginService.OnLoginToRegion += backendService.AddNewSession;
m_httpServer.AddXmlRPCHandler("login_to_simulator", loginService.XmlRpcLoginMethod); m_httpServer.AddXmlRPCHandler("login_to_simulator", loginService.XmlRpcLoginMethod);