#pragma once
|
|
#include <queue>
|
#include <mutex>
|
#include <condition_variable>
|
//#include <json/json.h>
|
|
#include "MysqlConn.h"
|
|
//using namespace Json;
|
|
class ConnectionPool
|
{
|
public:
|
static ConnectionPool* getInstance( );
|
|
std::shared_ptr<MysqlConn> getMysqlConn(); // ´ÓÊý¾Ý¿âÁ¬½Ó³Ø»ñÈ¡Á¬½Ó
|
|
ConnectionPool(const ConnectionPool& other) = delete;
|
ConnectionPool& operator = (const ConnectionPool & other ) = delete;
|
|
~ConnectionPool();
|
|
void description();
|
|
protected:
|
ConnectionPool( ); // ¹¹Ô캯Êý
|
private:
|
bool parseJsonFile(); // ½âÎöÅäÖÃ
|
|
void produce();
|
void recycle();
|
void addConnection(); // Ôö¼ÓÁ¬½ÓÊý
|
|
std::string m_ip;
|
std::string m_userName;
|
std::string m_passwd;
|
std::string m_db;
|
unsigned short m_port;
|
|
int m_max_conn;
|
int m_min_conn;
|
|
int m_timeout; // Á¬½Ó³¬Ê±Ê±¼ä
|
int max_del_time; // ×î´óɾ³ýʱ¼ä( Á¬½Ó¿ÕÏÐʱ¼ä³¬¹ýÕâ¸ö,¾Í¸øµ±Ç°Á¬½Ó¹Ø±Õ )
|
std::queue<MysqlConn*>m_connkQueue ; // Á¬½Ó¶ÓÁÐ
|
std::mutex m_mutex; // »¥³âËø
|
std::condition_variable m_cond; // Ìõ¼þ±äÁ¿
|
};
|