[DB] Use a single shared pool of connections to the database

This commit is contained in:
emeric
2015-08-19 13:31:50 +02:00
parent 4b35e03ef8
commit e18221689f
23 changed files with 89 additions and 62 deletions
+2 -2
View File
@@ -39,11 +39,11 @@ namespace Server {
Connection::Connection(boost::asio::io_service& ioService,
boost::asio::ssl::context& context,
ConnectionManager& manager,
const boost::filesystem::path& dbPath)
Wt::Dbo::SqlConnectionPool& connectionPool)
: _closing(false),
_socket(ioService, context),
_connectionManager(manager),
_requestHandler(dbPath)
_requestHandler(connectionPool)
{
LMS_LOG(MOD_REMOTE, SEV_DEBUG) << "Server::Connection::Connection, Creating connection";
}
+1 -1
View File
@@ -50,7 +50,7 @@ class Connection : public std::enable_shared_from_this<Connection>
/// Construct a connection with the given io_service.
explicit Connection(boost::asio::io_service& ioService, boost::asio::ssl::context& context,
ConnectionManager& manager,
const boost::filesystem::path& dbPath);
Wt::Dbo::SqlConnectionPool& connectionPool);
ssl_socket::lowest_layer_type& getSocket() {return _socket.lowest_layer();}
+2 -2
View File
@@ -24,8 +24,8 @@
namespace LmsAPI {
namespace Server {
RequestHandler::RequestHandler(boost::filesystem::path dbPath)
: _db( dbPath ),
RequestHandler::RequestHandler(Wt::Dbo::SqlConnectionPool &connectionPool)
: _db( connectionPool ),
_authRequestHandler(_db),
_audioCollectionRequestHandler(_db),
_mediaRequestHandler(_db)
+2 -2
View File
@@ -20,7 +20,7 @@
#ifndef REMOTE_REQUEST_HANDLER
#define REMOTE_REQUEST_HANDLER
#include <boost/filesystem.hpp>
#include <Wt/Dbo/SqlConnectionPool>
#include "messages.pb.h"
@@ -37,7 +37,7 @@ class RequestHandler
{
public:
RequestHandler(boost::filesystem::path dbPath);
RequestHandler(Wt::Dbo::SqlConnectionPool& connectionPool);
~RequestHandler();
bool process(const ClientMessage& request, ServerMessage& response);
+3 -3
View File
@@ -34,12 +34,12 @@ Server::Server(const endpoint_type& bindEndpoint,
boost::filesystem::path certPath,
boost::filesystem::path privKeyPath,
boost::filesystem::path dhPath,
boost::filesystem::path dbPath)
Wt::Dbo::SqlConnectionPool& connectionPool)
:
_acceptor(_ioService, bindEndpoint, true /*SO_REUSEADDR*/),
_connectionManager(),
_context(boost::asio::ssl::context::tlsv1_server),
_dbPath(dbPath)
_connectionPool(connectionPool)
{
_ioService.setThreadCount(1); // TODO parametrize
@@ -68,7 +68,7 @@ Server::start()
void
Server::asyncAccept()
{
std::shared_ptr<Connection> newConnection = std::make_shared<Connection>(_ioService, _context, _connectionManager, _dbPath);
std::shared_ptr<Connection> newConnection = std::make_shared<Connection>(_ioService, _context, _connectionManager, _connectionPool);
_acceptor.async_accept(newConnection->getSocket(),
boost::bind(&Server::handleAccept, this, newConnection, boost::asio::placeholders::error));
+3 -2
View File
@@ -21,6 +21,7 @@
#define REMOTE_SERVER_HPP
#include <Wt/WIOService>
#include <Wt/Dbo/SqlConnectionPool>
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
@@ -49,7 +50,7 @@ class Server
boost::filesystem::path certPath,
boost::filesystem::path privKeyPath,
boost::filesystem::path dhPath,
boost::filesystem::path dbPath);
Wt::Dbo::SqlConnectionPool& connectionPool);
// Run the server's io_service loop.
void start();
@@ -72,7 +73,7 @@ class Server
boost::asio::ssl::context _context;
/// The database to be used for requests
boost::filesystem::path _dbPath;
Wt::Dbo::SqlConnectionPool& _connectionPool;
};
} // namespace Server