当前位置: 首页 > news >正文

变化型网页网站有哪些建设摩托官网

变化型网页网站有哪些,建设摩托官网,房地产设计师,温州网站建站模板文章目录 一.编写思路二.代码实践 一.编写思路 定义消息队列 名字是否持久化 定义队列持久化类(持久化到 sqlite3) 构造函数(只能成功#xff0c;不能失败) 如果数据库(文件)不存在则创建打开数据库打开 msg_queue_table 数据库表 插入队列移除队列将数据库中的队列恢复到内存… 文章目录 一.编写思路二.代码实践 一.编写思路 定义消息队列 名字是否持久化 定义队列持久化类(持久化到 sqlite3) 构造函数(只能成功不能失败) 如果数据库(文件)不存在则创建打开数据库打开 msg_queue_table 数据库表 插入队列移除队列将数据库中的队列恢复到内存中 传入一个哈希表key 为名字value 为队列的智能指针填充该哈希表 定义队列管理类(包含内存管理和持久化管理) 构造函数从数据库中恢复队列声明队列移除队列获取队列 二.代码实践 MsgQueue.hpp: #pragma once #include ../common/Log.hpp #include ../common/Util.hpp #include ../common/Util.hpp #include memory #include unordered_map #include mutex namespace ns_data {class MsgQueue;using MsgQueuePtr std::shared_ptrMsgQueue;/************* 定义消息队列* ****************/struct MsgQueue{std::string _name;bool _isDurable;MsgQueue(const std::string name, bool isDurable): _name(name),_isDurable(isDurable){}};/****************** 定义消息队列持久化类* ******************/class MsgQueueMapper{private:ns_util::Sqlite3Util _sqlite;public:MsgQueueMapper(const std::string dbName): _sqlite(dbName){// 确保数据库文件已经存在不存在就创建if (!ns_util::FileUtil::createFile(dbName)){LOG(FATAL) create database dbName fail endl;exit(1);}if (!_sqlite.open()){LOG(FATAL) open database dbName fail endl;exit(1);}createTable();}/************** 插入消息队列* *************/bool insertMsgQueue(MsgQueuePtr msgQueuePtr){char insertSql[1024];sprintf(insertSql, insert into msg_queue_table values(%s, %d);,msgQueuePtr-_name.c_str(), msgQueuePtr-_isDurable);if (!_sqlite.exec(insertSql, nullptr, nullptr)){LOG(WARNING) insert MsgQueue fail, MsgQueue: msgQueuePtr-_name endl;return false;}return true;}/*********** 移除消息队列* ***************/void removeMsgQueue(const std::string name){char deleteSql[1024];sprintf(deleteSql, delete from msg_queue_table where name%s;, name.c_str());if (!_sqlite.exec(deleteSql, nullptr, nullptr)){LOG(WARNING) remove MsgQueue fail, MsgQueue: name endl;}}/************ 从数据库中恢复消息队列到内存* *****************/void recoverMsgQueue(std::unordered_mapstd::string, MsgQueuePtr *mapPtr){const std::string selectSql select * from msg_queue_table;;if (!_sqlite.exec(selectSql.c_str(), selectCallback, mapPtr)){LOG(FATAL) recover MsgQueue from msg_queue_table fail endl;exit(1);}}/*************** 删除数据库表(仅调试)* ***************/void removeTable(){const std::string dropSql drop table if exists msg_queue_table;;if (_sqlite.exec(dropSql.c_str(), nullptr, nullptr)){LOG(WARNING) remove table msg_queue_table fail endl;}}private:void createTable(){const std::string createSql create table if not exists msg_queue_table(\name varchar(32) primary key,\durable int\);;if (!_sqlite.exec(createSql.c_str(), nullptr, nullptr)){LOG(FATAL) create table msg_queue_table fail endl;exit(1);}}static int selectCallback(void *arg, int colNum, char **line, char **fields){auto mapPtr static_caststd::unordered_mapstd::string, MsgQueuePtr *(arg);std::string name line[0];bool isDurable std::stoi(line[1]);auto msgQueuePtr std::make_sharedMsgQueue(name, isDurable);mapPtr-insert({name, msgQueuePtr});return 0;}};class MsgQueueManager{private:MsgQueueMapper _mapper;std::unordered_mapstd::string, MsgQueuePtr _msgQueues;std::mutex _mtx;public:MsgQueueManager(const std::string dbName): _mapper(dbName){_mapper.recoverMsgQueue(_msgQueues);}/************ 声明队列* ************/bool declareMsgQueue(const std::string name, bool isDurable){std::unique_lockstd::mutex lck(_mtx);if (_msgQueues.count(name)){return true;}auto msgQueuePtr std::make_sharedMsgQueue(name, isDurable);_msgQueues[name] msgQueuePtr;if (isDurable){return _mapper.insertMsgQueue(msgQueuePtr);}return true;}/*********** 移除队列* ***********/void removeMsgQueue(const std::string name){std::unique_lockstd::mutex lck(_mtx);auto it _msgQueues.find(name);if (it _msgQueues.end()){return;}if (it-second-_isDurable){_mapper.removeMsgQueue(name);}_msgQueues.erase(name);}/************* 获取指定队列* ***************/MsgQueuePtr getMsgQueue(const std::string name){std::unique_lockstd::mutex lck(_mtx);if (_msgQueues.count(name) 0){return nullptr;}return _msgQueues[name];}/************** 清理所有队列(仅调试)* ******************/void clearMsgQueues(){std::unique_lockstd::mutex lck(_mtx);_msgQueues.clear();_mapper.removeTable();}};}
http://www.hkea.cn/news/14387117/

相关文章:

  • 济南wordpress 建站网站建设的可行性要求
  • 北京建设监理协会网站中铁三局招聘信息2022
  • 企业首页网站属于什么类型网站做经销找厂家好的网站
  • 阿里云服务器租赁重庆seo全面优化
  • python做网站吗哈尔滨网站制作公司电话
  • 网站建设学生选课系统设计长宁区公司网站建设
  • 福州网站设计培训做网站标签栏的图片大小
  • 用discuz做的大网站h5 做移动端网站
  • 哪里有国内网站建设公司个人做当地旅游网站
  • 大学生网站设计孝感网站建设软件
  • 做搜狗网站优化点击软免费 网站建设
  • 做网站的主流软件四川省建设安全质量监理协会网站
  • 做彩票网站犯法不普陀做网站价格
  • 外贸建站的公司vs怎么开发app软件
  • 装修设计师网站加强门户网站建设的方案
  • 广州知名网站建设网站展示怎么做
  • 求个网站2022wordpress自动存图
  • 做礼品建什么网站电动车行业网站建设
  • 增城微网站建设wordpress省理工大学
  • 可以做投票的网站上海贸易公司注册条件
  • 搭建网站平台保定手机网站建设
  • zen cart 创建的网站网站建立明细预计表
  • 中职计算机网站建设教学计划网站空间费价格
  • 100个万能网站html购物网站代码
  • 番禺建设网站公司排名wordpress安装windows
  • 昆山网站开发营销技巧心得体会
  • iis配置网站无法访问网络系统管理员在哪里
  • 中山网站的建设wordpress文章图片点击放大浏览
  • 170个可带链接锚文本外链的网站论坛临海app开发
  • 龙岩网站建设运营电商平台有哪些软件