bool SDRedisStatusChecker::init(SDServerDispatcher_ptr dispatcher, SDRedisServerManager_ptr rs_manager) { LOG4CPLUS_DEBUG(logger, "SDRedisStatusChecker start init"); m_dispatcher = dispatcher; m_rs_manager = rs_manager; SDConfiguration* config = SDConfigurationSingleton::get_instance()->get_config(); m_zk_host = config->getString("status.zk.server.host.port"); m_zk_recv_to = config->getInt("status.zk.session.timeout",3000); m_zk_service = config->getString("status.zk.service","redis_status"); m_check_interval = config->getInt("status.manager.check.interval.s",5); m_backup_xml = true; std::string root_key; //为bcid做特化处理 #ifdef SPECIAL_BCID if(m_service_name=="bcid_info_cache") { char host_name[128]; gethostname(host_name, sizeof(host_name)); root_key = m_zk_service +"." + m_service_name+"."+std::string(host_name); } else #endif { root_key = m_zk_service + "." + m_service_name; } m_dis_conf = boost::shared_ptr<ZKDisConf>(new ZKDisConf(m_zk_host, m_zk_recv_to, root_key, m_backup_xml)); if(!m_dis_conf->init()) { LOG4CPLUS_ERROR(logger, "ZKDisConf " << m_dis_conf << " init failed"); return false; } // register callback func when redis status change m_dis_conf->register_update_cb(boost::bind(&SDRedisStatusChecker::sync_value, this, _1, _3)); // make sure the node has create std::string nothing; m_dis_conf->set_node_not_exist(root_key,nothing,true); // read from zk(construct local pt tree) m_dis_conf->read_zk(); LOG4CPLUS_DEBUG(logger, "ZKDisConf " << m_dis_conf << " init succ!"); return true; }
int main(int argc, char* argv[]) { char property_file[256]; LogInit(argv[0]); if(argc >= 2) { strcpy(property_file, argv[1]); } else { LogMsg("start server failed. argc=[%d]", argc); return 1; } //ignore some signal signal(SIGPIPE, SIG_IGN); //load config SDConfiguration conf; if(!conf.load(argv[1])) { LogMsg("load confige file failed. file path=[%s]", argv[1]); return 1; } g_server_ip = conf.getString("server_ip"); if(g_server_ip == "") { LogMsg("server ip is null"); return 1; } g_server_port = (unsigned int)conf.getInt("server_port"); if(g_server_port == 0) { LogMsg("server_port is null"); return 1; } g_db_ip = conf.getString("db_ip"); if(g_db_ip == "") { LogMsg("db_ip is null"); return 1; } g_db_username = conf.getString("db_username"); if(g_db_username == "") { LogMsg("db_username is null"); return 1; } g_db_psw = conf.getString("db_psw"); if(g_db_psw == "") { LogMsg("db_psw is null"); return 1; } // g_pack_import_q = new PacketQueue(100000); g_pack_outport_q = new PacketQueue(100000); // ProcServerThread ProcServer(g_pack_import_q, g_pack_outport_q , g_db_ip, g_db_username, g_db_psw); g_procServer = &ProcServer; create_robots(); //g_procServer->change_robot_zb_qianghua(); return 0; }