Exemple #1
0
void WorkerServer::dispatch(msgpack::rpc::request req)
{
    try
    {
        std::string method;
        req.method().convert(&method);

        WorkerHandlerBase* handler = router_.find(method);
        if (handler)
        {
            //handler->invoke(req);
            worker_pool_.schedule_task(boost::bind(handler_wrapper, handler, req));
        }
        else
        {
            std::cerr << "[WorkerServer] Method not found: " << method << std::endl;
            req.error(msgpack::rpc::NO_METHOD_ERROR);
        }
    }
    catch (const msgpack::type_error& e)
    {
        std::cerr << "[WorkerServer] " << e.what() << std::endl;
        req.error(msgpack::rpc::ARGUMENT_ERROR);
    }
    catch (const std::exception& e)
    {
        std::cerr << "[WorkerServer] " << e.what() << std::endl;
        req.error(std::string(e.what()));
    }
}
Exemple #2
0
void handler_wrapper(WorkerHandlerBase* handler, msgpack::rpc::request& req)
{
    try
    {
        handler->invoke(req);
    }
    catch (const msgpack::type_error& e)
    {
        std::cerr << "[WorkerServer] " << e.what() << std::endl;
        req.error(msgpack::rpc::ARGUMENT_ERROR);
    }
    catch (const std::exception& e)
    {
        std::cerr << "[WorkerServer] " << e.what() << std::endl;
        req.error(std::string(e.what()));
    }
}
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(&params);
            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(&params);
            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();
    }
}
Exemple #4
0
void server::dispatch(msgpack::rpc::request req)
try {
	std::string method;
	req.method().convert(&method);

	const table_type* table((table_type*)TABLE);

	table_type::const_iterator m = table->find(method);
	if(m == table->end()) {
		req.error(msgpack::rpc::NO_METHOD_ERROR);
		return;
	}

	(*m->second)(this, &req);

} catch (msgpack::type_error& e) {
	req.error(msgpack::rpc::ARGUMENT_ERROR);
	return;

} catch (std::exception& e) {
	req.error(std::string(e.what()));
	return;
}
Exemple #5
0
// rpc_server
//   Msgpack-RPC based server with 'hashed' dispatcher.
//   rpc_server can add RPC method on-the-fly.
//
void rpc_server::dispatch(msgpack::rpc::request req) {
  std::string method;
  req.method().convert(&method);

  func_map::iterator fun = funcs_.find(method);
  if (fun == funcs_.end()) {
    req.error(msgpack::rpc::NO_METHOD_ERROR, method);
    return;
  }

  try {
    fun->second->invoke(req);
  } catch(const msgpack::type_error& e) {
    req.error(msgpack::rpc::ARGUMENT_ERROR, std::string(e.what()));
  } catch(const jubatus::core::common::exception::jubatus_exception& e) {
    LOG(WARNING) << "exception in RPC thread: "
                 << e.diagnostic_information(true);
    req.error(std::string(e.what()));
  } catch(const std::exception& e) {
    LOG(ERROR) << "error in RPC thread: "
               << e.what();
    req.error(std::string(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(&params);
            push_queue(req, params.get<0>(), params.get<1>());
        } else if(method == "pop") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            pop_queue(req, params.get<0>());
        } else if(method == "push_nowait") {
            msgpack::type::tuple<std::string, std::string> params;
            req.params().convert(&params);
            push_queue_nowait(req, params.get<0>(), params.get<1>());
        } else if(method == "pop_nowait") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            pop_queue_nowait(req, params.get<0>());
        } else if(method == "add") {
            msgpack::type::tuple<std::string, int> params;
            req.params().convert(&params);
            add_queue(req, params.get<0>(), params.get<1>());
        /*
        } else if(method == "del") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            del_queue(req, params.get<0>());
        } else if(method == "fdel") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            force_del_queue(req, params.get<0>());
        */
        } else if(method == "set_capacity") {
            msgpack::type::tuple<std::string, int> params;
            req.params().convert(&params);
            set_queue_capacity(req, params.get<0>(), params.get<1>());
        } else if(method == "start") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            start_queue(req, params.get<0>());
        } else if(method == "stop") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            stop_queue(req, params.get<0>());
        } else if(method == "clear") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            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(&params);
            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;
    }
}
Exemple #7
0
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(&params);
            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(&params);
            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(&params);
            set_default_interval(req, params.get<0>());
        } else if(method == "set_site_interval") {
            msgpack::type::tuple<std::string, int> params;
            req.params().convert(&params);
            set_site_interval(req, params.get<0>(), params.get<1>());
        } else if(method == "stat_site") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            stat_site(req, params.get<0>());
        } else if(method == "dump_ordered_site") {
            msgpack::type::tuple<int> params;
            req.params().convert(&params);
            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(&params);
            start_site(req, params.get<0>());
        } else if(method == "stop_site") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            stop_site(req, params.get<0>());
        } else if(method == "clear_site") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            clear_site(req, params.get<0>());
        } else if(method == "start_dump_site") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            start_dump_site(req, params.get<0>());
        } else if(method == "dump_site") {
            msgpack::type::tuple<std::string> params;
            req.params().convert(&params);
            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;
    }
}