From 7f11079f57faacedc2dc8e3f2005b483e7314726 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Fri, 28 Mar 2008 21:43:46 +0000 Subject: * Refactored out common http handler operations --- OpenSim/Grid/AssetServer/Main.cs | 17 +++++--- OpenSim/Grid/GridServer/GridServerBase.cs | 61 ++++++++++++--------------- OpenSim/Grid/InventoryServer/Main.cs | 28 ++++++++----- OpenSim/Grid/MessagingServer/Main.cs | 13 +++--- OpenSim/Grid/UserServer/Main.cs | 69 ++++++++++++------------------- 5 files changed, 86 insertions(+), 102 deletions(-) (limited to 'OpenSim/Grid') diff --git a/OpenSim/Grid/AssetServer/Main.cs b/OpenSim/Grid/AssetServer/Main.cs index d2c247a..c863c76 100644 --- a/OpenSim/Grid/AssetServer/Main.cs +++ b/OpenSim/Grid/AssetServer/Main.cs @@ -51,7 +51,7 @@ namespace OpenSim.Grid.AssetServer // Temporarily hardcoded - should be a plugin protected IAssetLoader assetLoader = new AssetLoaderFileSystem(); - private IAssetProvider m_assetProvider; + private IAssetProvider m_assetProvider; [STAThread] public static void Main(string[] args) @@ -94,14 +94,19 @@ namespace OpenSim.Grid.AssetServer LoadDefaultAssets(); m_log.Info("[ASSET]: Starting HTTP process"); - BaseHttpServer httpServer = new BaseHttpServer(m_config.HttpPort); - + m_httpServer = new BaseHttpServer(m_config.HttpPort); + StatsManager.StartCollectingAssetStats(); - httpServer.AddStreamHandler(new GetAssetStreamHandler(this, m_assetProvider)); - httpServer.AddStreamHandler(new PostAssetStreamHandler(this, m_assetProvider)); + AddHttpHandlers(); - httpServer.Start(); + m_httpServer.Start(); + } + + protected void AddHttpHandlers() + { + m_httpServer.AddStreamHandler(new GetAssetStreamHandler(this, m_assetProvider)); + m_httpServer.AddStreamHandler(new PostAssetStreamHandler(this, m_assetProvider)); } public byte[] GetAssetData(LLUUID assetID, bool isTexture) diff --git a/OpenSim/Grid/GridServer/GridServerBase.cs b/OpenSim/Grid/GridServer/GridServerBase.cs index 884ba4f..3be98d8 100644 --- a/OpenSim/Grid/GridServer/GridServerBase.cs +++ b/OpenSim/Grid/GridServer/GridServerBase.cs @@ -45,14 +45,8 @@ namespace OpenSim.Grid.GridServer { protected GridConfig m_config; protected GridManager m_gridManager; - protected BaseHttpServer httpServer; protected List m_plugins = new List(); - public BaseHttpServer HttpServer - { - get { return httpServer; } - } - public void Work() { m_console.Notice("Enter help for a list of commands\n"); @@ -88,38 +82,37 @@ namespace OpenSim.Grid.GridServer SetupGridManager(); m_console.Status("[GRID]: Starting HTTP process"); - httpServer = new BaseHttpServer(m_config.HttpPort); - //GridManagementAgent GridManagerAgent = new GridManagementAgent(httpServer, "gridserver", m_config.SimSendKey, m_config.SimRecvKey, managercallback); + m_httpServer = new BaseHttpServer(m_config.HttpPort); - httpServer.AddXmlRPCHandler("simulator_login", m_gridManager.XmlRpcSimulatorLoginMethod); - httpServer.AddXmlRPCHandler("simulator_data_request", m_gridManager.XmlRpcSimulatorDataRequestMethod); - httpServer.AddXmlRPCHandler("simulator_after_region_moved", m_gridManager.XmlRpcDeleteRegionMethod); - httpServer.AddXmlRPCHandler("map_block", m_gridManager.XmlRpcMapBlockMethod); + AddHttpHandlers(); - // Message Server ---> Grid Server - httpServer.AddXmlRPCHandler("register_messageserver", m_gridManager.XmlRPCRegisterMessageServer); - httpServer.AddXmlRPCHandler("deregister_messageserver", m_gridManager.XmlRPCDeRegisterMessageServer); + LoadGridPlugins( ); - httpServer.AddStreamHandler(new RestStreamHandler("GET", "/sims/", m_gridManager.RestGetSimMethod)); - httpServer.AddStreamHandler(new RestStreamHandler("POST", "/sims/", m_gridManager.RestSetSimMethod)); + m_httpServer.Start(); - httpServer.AddStreamHandler(new RestStreamHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod)); - httpServer.AddStreamHandler(new RestStreamHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod)); + m_console.Status("[GRID]: Starting sim status checker"); - //httpServer.AddRestHandler("GET", "/sims/", m_gridManager.RestGetSimMethod); - //httpServer.AddRestHandler("POST", "/sims/", m_gridManager.RestSetSimMethod); - //httpServer.AddRestHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod); - //httpServer.AddRestHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod); + Timer simCheckTimer = new Timer(3600000 * 3); // 3 Hours between updates. + simCheckTimer.Elapsed += new ElapsedEventHandler(CheckSims); + simCheckTimer.Enabled = true; + } - LoadGridPlugins(); + protected void AddHttpHandlers() + { + m_httpServer.AddXmlRPCHandler("simulator_login", m_gridManager.XmlRpcSimulatorLoginMethod); + m_httpServer.AddXmlRPCHandler("simulator_data_request", m_gridManager.XmlRpcSimulatorDataRequestMethod); + m_httpServer.AddXmlRPCHandler("simulator_after_region_moved", m_gridManager.XmlRpcDeleteRegionMethod); + m_httpServer.AddXmlRPCHandler("map_block", m_gridManager.XmlRpcMapBlockMethod); - httpServer.Start(); + // Message Server ---> Grid Server + m_httpServer.AddXmlRPCHandler("register_messageserver", m_gridManager.XmlRPCRegisterMessageServer); + m_httpServer.AddXmlRPCHandler("deregister_messageserver", m_gridManager.XmlRPCDeRegisterMessageServer); - m_console.Status("[GRID]: Starting sim status checker"); + m_httpServer.AddStreamHandler(new RestStreamHandler("GET", "/sims/", m_gridManager.RestGetSimMethod)); + m_httpServer.AddStreamHandler(new RestStreamHandler("POST", "/sims/", m_gridManager.RestSetSimMethod)); - Timer simCheckTimer = new Timer(3600000*3); // 3 Hours between updates. - simCheckTimer.Elapsed += new ElapsedEventHandler(CheckSims); - simCheckTimer.Enabled = true; + m_httpServer.AddStreamHandler(new RestStreamHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod)); + m_httpServer.AddStreamHandler(new RestStreamHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod)); } protected void LoadGridPlugins() @@ -131,8 +124,8 @@ namespace OpenSim.Grid.GridServer ExtensionNodeList nodes = AddinManager.GetExtensionNodes("/OpenSim/GridServer"); foreach (TypeExtensionNode node in nodes) { - m_console.Status("[GRIDPLUGINS]: Loading OpenSim plugin "+node.Path); - IGridPlugin plugin = (IGridPlugin) node.CreateInstance(); + m_console.Status("[GRIDPLUGINS]: Loading OpenSim plugin " + node.Path); + IGridPlugin plugin = (IGridPlugin)node.CreateInstance(); plugin.Initialise(this); m_plugins.Add(plugin); } @@ -191,15 +184,15 @@ namespace OpenSim.Grid.GridServer public override void RunCmd(string cmd, string[] cmdparams) { base.RunCmd(cmd, cmdparams); - + switch (cmd) { case "help": m_console.Notice("shutdown - shutdown the grid (USE CAUTION!)"); - break; + break; case "shutdown": - foreach(IGridPlugin plugin in m_plugins) plugin.Close(); + foreach (IGridPlugin plugin in m_plugins) plugin.Close(); m_console.Close(); Environment.Exit(0); break; diff --git a/OpenSim/Grid/InventoryServer/Main.cs b/OpenSim/Grid/InventoryServer/Main.cs index 9aa9adc..ea056a0 100644 --- a/OpenSim/Grid/InventoryServer/Main.cs +++ b/OpenSim/Grid/InventoryServer/Main.cs @@ -72,36 +72,42 @@ namespace OpenSim.Grid.InventoryServer m_inventoryService.AddPlugin(m_config.DatabaseProvider); m_log.Info("[" + LogName + "]: Starting HTTP server ..."); - BaseHttpServer httpServer = new BaseHttpServer(m_config.HttpPort); - httpServer.AddStreamHandler( + + m_httpServer = new BaseHttpServer(m_config.HttpPort); + AddHttpHandlers(); + m_httpServer.Start(); + + m_log.Info("[" + LogName + "]: Started HTTP server"); + } + + protected void AddHttpHandlers() + { + m_httpServer.AddStreamHandler( new RestDeserialisehandler("POST", "/GetInventory/", m_inventoryService.GetUserInventory)); - httpServer.AddStreamHandler( + m_httpServer.AddStreamHandler( new RestDeserialisehandler("POST", "/CreateInventory/", m_inventoryService.CreateUsersInventory)); - httpServer.AddStreamHandler( + m_httpServer.AddStreamHandler( new RestDeserialisehandler("POST", "/NewFolder/", m_inventoryService.AddInventoryFolder)); - httpServer.AddStreamHandler( + m_httpServer.AddStreamHandler( new RestDeserialisehandler("POST", "/MoveFolder/", m_inventoryService.MoveInventoryFolder)); - httpServer.AddStreamHandler( + m_httpServer.AddStreamHandler( new RestDeserialisehandler("POST", "/NewItem/", m_inventoryService.AddInventoryItem)); - httpServer.AddStreamHandler( + m_httpServer.AddStreamHandler( new RestDeserialisehandler("POST", "/DeleteItem/", m_inventoryService.DeleteInvItem)); - httpServer.AddStreamHandler( + m_httpServer.AddStreamHandler( new RestDeserialisehandler>("POST", "/RootFolders/", m_inventoryService.RequestFirstLevelFolders)); // httpServer.AddStreamHandler(new InventoryManager.GetInventory(m_inventoryManager)); - - httpServer.Start(); - m_log.Info("[" + LogName + "]: Started HTTP server"); } private void Work() diff --git a/OpenSim/Grid/MessagingServer/Main.cs b/OpenSim/Grid/MessagingServer/Main.cs index 063da55..b288b33 100644 --- a/OpenSim/Grid/MessagingServer/Main.cs +++ b/OpenSim/Grid/MessagingServer/Main.cs @@ -44,9 +44,6 @@ namespace OpenSim.Grid.MessagingServer private MessageServerConfig Cfg; private MessageService msgsvc; - - //public UserManager m_userManager; - //public UserLoginService m_loginService; private LLUUID m_lastCreatedUser = LLUUID.Random(); @@ -86,14 +83,14 @@ namespace OpenSim.Grid.MessagingServer Cfg = new MessageServerConfig("MESSAGING SERVER", (Path.Combine(Util.configDir(), "MessagingServer_Config.xml"))); m_log.Info("[REGION]: Starting HTTP process"); - BaseHttpServer httpServer = new BaseHttpServer(Cfg.HttpPort); - + m_httpServer = new BaseHttpServer(Cfg.HttpPort); + msgsvc = new MessageService(Cfg); if (msgsvc.registerWithUserServer()) { - httpServer.AddXmlRPCHandler("login_to_simulator", msgsvc.UserLoggedOn); - httpServer.AddXmlRPCHandler("logout_of_simulator", msgsvc.UserLoggedOff); + m_httpServer.AddXmlRPCHandler("login_to_simulator", msgsvc.UserLoggedOn); + m_httpServer.AddXmlRPCHandler("logout_of_simulator", msgsvc.UserLoggedOff); //httpServer.AddXmlRPCHandler("get_user_by_name", m_userManager.XmlRPCGetUserMethodName); //httpServer.AddXmlRPCHandler("get_user_by_uuid", m_userManager.XmlRPCGetUserMethodUUID); //httpServer.AddXmlRPCHandler("get_avatar_picker_avatar", m_userManager.XmlRPCGetAvatarPickerAvatar); @@ -106,7 +103,7 @@ namespace OpenSim.Grid.MessagingServer //httpServer.AddStreamHandler( //new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod)); - httpServer.Start(); + m_httpServer.Start(); m_log.Info("[SERVER]: Messageserver 0.5 - Startup complete"); } else diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs index c103e22..19f037f 100644 --- a/OpenSim/Grid/UserServer/Main.cs +++ b/OpenSim/Grid/UserServer/Main.cs @@ -100,35 +100,41 @@ namespace OpenSim.Grid.UserServer m_userManager.OnLogOffUser += NotifyMessageServersUserLoggOff; m_log.Info("[REGION]: Starting HTTP process"); - BaseHttpServer httpServer = new BaseHttpServer(Cfg.HttpPort); + + m_httpServer = new BaseHttpServer(Cfg.HttpPort); + AddHttpHandlers(); + m_httpServer.Start(); - httpServer.AddXmlRPCHandler("login_to_simulator", m_loginService.XmlRpcLoginMethod); + m_log.Info("[SERVER]: Userserver 0.5 - Startup complete"); + } - httpServer.AddHTTPHandler("login", m_loginService.ProcessHTMLLogin); + protected void AddHttpHandlers() + { + m_httpServer.AddXmlRPCHandler("login_to_simulator", m_loginService.XmlRpcLoginMethod); + + m_httpServer.AddHTTPHandler("login", m_loginService.ProcessHTMLLogin); - httpServer.SetLLSDHandler(m_loginService.LLSDLoginMethod); - - httpServer.AddXmlRPCHandler("get_user_by_name", m_userManager.XmlRPCGetUserMethodName); - httpServer.AddXmlRPCHandler("get_user_by_uuid", m_userManager.XmlRPCGetUserMethodUUID); - httpServer.AddXmlRPCHandler("get_avatar_picker_avatar", m_userManager.XmlRPCGetAvatarPickerAvatar); - httpServer.AddXmlRPCHandler("add_new_user_friend", m_userManager.XmlRpcResponseXmlRPCAddUserFriend); - httpServer.AddXmlRPCHandler("remove_user_friend", m_userManager.XmlRpcResponseXmlRPCRemoveUserFriend); - httpServer.AddXmlRPCHandler("update_user_friend_perms", m_userManager.XmlRpcResponseXmlRPCUpdateUserFriendPerms); - httpServer.AddXmlRPCHandler("get_user_friend_list", m_userManager.XmlRpcResponseXmlRPCGetUserFriendList); - httpServer.AddXmlRPCHandler("logout_of_simulator", m_userManager.XmlRPCLogOffUserMethodUUID); + m_httpServer.SetLLSDHandler(m_loginService.LLSDLoginMethod); + + m_httpServer.AddXmlRPCHandler("get_user_by_name", m_userManager.XmlRPCGetUserMethodName); + m_httpServer.AddXmlRPCHandler("get_user_by_uuid", m_userManager.XmlRPCGetUserMethodUUID); + m_httpServer.AddXmlRPCHandler("get_avatar_picker_avatar", m_userManager.XmlRPCGetAvatarPickerAvatar); + m_httpServer.AddXmlRPCHandler("add_new_user_friend", m_userManager.XmlRpcResponseXmlRPCAddUserFriend); + m_httpServer.AddXmlRPCHandler("remove_user_friend", m_userManager.XmlRpcResponseXmlRPCRemoveUserFriend); + m_httpServer.AddXmlRPCHandler("update_user_friend_perms", m_userManager.XmlRpcResponseXmlRPCUpdateUserFriendPerms); + m_httpServer.AddXmlRPCHandler("get_user_friend_list", m_userManager.XmlRpcResponseXmlRPCGetUserFriendList); + m_httpServer.AddXmlRPCHandler("logout_of_simulator", m_userManager.XmlRPCLogOffUserMethodUUID); // Message Server ---> User Server - httpServer.AddXmlRPCHandler("register_messageserver", m_messagesService.XmlRPCRegisterMessageServer); - httpServer.AddXmlRPCHandler("agent_change_region", m_messagesService.XmlRPCUserMovedtoRegion); - httpServer.AddXmlRPCHandler("deregister_messageserver", m_messagesService.XmlRPCDeRegisterMessageServer); + m_httpServer.AddXmlRPCHandler("register_messageserver", m_messagesService.XmlRPCRegisterMessageServer); + m_httpServer.AddXmlRPCHandler("agent_change_region", m_messagesService.XmlRPCUserMovedtoRegion); + m_httpServer.AddXmlRPCHandler("deregister_messageserver", m_messagesService.XmlRPCDeRegisterMessageServer); - httpServer.AddStreamHandler( + m_httpServer.AddStreamHandler( new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod)); - httpServer.AddXmlRPCHandler("update_user_profile", m_userManager.XmlRpcResponseXmlRPCUpdateUserProfile); - httpServer.Start(); - m_log.Info("[SERVER]: Userserver 0.5 - Startup complete"); + m_httpServer.AddXmlRPCHandler("update_user_profile", m_userManager.XmlRpcResponseXmlRPCUpdateUserProfile); } public void do_create(string what) @@ -239,28 +245,5 @@ namespace OpenSim.Grid.UserServer m_messagesService.TellMessageServersAboutUser( agentID, sessionID, RegionID, regionhandle, positionX, positionY, positionZ, firstname, lastname); } - - /*private void ConfigDB(IGenericConfig configData) - { - try - { - string attri = String.Empty; - attri = configData.GetAttribute("DataBaseProvider"); - if (attri == String.Empty) - { - StorageDll = "OpenSim.Framework.Data.DB4o.dll"; - configData.SetAttribute("DataBaseProvider", "OpenSim.Framework.Data.DB4o.dll"); - } - else - { - StorageDll = attri; - } - configData.Commit(); - } - catch - { - - } - }*/ } } -- cgit v1.1