summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/components/log
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/trunk/components/log')
-rw-r--r--sca-cpp/trunk/components/log/Makefile.am2
-rw-r--r--sca-cpp/trunk/components/log/client-test.cpp57
-rw-r--r--sca-cpp/trunk/components/log/log.cpp37
-rw-r--r--sca-cpp/trunk/components/log/logger.cpp46
-rw-r--r--sca-cpp/trunk/components/log/scribe-cat.cpp8
-rw-r--r--sca-cpp/trunk/components/log/scribe-status.cpp2
-rw-r--r--sca-cpp/trunk/components/log/scribe.hpp38
7 files changed, 70 insertions, 120 deletions
diff --git a/sca-cpp/trunk/components/log/Makefile.am b/sca-cpp/trunk/components/log/Makefile.am
index 0e96be5697..45074b11a4 100644
--- a/sca-cpp/trunk/components/log/Makefile.am
+++ b/sca-cpp/trunk/components/log/Makefile.am
@@ -70,7 +70,7 @@ scribe_status_SOURCES = scribe-status.cpp
scribe_status_LDFLAGS = -L${THRIFT_LIB} -R${THRIFT_LIB} -lthrift -L${FB303_LIB} -R${FB303_LIB} -lfb303 -L${SCRIBE_LIB} -R${SCRIBE_LIB} -lscribe
client_test_SOURCES = client-test.cpp
-client_test_LDFLAGS = -lxml2 -lcurl -lmozjs
+client_test_LDFLAGS = -lxml2 -lcurl -ljansson
dist_noinst_SCRIPTS = scribe-test server-test
noinst_PROGRAMS = client-test
diff --git a/sca-cpp/trunk/components/log/client-test.cpp b/sca-cpp/trunk/components/log/client-test.cpp
index d8cac5ee81..6e0ecaf89e 100644
--- a/sca-cpp/trunk/components/log/client-test.cpp
+++ b/sca-cpp/trunk/components/log/client-test.cpp
@@ -38,15 +38,15 @@ namespace log {
const string uri("http://localhost:8090/log");
-bool testLog() {
- http::CURLSession cs("", "", "", "", 0);
-
- const list<value> i = list<value>() + "content" + (list<value>() + "item"
- + (list<value>() + "name" + string("Apple"))
- + (list<value>() + "price" + string("$2.99")));
- const list<value> a = list<value>() + (list<value>() + "entry"
- + (list<value>() + "title" + string("item"))
- + (list<value>() + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+const bool testLog() {
+ const http::CURLSession cs("", "", "", "", 0);
+
+ const list<value> i = nilListValue + "content" + (nilListValue + "item"
+ + (nilListValue + "name" + string("Apple"))
+ + (nilListValue + "price" + string("$2.99")));
+ const list<value> a = nilListValue + (nilListValue + "entry"
+ + (nilListValue + "title" + string("item"))
+ + (nilListValue + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
const failable<value> id = http::post(a, uri, cs);
@@ -55,40 +55,31 @@ bool testLog() {
return true;
}
-struct logLoop {
- const value a;
- const string uri;
- http::CURLSession& cs;
- logLoop(const value& a, const string& uri, http::CURLSession& cs) : a(a), uri(uri), cs(cs) {
- }
- const bool operator()() const {
- const failable<value> id = http::post(a, uri, cs);
- assert(hasContent(id));
- return true;
- }
-};
-
-bool testLogPerf() {
- const list<value> i = list<value>() + "content" + (list<value>() + "item"
- + (list<value>() + "name" + string("Apple"))
- + (list<value>() + "price" + string("$2.99")));
- const list<value> a = list<value>() + (list<value>() + "entry"
- + (list<value>() + "title" + string("item"))
- + (list<value>() + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+const bool testLogPerf() {
+ const list<value> i = nilListValue + "content" + (nilListValue + "item"
+ + (nilListValue + "name" + string("Apple"))
+ + (nilListValue + "price" + string("$2.99")));
+ const list<value> a = nilListValue + (nilListValue + "entry"
+ + (nilListValue + "title" + string("item"))
+ + (nilListValue + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
- http::CURLSession cs("", "", "", "", 0);
+ const http::CURLSession cs("", "", "", "", 0);
const failable<value> id = http::post(a, uri, cs);
assert(hasContent(id));
- const lambda<bool()> ll = logLoop(a, uri, cs);
+ const blambda ll = [a, uri, cs]() -> const bool {
+ const failable<value> id = http::post(a, uri, cs);
+ assert(hasContent(id));
+ return true;
+ };
cout << "Log test " << time(ll, 5, 200) << " ms" << endl;
return true;
}
-bool testLogger() {
- http::CURLSession cs("", "", "", "", 0);
+const bool testLogger() {
+ const http::CURLSession cs("", "", "", "", 0);
const failable<value> res = http::evalExpr(mklist<value>(string("sum"), 33, 22), string("http://localhost:8090/client"), cs);
assert(hasContent(res));
diff --git a/sca-cpp/trunk/components/log/log.cpp b/sca-cpp/trunk/components/log/log.cpp
index f7f7086192..11d24c8da5 100644
--- a/sca-cpp/trunk/components/log/log.cpp
+++ b/sca-cpp/trunk/components/log/log.cpp
@@ -38,7 +38,7 @@ namespace log {
/**
* Post an item to the Scribe log.
*/
-const failable<value> post(const list<value>& params, const value& host, const value& category, scribe::Scribe& sc) {
+const failable<value> post(const list<value>& params, const value& host, const value& category, const scribe::Scribe& sc) {
debug(cadr(params), "log::post::value");
const failable<bool> val = scribe::log(cadr(params), host, category, sc);
if (!hasContent(val))
@@ -47,41 +47,26 @@ const failable<value> post(const list<value>& params, const value& host, const v
}
/**
- * Component implementation lambda function.
- */
-class applyLog {
-public:
- applyLog(const value& host, const value& category, scribe::Scribe& sc) : host(host), category(category), sc(sc) {
- }
-
- const value operator()(const list<value>& params) const {
- const value func(car(params));
- if (func == "post")
- return post(cdr(params), host, category, sc);
- return mkfailure<value>();
- }
-
-private:
- const value host;
- const value category;
- scribe::Scribe& sc;
-};
-
-/**
* Start the component.
*/
const failable<value> start(const list<value>& params) {
// Connect to Scribe
- scribe::Scribe& sc = *(new (gc_new<scribe::Scribe>()) scribe::Scribe("localhost", 1464));
+ const scribe::Scribe& sc = *(new (gc_new<scribe::Scribe>()) scribe::Scribe("localhost", 1464));
// Extract the configured category
- const value host = ((lambda<value(const list<value>&)>)car(params))(list<value>());
- const value category = ((lambda<value(const list<value>&)>)cadr(params))(list<value>());
+ const value host = ((lvvlambda)car(params))(nilListValue);
+ const value category = ((lvvlambda)cadr(params))(nilListValue);
debug(host, "log::start::host");
debug(category, "log::start::category");
// Return the component implementation lambda function
- return value(lambda<value(const list<value>&)>(applyLog(host, category, sc)));
+ const lvvlambda applyLog = [host, category, sc](const list<value>& params) -> const value {
+ const value func(car(params));
+ if (func == "post")
+ return post(cdr(params), host, category, sc);
+ return mkfailure<value>();
+ };
+ return value(applyLog);
}
}
diff --git a/sca-cpp/trunk/components/log/logger.cpp b/sca-cpp/trunk/components/log/logger.cpp
index d7969036ab..46fd1f7cb4 100644
--- a/sca-cpp/trunk/components/log/logger.cpp
+++ b/sca-cpp/trunk/components/log/logger.cpp
@@ -37,14 +37,21 @@ namespace tuscany {
namespace logger {
/**
- * Component implementation lambda function.
+ * Start the component.
*/
-class applyLog {
-public:
- applyLog(const lambda<value(const list<value>&)>& relay, const value& host, const value& category, scribe::Scribe& sc) : relay(relay), host(host), category(category), sc(sc) {
- }
+const failable<value> start(const list<value>& params) {
+ // Connect to Scribe
+ const scribe::Scribe& sc = *(new (gc_new<scribe::Scribe>()) scribe::Scribe("localhost", 1464));
- const value operator()(const list<value>& params) const {
+ // Extract the configured relay service and category
+ const value relay = car(params);
+ const value host = ((lvvlambda)cadr(params))(nilListValue);
+ const value category = ((lvvlambda)caddr(params))(nilListValue);
+ debug(host, "logger::start::host");
+ debug(category, "logger::start::category");
+
+ // Return the component implementation lambda function
+ const lvvlambda applyLog = [relay, host, category, sc](const list<value>& params) -> const value {
// Log the function params
debug(params, "logger::apply::params");
scribe::log(params, host, category, sc);
@@ -55,31 +62,8 @@ public:
// Log the result
scribe::log(res, host, category, sc);
return res;
- }
-
-private:
- const lambda<value(const list<value>&)> relay;
- const value host;
- const value category;
- scribe::Scribe& sc;
-};
-
-/**
- * Start the component.
- */
-const failable<value> start(const list<value>& params) {
- // Connect to Scribe
- scribe::Scribe& sc = *(new (gc_new<scribe::Scribe>()) scribe::Scribe("localhost", 1464));
-
- // Extract the configured relay service and category
- const value rel = car(params);
- const value host = ((lambda<value(const list<value>&)>)cadr(params))(list<value>());
- const value category = ((lambda<value(const list<value>&)>)caddr(params))(list<value>());
- debug(host, "logger::start::host");
- debug(category, "logger::start::category");
-
- // Return the component implementation lambda function
- return value(lambda<value(const list<value>&)>(applyLog(rel, host, category, sc)));
+ };
+ return value(applyLog);
}
}
diff --git a/sca-cpp/trunk/components/log/scribe-cat.cpp b/sca-cpp/trunk/components/log/scribe-cat.cpp
index 254e2167ae..d9a2e44613 100644
--- a/sca-cpp/trunk/components/log/scribe-cat.cpp
+++ b/sca-cpp/trunk/components/log/scribe-cat.cpp
@@ -36,14 +36,14 @@
namespace tuscany {
namespace scribecat {
-int cat(const string& host, const string& category, const string& type) {
+const int cat(const string& host, const string& category, const string& type) {
// Connect to Scribe
scribe::Scribe& sc = *(new (gc_new<scribe::Scribe>()) scribe::Scribe(host, 1464));
// Read lines from stdin and log them
char buf[8193];
for (;;) {
- gc_scoped_pool p;
+ const gc_scoped_pool p;
// Write line prefix
ostringstream os;
@@ -54,7 +54,7 @@ int cat(const string& host, const string& category, const string& type) {
strcpy(buf, c_str(prefix));
// Read log line
- const char* s = fgets(buf + pl, 8192 - pl, stdin);
+ const char* const s = fgets(buf + pl, 8192 - pl, stdin);
if (s == NULL)
return 0;
@@ -73,7 +73,7 @@ int cat(const string& host, const string& category, const string& type) {
}
}
-int main(const int argc, const char** argv) {
+int main(const int argc, const char** const argv) {
return tuscany::scribecat::cat(argc < 2? "localhost" : argv[1], argc < 3? "default" : argv[2], argc < 4? "" : argv[3]);
}
diff --git a/sca-cpp/trunk/components/log/scribe-status.cpp b/sca-cpp/trunk/components/log/scribe-status.cpp
index 79f7572947..7dbf94542b 100644
--- a/sca-cpp/trunk/components/log/scribe-status.cpp
+++ b/sca-cpp/trunk/components/log/scribe-status.cpp
@@ -60,7 +60,7 @@ const int status(const string& host, const int port) {
}
}
-int main(const int argc, const char** argv) {
+int main(const int argc, const char** const argv) {
return tuscany::scribestatus::status(argc < 2? "localhost" : argv[1], argc < 3? 1463 : atoi(argv[2]));
}
diff --git a/sca-cpp/trunk/components/log/scribe.hpp b/sca-cpp/trunk/components/log/scribe.hpp
index 0f0570be64..fd18f53bb7 100644
--- a/sca-cpp/trunk/components/log/scribe.hpp
+++ b/sca-cpp/trunk/components/log/scribe.hpp
@@ -74,21 +74,11 @@ public:
init(host, port);
}
- Scribe(const Scribe& c) : owner(false) {
+ Scribe(const Scribe& c) : owner(false), client(c.client), transport(c.transport) {
debug("scribe::scribe::copy");
- client = c.client;
- transport = c.transport;
}
- const Scribe& operator=(const Scribe& c) {
- debug("scribe::scribe::operator=");
- if(this == &c)
- return *this;
- owner = false;
- client = c.client;
- transport = c.transport;
- return *this;
- }
+ Scribe& operator=(const Scribe& c) = delete;
~Scribe() {
if (!owner)
@@ -102,7 +92,7 @@ public:
}
private:
- bool owner;
+ const bool owner;
::scribe::thrift::scribeClient* client;
boost::shared_ptr<apache::thrift::transport::TTransport> transport;
@@ -135,8 +125,8 @@ const failable<bool> log(const value& val, const string& host, const value& cate
debug(category, "scribe::log::category");
const value cat = isString(category)? value(c_str(category)):category;
- const string cs(scheme::writeValue(cat));
- const string vs(scheme::writeValue(val));
+ const string cs(write(content(scheme::writeValue(cat))));
+ const string vs(write(content(scheme::writeValue(val))));
ostringstream os;
os << "[" << host << "] " << vs;
@@ -147,8 +137,8 @@ const failable<bool> log(const value& val, const string& host, const value& cate
std::vector< ::scribe::thrift::LogEntry> msgs;
msgs.push_back(entry);
- int result = sc.client->Log(msgs);
- if (result != ::scribe::thrift::OK)
+ const int result = sc.client->Log(msgs);
+ if (result != ::scribe::thrift::ResultCode::OK)
return mkfailure<bool>("Could not log value, retry later");
} catch (const std::exception& e) {
return mkfailure<bool>(e.what());
@@ -165,24 +155,24 @@ const failable<string> status(const Scribe& sc) {
debug("scribe::status");
try {
- ::facebook::fb303::fb_status s = sc.client->getStatus();
+ ::facebook::fb303::fb_status::type s = sc.client->getStatus();
switch(s) {
- case ::facebook::fb303::DEAD:
+ case ::facebook::fb303::fb_status::DEAD:
debug("DEAD", "scribe::status::result");
return string("DEAD");
- case ::facebook::fb303::STARTING:
+ case ::facebook::fb303::fb_status::STARTING:
debug("STARTING", "scribe::status::result");
return string("STARTING");
- case ::facebook::fb303::ALIVE:
+ case ::facebook::fb303::fb_status::ALIVE:
debug("ALIVE", "scribe::status::result");
return string("ALIVE");
- case ::facebook::fb303::STOPPING:
+ case ::facebook::fb303::fb_status::STOPPING:
debug("STOPPING", "scribe::status::result");
return string("STOPPING");
- case ::facebook::fb303::STOPPED:
+ case ::facebook::fb303::fb_status::STOPPED:
debug("STOPPED", "scribe::status::result");
return string("STOPPED");
- case ::facebook::fb303::WARNING:
+ case ::facebook::fb303::fb_status::WARNING:
debug("WARNING", "scribe::status::result");
return string("WARNING");
}