void AdStreamReceiveServer::dispatch(msgpack::rpc::request req) { try { std::string method; req.method().convert(&method); if (method == AdStreamReceiveServerRequest::method_names[AdStreamReceiveServerRequest::METHOD_TEST]) { LOG(INFO) << "got heart check msg."; //msgpack::type::tuple<bool> params; //req.params().convert(¶ms); req.result(true); } else if (method == AdStreamReceiveServerRequest::method_names[AdStreamReceiveServerRequest::METHOD_PUSH_ADMESSAGE]) { //LOG(INFO) << "got pushed ad msg"; //LOG(INFO) << "data:" << req.params(); msgpack::type::tuple<AdMessageListData> params; req.params().convert(¶ms); AdMessageListData& data_list = params.get<0>(); AdStreamSubscriber::get()->onAdMessage(data_list.msg_list); req.result(true); } else { req.error(msgpack::rpc::NO_METHOD_ERROR); } } catch (const msgpack::type_error& e) { req.error(msgpack::rpc::ARGUMENT_ERROR); LOG(WARNING) << "type error in rpc server." << e.what(); } catch (const std::exception& e) { req.error(std::string(e.what())); LOG(WARNING) << "exception in rpc server." << e.what(); } }
void QContentHubServer::dispatch(msgpack::rpc::request req) { try { std::string method; req.method().convert(&method); if(method == "push") { msgpack::type::tuple<std::string, std::string> params; req.params().convert(¶ms); push_queue(req, params.get<0>(), params.get<1>()); } else if(method == "pop") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); pop_queue(req, params.get<0>()); } else if(method == "push_nowait") { msgpack::type::tuple<std::string, std::string> params; req.params().convert(¶ms); push_queue_nowait(req, params.get<0>(), params.get<1>()); } else if(method == "pop_nowait") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); pop_queue_nowait(req, params.get<0>()); } else if(method == "add") { msgpack::type::tuple<std::string, int> params; req.params().convert(¶ms); add_queue(req, params.get<0>(), params.get<1>()); /* } else if(method == "del") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); del_queue(req, params.get<0>()); } else if(method == "fdel") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); force_del_queue(req, params.get<0>()); */ } else if(method == "set_capacity") { msgpack::type::tuple<std::string, int> params; req.params().convert(¶ms); set_queue_capacity(req, params.get<0>(), params.get<1>()); } else if(method == "start") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); start_queue(req, params.get<0>()); } else if(method == "stop") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); stop_queue(req, params.get<0>()); } else if(method == "clear") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); clear_queue(req, params.get<0>()); } else if(method == "stats") { stats(req); } else if(method == "stat_queue") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); stat_queue(req, params.get<0>()); } else { req.error(msgpack::rpc::NO_METHOD_ERROR); } } catch (msgpack::type_error& e) { req.error(msgpack::rpc::ARGUMENT_ERROR); return; } catch (std::exception& e) { req.error(std::string(e.what())); return; } }
void QUrlQueueServer::dispatch(msgpack::rpc::request req) { try { std::string method; req.method().convert(&method); if(method == "push") { msgpack::type::tuple<int, std::string, std::string> params; req.params().convert(¶ms); push_url(req, params.get<0>(), params.get<1>(), params.get<2>()); } else if(method == "pop") { pop_url(req); } else if(method == "push_url_front") { msgpack::type::tuple<int, std::string, std::string> params; req.params().convert(¶ms); push_url_front(req, params.get<0>(), params.get<1>(), params.get<2>()); } else if(method == "start_dump_all") { start_dump_all(req); } else if(method == "dump_all") { dump_all(req); } else if(method == "stats") { stats(req); } else if(method == "set_default_interval") { msgpack::type::tuple<int> params; req.params().convert(¶ms); set_default_interval(req, params.get<0>()); } else if(method == "set_site_interval") { msgpack::type::tuple<std::string, int> params; req.params().convert(¶ms); set_site_interval(req, params.get<0>(), params.get<1>()); } else if(method == "stat_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); stat_site(req, params.get<0>()); } else if(method == "dump_ordered_site") { msgpack::type::tuple<int> params; req.params().convert(¶ms); dump_ordered_site(req, params.get<0>()); } else if(method == "start_all") { start_all(req); } else if(method == "stop_all") { stop_all(req); } else if(method == "start_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); start_site(req, params.get<0>()); } else if(method == "stop_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); stop_site(req, params.get<0>()); } else if(method == "clear_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); clear_site(req, params.get<0>()); } else if(method == "start_dump_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); start_dump_site(req, params.get<0>()); } else if(method == "dump_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); dump_site(req, params.get<0>()); } else if(method == "clear_empty_site") { clear_empty_site(req); } else { req.error(msgpack::rpc::NO_METHOD_ERROR); } } catch (msgpack::type_error& e) { req.error(msgpack::rpc::ARGUMENT_ERROR); return; } catch (std::exception& e) { req.error(std::string(e.what())); return; } }