[DB] Use a single shared pool of connections to the database
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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();}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user