From a1738defeff50ca6392cc4da216ce8bb81589469 Mon Sep 17 00:00:00 2001 From: lijing Date: Thu, 19 Oct 2017 19:34:52 +0800 Subject: [PATCH] update monitor --- Main/ghttp.cpp | 34 +++++++++++++++++++++++++++++++--- Util/Util.h | 2 +- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Main/ghttp.cpp b/Main/ghttp.cpp index 44e9a2f..c83a72d 100644 --- a/Main/ghttp.cpp +++ b/Main/ghttp.cpp @@ -296,7 +296,26 @@ int initialize(int argc, char *argv[]) server.resource["^/%3[F|f]operation%3[D|d]unload%26db_name%3[D|d](.*)$"]["GET"]=[&server](shared_ptr response, shared_ptr request) { unload_handler(server, response, request); - }; + }; + + //GET-example for the path /?operation=build&db_name=[db_name]&ds_path=[ds_path], responds with the matched string in path + //i.e. database name and dataset path + server.resource["^/?operation=build&db_name=(.*)&ds_path=(.*)$"]["GET"]=[&server](shared_ptr response, shared_ptr request) + { + build_handler(server, response, request); + }; + + //GET-example for the path /?operation=load&db_name=[db_name], responds with the matched string in path + server.resource["^/?operation=load&db_name=(.*)$"]["GET"]=[&server](shared_ptr response, shared_ptr request) + { + load_handler(server, response, request); + }; + + //GET-example for the path /?operation=unload&db_name=[db_name], responds with the matched string in path + server.resource["^/?operation=unload&db_name=(.*)$"]["GET"]=[&server](shared_ptr response, shared_ptr request) + { + unload_handler(server, response, request); + }; #endif @@ -307,14 +326,15 @@ int initialize(int argc, char *argv[]) // server.resource["^/query/(.*)$"]["GET"] = [&server](shared_ptr response, shared_ptr request) { }; + //NOTICE:this may not be visited by browser directly if the browser does not do URL encode automatically! //In programming language, do URL encode first and then call server, then all is ok - server.resource["^/%3Foperation%3[D|d]monitor$"]["GET"]=[&server](shared_ptr response, shared_ptr request) + server.resource["^/?operation=monitor$"]["GET"]=[&server](shared_ptr response, shared_ptr request) { //server.resource["^/monitor$"]["GET"]=[&server](shared_ptr response, shared_ptr request) { monitor_handler(server, response, request); }; - + // server.resource["^/json$"]["POST"]=[](shared_ptr response, shared_ptr request) { // try { // ptree pt; @@ -985,6 +1005,14 @@ bool download_handler(const HttpServer& server, const shared_ptr& response, const shared_ptr& request) { cout<<"HTTP: this is default"<path; + cout << "request url: " << req_url << endl; + //if request matches /?operation=monitor, then do monitor_handler + //because if the user visit through the browser by using url /?operation=monitor + //it can not match directly to monitor_handler, and will match this default get + //so we need to check here to do monitor_handler, although the implementation is not perfect enough. + if(req_url == "/?operation=monitor") + monitor_handler(server, response, request); //BETTER: use lock to ensure thread safe connection_num++; //NOTICE: it seems a visit will output twice times diff --git a/Util/Util.h b/Util/Util.h index 367ea31..3a7444b 100644 --- a/Util/Util.h +++ b/Util/Util.h @@ -111,7 +111,7 @@ in the sparql query can point to the same node in data graph) //if used as only-read application(like sparql endpoint) //#define ONLY_READ 1 -//#define SPARQL_ENDPOINT 1 +#define SPARQL_ENDPOINT 1 #ifdef SPARQL_ENDPOINT #ifndef ONLY_READ #define ONLY_READ 1