Changeset 3336
- Timestamp:
- 01/30/10 15:53:00 (7 weeks ago)
- Location:
- Enterprise/branches/0075_TR_SCRIPTING/AppServer
- Files:
-
- 3 modified
-
I_ApplicationServer.hpp (modified) (4 diffs)
-
src/ApplicationServer.cpp (modified) (6 diffs)
-
src/ApplicationServer.hpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Enterprise/branches/0075_TR_SCRIPTING/AppServer/I_ApplicationServer.hpp
r3331 r3336 34 34 #include <Zen/Core/Plugins/I_Configuration.hpp> 35 35 #include <Zen/Core/Threading/I_Condition.hpp> 36 #include <Zen/Core/Threading/I_Thread.hpp> 36 37 #include <Zen/Core/Scripting/I_ScriptEngine.hpp> 37 38 … … 40 41 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 41 42 namespace Zen { 43 namespace Database { 44 class I_DatabaseConnection; 45 } // namespace Database 42 46 namespace Enterprise { 43 47 namespace AppServer { … … 79 83 typedef Memory::managed_ptr<I_MessageRegistry> pMessageRegistry_type; 80 84 85 typedef Memory::managed_ptr<Database::I_DatabaseConnection> pDatabaseConnection_type; 86 81 87 typedef Zen::Plugins::I_ConfigurationElement::const_ptr_type pConfig_type; 82 88 … … 169 175 /// @see I_SessionEvent 170 176 virtual void handleSessionEvent(pSessionEvent_type _pSessionEvent) = 0; 177 178 /// Get the database connection for the current thread. 179 virtual pDatabaseConnection_type getDatabaseConnection(const std::string& _database, Zen::Threading::I_Thread::ThreadId& _threadId) = 0; 171 180 /// @} 172 181 -
Enterprise/branches/0075_TR_SCRIPTING/AppServer/src/ApplicationServer.cpp
r3331 r3336 3 3 // 4 4 // Copyright (C) 2001 - 2010 Tony Richards 5 // Copyright (C) 2008 - 20 09Matthew Alan Gray5 // Copyright (C) 2008 - 2010 Matthew Alan Gray 6 6 // Copyright (C) 2009 Joshua Cassity 7 7 // … … 46 46 47 47 #include <Zen/Core/Threading/MutexFactory.hpp> 48 #include <Zen/Core/Threading/I_Mutex.hpp> 49 #include <Zen/Core/Threading/CriticalSection.hpp> 48 50 49 51 #include <Zen/Core/Scripting/I_ScriptableService.hpp> … … 51 53 #include <Zen/Enterprise/Networking/I_Endpoint.hpp> 52 54 #include <Zen/Enterprise/Networking/I_Address.hpp> 55 56 #include <Zen/Enterprise/Database/I_DatabaseManager.hpp> 57 #include <Zen/Enterprise/Database/I_DatabaseService.hpp> 58 #include <Zen/Enterprise/Database/I_DatabaseConnection.hpp> 53 59 54 60 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ … … 80 86 , m_pApplicationGuard(Threading::MutexFactory::create()) 81 87 , m_pMessageRegistry_type(new NumericTypeMessageRegistry(), &destroy) 88 , m_databaseConnectionsMap() 82 89 { 83 90 } … … 808 815 809 816 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 817 ApplicationServer::pDatabaseConnection_type 818 ApplicationServer::getDatabaseConnection(const std::string& _database, 819 Zen::Threading::I_Thread::ThreadId& _threadId) 820 { 821 /// Do we need to guard this? 822 823 DatabaseConnectionsMap_type::iterator iter = m_databaseConnectionsMap.find(_database); 824 if( iter != m_databaseConnectionsMap.end() ) 825 { 826 return iter->second.getConnection(_threadId); 827 } 828 else 829 { 830 return pDatabaseConnection_type(); 831 // TODO Error? 832 } 833 } 834 835 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 810 836 void 811 837 ApplicationServer::handleInstallProtocol(pProtocolService_type _pProtocolService, const std::string& _protocolName) … … 862 888 863 889 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 890 ApplicationServer::DatabaseConnections::DatabaseConnections(pDatabaseService_type _pService, 891 config_type _connectionConfig) 892 : m_pDatabaseService(_pService) 893 , m_connectionConfig(_connectionConfig) 894 , m_databaseConnections() 895 , m_databaseConnectionsMutex(Zen::Threading::MutexFactory::create()) 896 { 897 } 898 899 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 900 ApplicationServer::DatabaseConnections::~DatabaseConnections() 901 { 902 Zen::Threading::MutexFactory::destroy(m_databaseConnectionsMutex); 903 } 904 905 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 906 ApplicationServer::DatabaseConnections::pDatabaseConnection_type 907 ApplicationServer::DatabaseConnections::getConnection(Zen::Threading::I_Thread::ThreadId& _threadId) 908 { 909 Zen::Threading::CriticalSection guard(m_databaseConnectionsMutex); 910 911 DatabaseConnections_type::iterator iter = m_databaseConnections.find(_threadId); 912 if( iter != m_databaseConnections.end() ) 913 { 914 return iter->second; 915 } 916 else 917 { 918 pDatabaseConnection_type pDatabaseConnection = m_pDatabaseService->connect(_threadId.toString(), m_connectionConfig); 919 m_databaseConnections[_threadId] = pDatabaseConnection; 920 return pDatabaseConnection; 921 } 922 } 923 924 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 864 925 } // namespace AppServer 865 926 } // namespace Enterprise -
Enterprise/branches/0075_TR_SCRIPTING/AppServer/src/ApplicationServer.hpp
r3331 r3336 3 3 // 4 4 // Copyright (C) 2001 - 2010 Tony Richards 5 // Copyright (C) 2008 - 20 09Matthew Alan Gray5 // Copyright (C) 2008 - 2010 Matthew Alan Gray 6 6 // Copyright (C) 2009 Joshua Cassity 7 7 // … … 31 31 #include "../I_ApplicationServer.hpp" 32 32 33 #include <Zen/Core/Threading/I_Thread.hpp> 33 34 #include <Zen/Core/Threading/ThreadPool.hpp> 34 35 … … 40 41 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ 41 42 namespace Zen { 43 namespace Database { 44 class I_DatabaseService; 45 class I_DatabaseConnection; 46 } // namespace Database 42 47 namespace Enterprise { 43 48 namespace AppServer { … … 86 91 virtual void handleRequest(pRequest_type _pRequest, pResponseHandler_type _pResponseHandler); 87 92 virtual void handleSessionEvent(pSessionEvent_type _pSessionEvent); 93 virtual pDatabaseConnection_type getDatabaseConnection(const std::string& _database, Zen::Threading::I_Thread::ThreadId& _threadId); 88 94 /// @} 89 95 … … 108 114 109 115 Threading::ThreadPool& getSharedThreadPool() { return m_sharedThreadPool; } 116 /// @} 117 118 /// @name Inner classes 119 /// @{ 120 private: 121 class DatabaseConnections 122 { 123 /// @name Types 124 /// @{ 125 public: 126 typedef Zen::Memory::managed_ptr<Zen::Database::I_DatabaseService> pDatabaseService_type; 127 typedef std::map<std::string,std::string> config_type; 128 typedef Zen::Memory::managed_ptr<Zen::Database::I_DatabaseConnection> pDatabaseConnection_type; 129 typedef std::map<Zen::Threading::I_Thread::ThreadId,pDatabaseConnection_type> DatabaseConnections_type; 130 /// @} 131 132 /// @name DatabaseConnections implementation 133 /// @{ 134 public: 135 pDatabaseConnection_type getConnection(Zen::Threading::I_Thread::ThreadId& _threadId); 136 /// @} 137 138 /// @name 'Structors 139 /// @{ 140 DatabaseConnections(pDatabaseService_type _pService, config_type _connectionConfig); 141 ~DatabaseConnections(); 142 /// @} 143 144 /// @name Member Variables 145 /// @{ 146 private: 147 pDatabaseService_type m_pDatabaseService; 148 config_type m_connectionConfig; 149 DatabaseConnections_type m_databaseConnections; 150 Zen::Threading::I_Mutex* m_databaseConnectionsMutex; 151 /// @} 152 153 }; // class DatabaseConnections 110 154 /// @} 111 155 … … 156 200 157 201 pMessageRegistry_type m_pMessageRegistry_type; 202 203 typedef std::map<std::string, DatabaseConnections> DatabaseConnectionsMap_type; 204 DatabaseConnectionsMap_type m_databaseConnectionsMap; 158 205 /// @} 159 206
