| | |
| | | #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( ); |
| | | static ConnectionPool* getInstance(); |
| | | |
| | | std::shared_ptr<MysqlConn> getMysqlConn(); // 仿°æ®åºè¿æ¥æ± è·åè¿æ¥ |
| | | shared_ptr<MysqlConn> getMysqlConn(); // 仿°æ®åºè¿æ¥æ± è·åè¿æ¥ |
| | | |
| | | ConnectionPool(const ConnectionPool& other) = delete; |
| | | ConnectionPool& operator = (const ConnectionPool & other ) = delete; |
| | | |
| | | ~ConnectionPool(); |
| | | ConnectionPool(const ConnectionPool& other) = delete; |
| | | ConnectionPool& operator=(const ConnectionPool& other) = delete; |
| | | |
| | | void description(); |
| | | ~ConnectionPool(); |
| | | |
| | | void description(); |
| | | |
| | | protected: |
| | | ConnectionPool( ); // æé 彿° |
| | | ConnectionPool(); // æé 彿° |
| | | private: |
| | | bool parseJsonFile(); // è§£æé
ç½® |
| | | // ä¸åéè¦è§£æé
ç½®æä»¶ç彿° |
| | | // bool parseJsonFile(); // è§£æé
ç½® |
| | | |
| | | void produce(); |
| | | void recycle(); |
| | | void addConnection(); // å¢å è¿æ¥æ° |
| | | 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; |
| | | // åæ»çæ°æ®åºè¿æ¥åæ° |
| | | string m_ip = "127.0.0.1"; |
| | | string m_userName = "root"; |
| | | string m_passwd = "123456"; |
| | | string m_db = "mayi_kunlun"; |
| | | unsigned short m_port = 3306; |
| | | |
| | | int m_max_conn; |
| | | int m_min_conn; |
| | | 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; // æ¡ä»¶åé |
| | | int m_timeout; // è¿æ¥è¶
æ¶æ¶é´ |
| | | int max_del_time; // æå¤§å 餿¶é´( è¿æ¥ç©ºé²æ¶é´è¶
è¿è¿ä¸ª,å°±ç»å½åè¿æ¥å
³é ) |
| | | queue<MysqlConn*> m_connkQueue; // è¿æ¥éå |
| | | mutex m_mutex; // äºæ¥é |
| | | condition_variable m_cond; // æ¡ä»¶åé |
| | | }; |
| | | |