From 36adc76235fb0a38e7042bc751f988b71627e2a0 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Tue, 11 Dec 2012 06:13:02 +0000 Subject: Changes to get successful C++11 based build. Code cleanup, dependency upgrades, and const + inline optimizations in components, samples, and app hosting server. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1420007 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/components/cache/Makefile.am | 2 +- sca-cpp/trunk/components/cache/cache.composite | 2 +- sca-cpp/trunk/components/cache/client-test.cpp | 83 +++++++++----------- sca-cpp/trunk/components/cache/datacache.cpp | 12 +-- sca-cpp/trunk/components/cache/memcache-test.cpp | 26 +++---- sca-cpp/trunk/components/cache/memcache.cpp | 51 +++++-------- sca-cpp/trunk/components/cache/memcache.hpp | 78 ++++++++++--------- sca-cpp/trunk/components/cache/memocache.cpp | 2 +- sca-cpp/trunk/components/cache/partitioner.cpp | 97 ++++++++++++++++-------- sca-cpp/trunk/components/cache/select-test.scm | 2 +- 10 files changed, 184 insertions(+), 171 deletions(-) (limited to 'sca-cpp/trunk/components/cache') diff --git a/sca-cpp/trunk/components/cache/Makefile.am b/sca-cpp/trunk/components/cache/Makefile.am index 0240a32bb4..3704a7a3ce 100644 --- a/sca-cpp/trunk/components/cache/Makefile.am +++ b/sca-cpp/trunk/components/cache/Makefile.am @@ -50,7 +50,7 @@ memcache_test_SOURCES = memcache-test.cpp memcache_test_LDFLAGS = -lxml2 client_test_SOURCES = client-test.cpp -client_test_LDFLAGS = -lxml2 -lcurl -lmozjs +client_test_LDFLAGS = -lxml2 -lcurl -ljansson dist_noinst_SCRIPTS = memcached-test memcached-ssl-test server-test noinst_PROGRAMS = memcache-test client-test diff --git a/sca-cpp/trunk/components/cache/cache.composite b/sca-cpp/trunk/components/cache/cache.composite index a85f909db9..99fdd8ffc0 100644 --- a/sca-cpp/trunk/components/cache/cache.composite +++ b/sca-cpp/trunk/components/cache/cache.composite @@ -81,7 +81,7 @@ - + diff --git a/sca-cpp/trunk/components/cache/client-test.cpp b/sca-cpp/trunk/components/cache/client-test.cpp index 63d1691f8b..5e9be6c14a 100644 --- a/sca-cpp/trunk/components/cache/client-test.cpp +++ b/sca-cpp/trunk/components/cache/client-test.cpp @@ -42,15 +42,15 @@ const string memocacheuri("http://localhost:8090/memocache"); const string partition1uri("http://localhost:8090/partitioner/a"); const string partition2uri("http://localhost:8090/partitioner/b"); -bool testCache(const string& uri) { - http::CURLSession cs("", "", "", "", 0); - - const list i = list() + "content" + (list() + "item" - + (list() + "name" + string("Apple")) - + (list() + "price" + string("$2.99"))); - const list a = list() + (list() + "entry" - + (list() + "title" + string("item")) - + (list() + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b")) +const bool testCache(const string& uri) { + const http::CURLSession cs("", "", "", "", 0); + + const list i = nilListValue + "content" + (nilListValue + "item" + + (nilListValue + "name" + string("Apple")) + + (nilListValue + "price" + string("$2.99"))); + const list a = nilListValue + (nilListValue + "entry" + + (nilListValue + "title" + string("item")) + + (nilListValue + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b")) + i); const failable id = http::post(a, uri, cs); @@ -63,18 +63,18 @@ bool testCache(const string& uri) { assert(content(val) == a); } - const list j = list() + "content" + (list() + "item" - + (list() + "name" + string("Apple")) - + (list() + "price" + string("$3.55"))); - const list b = list() + (list() + "entry" - + (list() + "title" + string("item")) - + (list() + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b")) + const list j = nilListValue + "content" + (nilListValue + "item" + + (nilListValue + "name" + string("Apple")) + + (nilListValue + "price" + string("$3.55"))); + const list b = nilListValue + (nilListValue + "entry" + + (nilListValue + "title" + string("item")) + + (nilListValue + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b")) + j); { const failable r = http::put(b, uri + p, cs); assert(hasContent(r)); - assert(content(r) == value(true)); + assert(content(r) == trueValue); } { const failable val = http::get(uri + p, cs); @@ -84,7 +84,7 @@ bool testCache(const string& uri) { { const failable r = http::del(uri + p, cs); assert(hasContent(r)); - assert(content(r) == value(true)); + assert(content(r) == trueValue); } { const failable val = http::get(uri + p, cs); @@ -94,16 +94,16 @@ bool testCache(const string& uri) { return true; } -bool testMemcache() { +const bool testMemcache() { return testCache(memcacheuri); } -bool testDatacache() { +const bool testDatacache() { return testCache(datacacheuri); } -bool testMemocache() { - http::CURLSession cs("", "", "", "", 0); +const bool testMemocache() { + const http::CURLSession cs("", "", "", "", 0); const failable res = http::evalExpr(mklist(string("add"), 33, 22), memocacheuri, cs); assert(hasContent(res)); @@ -116,8 +116,8 @@ bool testMemocache() { return true; } -bool testPartitioner() { - http::CURLSession cs("", "", "", "", 0); +const bool testPartitioner() { + const http::CURLSession cs("", "", "", "", 0); const failable res1 = http::get(partition1uri, cs); assert(hasContent(res1)); @@ -130,35 +130,26 @@ bool testPartitioner() { return true; } -struct getLoop { - const string path; - const value entry; - http::CURLSession& cs; - getLoop(const string& path, const value& entry, http::CURLSession& cs) : path(path), entry(entry), cs(cs) { - } - const bool operator()() const { - const failable val = http::get(memcacheuri + path, cs); - assert(hasContent(val)); - assert(content(val) == entry); - return true; - } -}; - -bool testGetPerf() { - const list i = list() + "content" + (list() + "item" - + (list() + "name" + string("Apple")) - + (list() + "price" + string("$4.55"))); - const list a = list() + (list() + "entry" - + (list() + "title" + string("item")) - + (list() + "id" + string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b")) +const bool testGetPerf() { + const list i = nilListValue + "content" + (nilListValue + "item" + + (nilListValue + "name" + string("Apple")) + + (nilListValue + "price" + string("$4.55"))); + const list 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 id = http::post(a, memcacheuri, cs); assert(hasContent(id)); const string p = path(content(id)); - const lambda gl = getLoop(p, a, cs); + const blambda gl = [p, a, cs]() -> const bool { + const failable val = http::get(memcacheuri + p, cs); + assert(hasContent(val)); + assert(content(val) == a); + return true; + }; cout << "Cache get test " << time(gl, 5, 200) << " ms" << endl; return true; diff --git a/sca-cpp/trunk/components/cache/datacache.cpp b/sca-cpp/trunk/components/cache/datacache.cpp index c259ec33c6..975ca43dce 100644 --- a/sca-cpp/trunk/components/cache/datacache.cpp +++ b/sca-cpp/trunk/components/cache/datacache.cpp @@ -44,7 +44,7 @@ namespace datacache { /** * Get an item from the cache. */ -const failable get(const value& key, const lambda&)>& rcache1, const lambda&)>& wcache1, const lambda&)>& rcache2, unused const lambda&)>& wcache2) { +const failable get(const value& key, const lvvlambda& rcache1, const lvvlambda& wcache1, const lvvlambda& rcache2, unused const lvvlambda& wcache2) { // Lookup level1 cache const value val1 = rcache1(mklist("get", key)); @@ -68,7 +68,7 @@ const failable get(const value& key, const lambda /** * Post an item to the cache. */ -const failable post(const value& key, const value& val, unused const lambda&)>& rcache1, const lambda&)>& wcache1, unused const lambda&)>& rcache2, const lambda&)>& wcache2) { +const failable post(const value& key, const value& val, unused const lvvlambda& rcache1, const lvvlambda& wcache1, unused const lvvlambda& rcache2, const lvvlambda& wcache2) { const value id = append(key, mklist(mkuuid())); // Update level1 cache @@ -83,7 +83,7 @@ const failable post(const value& key, const value& val, unused const lamb /** * Put an item into the cache. */ -const failable put(const value& key, const value& val, unused const lambda&)>& rcache1, const lambda&)>& wcache1, unused const lambda&)>& rcache2, const lambda&)>& wcache2) { +const failable put(const value& key, const value& val, unused const lvvlambda& rcache1, const lvvlambda& wcache1, unused const lvvlambda& rcache2, const lvvlambda& wcache2) { // Update level1 cache wcache1(mklist("put", key, val)); @@ -91,13 +91,13 @@ const failable put(const value& key, const value& val, unused const lambd // Update level2 cache wcache2(mklist("put", key, val)); - return value(true); + return trueValue; } /** * Delete an item from the cache. */ -const failable del(const value& key, unused const lambda&)>& rcache1, const lambda&)>& wcache1, unused const lambda&)>& rcache2, const lambda&)>& wcache2) { +const failable del(const value& key, unused const lvvlambda& rcache1, const lvvlambda& wcache1, unused const lvvlambda& rcache2, const lvvlambda& wcache2) { // Delete from level1 cache wcache1(mklist("delete", key)); @@ -105,7 +105,7 @@ const failable del(const value& key, unused const lambda("delete", key)); - return value(true); + return trueValue; } } diff --git a/sca-cpp/trunk/components/cache/memcache-test.cpp b/sca-cpp/trunk/components/cache/memcache-test.cpp index 85fc339f1a..6c6adb0541 100644 --- a/sca-cpp/trunk/components/cache/memcache-test.cpp +++ b/sca-cpp/trunk/components/cache/memcache-test.cpp @@ -33,7 +33,7 @@ namespace tuscany { namespace memcache { bool testMemCached() { - MemCached ch(mklist("localhost:11211", "localhost:11212", "localhost:11213")); + const MemCached ch(mklist("localhost:11211", "localhost:11212", "localhost:11213")); const value k = mklist("a"); assert(hasContent(post(k, string("AAA"), ch))); @@ -46,24 +46,16 @@ bool testMemCached() { return true; } -struct getLoop { - const value k; - MemCached& ch; - getLoop(const value& k, MemCached& ch) : k(k), ch(ch) { - } - const bool operator()() const { - gc_scoped_pool p; - assert(get(k, ch) == value(string("CCC"))); - return true; - } -}; - -bool testGetPerf() { +const bool testGetPerf() { const value k = mklist("c"); - MemCached ch(mklist("localhost:11211", "localhost:11212", "localhost:11213")); + const MemCached ch(mklist("localhost:11211", "localhost:11212", "localhost:11213")); assert(hasContent(post(k, string("CCC"), ch))); - const lambda gl = getLoop(k, ch); + const blambda gl = [k, ch]() -> const bool { + const gc_scoped_pool p; + assert(get(k, ch) == value(string("CCC"))); + return true; + }; cout << "Memcached get test " << time(gl, 5, 200) << " ms" << endl; return true; } @@ -72,7 +64,7 @@ bool testGetPerf() { } int main() { - tuscany::gc_scoped_pool p; + const tuscany::gc_scoped_pool p; tuscany::cout << "Testing..." << tuscany::endl; tuscany::memcache::testMemCached(); diff --git a/sca-cpp/trunk/components/cache/memcache.cpp b/sca-cpp/trunk/components/cache/memcache.cpp index 738a6ddd5a..2e4597efd3 100644 --- a/sca-cpp/trunk/components/cache/memcache.cpp +++ b/sca-cpp/trunk/components/cache/memcache.cpp @@ -37,14 +37,14 @@ namespace cache { /** * Get an item from the cache. */ -const failable get(const list& params, memcache::MemCached& ch) { +const failable get(const list& params, const memcache::MemCached& ch) { return memcache::get(car(params), ch); } /** * Post an item to the cache. */ -const failable post(const list& params, memcache::MemCached& ch) { +const failable post(const list& params, const memcache::MemCached& ch) { const value id = append(car(params), mklist(mkuuid())); const failable val = memcache::post(id, cadr(params), ch); if (!hasContent(val)) @@ -55,7 +55,7 @@ const failable post(const list& params, memcache::MemCached& ch) { /** * Put an item into the cache. */ -const failable put(const list& params, memcache::MemCached& ch) { +const failable put(const list& params, const memcache::MemCached& ch) { const failable val = memcache::put(car(params), cadr(params), ch); if (!hasContent(val)) return mkfailure(val); @@ -65,45 +65,20 @@ const failable put(const list& params, memcache::MemCached& ch) { /** * Delete an item from the cache. */ -const failable del(const list& params, memcache::MemCached& ch) { +const failable del(const list& params, const memcache::MemCached& ch) { const failable val = memcache::del(car(params), ch); if (!hasContent(val)) return mkfailure(val); return value(content(val)); } -/** - * Component implementation lambda function. - */ -class applyCache { -public: - applyCache(memcache::MemCached& ch) : ch(ch) { - } - - const value operator()(const list& params) const { - const value func(car(params)); - if (func == "get") - return get(cdr(params), ch); - if (func == "post") - return post(cdr(params), ch); - if (func == "put") - return put(cdr(params), ch); - if (func == "delete") - return del(cdr(params), ch); - return mkfailure(); - } - -private: - memcache::MemCached& ch; -}; - /** * Convert a list of properties to a list of server addresses. */ const list servers(const list& params) { if (isNil(params)) return list(); - const value s = ((lambda&)>)car(params))(list()); + const value s = ((lvvlambda)car(params))(nilListValue); return cons(s, servers(cdr(params))); } @@ -112,10 +87,22 @@ const list servers(const list& params) { */ const failable start(const list& params) { // Connect to memcached - memcache::MemCached& ch = *(new (gc_new()) memcache::MemCached(servers(params))); + const memcache::MemCached& ch = *(new (gc_new()) memcache::MemCached(servers(params))); // Return the component implementation lambda function - return value(lambda&)>(applyCache(ch))); + const lvvlambda applyCache = [ch](const list& params) -> const value { + const value func(car(params)); + if (func == "get") + return get(cdr(params), ch); + if (func == "post") + return post(cdr(params), ch); + if (func == "put") + return put(cdr(params), ch); + if (func == "delete") + return del(cdr(params), ch); + return mkfailure(); + }; + return value(applyCache); } } diff --git a/sca-cpp/trunk/components/cache/memcache.hpp b/sca-cpp/trunk/components/cache/memcache.hpp index f18405b2ec..00ee9c6291 100644 --- a/sca-cpp/trunk/components/cache/memcache.hpp +++ b/sca-cpp/trunk/components/cache/memcache.hpp @@ -48,43 +48,28 @@ namespace memcache { */ class MemCached { public: - MemCached() : owner(false) { + MemCached() : owner(false), mc(NULL) { } - MemCached(const string host, const int port) : p(), owner(true) { - debug(host, "memcache::memcached::host"); - debug(port, "memcache::memcached::port"); - apr_memcache_create(pool(p), 1, 0, &mc); - addServer(host, port); + MemCached(const string& host, const int port) : p(), owner(true), mc(mkmc(host, port)) { } - MemCached(const list& servers) : p(), owner(true) { - debug(servers, "memcache::memcached::servers"); - apr_memcache_create(pool(p), (apr_uint16_t)length(servers), 0, &mc); - addServers(servers); + MemCached(const list& servers) : p(), owner(true), mc(mkmc(servers)) { } MemCached(const MemCached& c) : p(c.p), owner(false), mc(c.mc) { debug("memcache::memcached::copy"); } - const MemCached& operator=(const MemCached& c) { - debug("memcache::memcached::operator="); - if(this == &c) - return *this; - p = c.p; - owner = false; - mc = c.mc; - return *this; - } + MemCached& operator=(const MemCached& c) = delete; ~MemCached() { } private: - gc_child_pool p; - bool owner; - apr_memcache_t* mc; + const gc_child_pool p; + const bool owner; + apr_memcache_t* const mc; friend const failable post(const value& key, const value& val, const MemCached& cache); friend const failable put(const value& key, const value& val, const MemCached& cache); @@ -94,7 +79,7 @@ private: /** * Add servers to the memcached context. */ - const failable addServer(const string& host, const int port) { + const failable addServer(apr_memcache_t* const m, const string& host, const int port) { apr_memcache_server_t *server; const apr_status_t sc = apr_memcache_server_create(pool(p), c_str(host), (apr_port_t)port, 1, 1, 1, 600, &server); if (sc != APR_SUCCESS) { @@ -102,27 +87,48 @@ private: os << "Couldn't connect to memcached server: " << host << ":" << port; return mkfailure(str(os)); } - const apr_status_t as = apr_memcache_add_server(mc, server); + const apr_status_t as = apr_memcache_add_server(m, server); if (as != APR_SUCCESS) return mkfailure("Couldn't add memcached server"); return true; } - const failable addServers(const list& servers) { + const failable addServers(apr_memcache_t* const m, const list& servers) { if (isNil(servers)) return true; const list toks = tokenize(":", car(servers)); - const failable r = addServer(car(toks), isNil(cdr(toks))? 11211 : atoi(c_str(cadr(toks)))); + const failable r = addServer(m, car(toks), isNil(cdr(toks))? 11211 : atoi(c_str(cadr(toks)))); if (!hasContent(r)) return r; - return addServers(cdr(servers)); + return addServers(m, cdr(servers)); + } + + /** + * Create memcached handle. + */ + apr_memcache_t* const mkmc(const string& host, const int port) { + debug(host, "memcache::memcached::host"); + debug(port, "memcache::memcached::port"); + apr_memcache_t* m; + apr_memcache_create(pool(p), 1, 0, &m); + addServer(m, host, port); + return m; } + + apr_memcache_t* const mkmc(const list& servers) { + debug(servers, "memcache::memcached::servers"); + apr_memcache_t* m; + apr_memcache_create(pool(p), (apr_uint16_t)length(servers), 0, &m); + addServers(m, servers); + return m; + } + }; /** * Replace spaces by tabs (as spaces are not allowed in memcached keys). */ -const char* nospaces(const char* s) { +const char* const nospaces(const char* const s) { char* c = const_cast(s); for (; *c; c++) if (*c == ' ') @@ -137,8 +143,8 @@ const failable post(const value& key, const value& val, const MemCached& c debug(key, "memcache::post::key"); debug(val, "memcache::post::value"); - const string ks(scheme::writeValue(key)); - const string vs(scheme::writeValue(val)); + const string ks(write(content(scheme::writeValue(key)))); + const string vs(write(content(scheme::writeValue(val)))); const apr_status_t rc = apr_memcache_add(cache.mc, nospaces(c_str(ks)), const_cast(c_str(vs)), length(vs), 0, 27); if (rc != APR_SUCCESS) { ostringstream os; @@ -157,8 +163,8 @@ const failable put(const value& key, const value& val, const MemCached& ca debug(key, "memcache::put::key"); debug(val, "memcache::put::value"); - const string ks(scheme::writeValue(key)); - const string vs(scheme::writeValue(val)); + const string ks(write(content(scheme::writeValue(key)))); + const string vs(write(content(scheme::writeValue(val)))); const apr_status_t rc = apr_memcache_set(cache.mc, nospaces(c_str(ks)), const_cast(c_str(vs)), length(vs), 0, 27); if (rc != APR_SUCCESS) { ostringstream os; @@ -176,17 +182,17 @@ const failable put(const value& key, const value& val, const MemCached& ca const failable get(const value& key, const MemCached& cache) { debug(key, "memcache::get::key"); - const string ks(scheme::writeValue(key)); + const string ks(write(content(scheme::writeValue(key)))); char *data; apr_size_t size; - gc_local_pool lp; + const gc_local_pool lp; const apr_status_t rc = apr_memcache_getp(cache.mc, pool(lp), nospaces(c_str(ks)), &data, &size, NULL); if (rc != APR_SUCCESS) { ostringstream os; os << "Couldn't get memcached entry: " << key; return mkfailure(str(os), 404, false); } - const value val(scheme::readValue(string(data, size))); + const value val(content(scheme::readValue(string(data, size)))); debug(val, "memcache::get::result"); return val; @@ -198,7 +204,7 @@ const failable get(const value& key, const MemCached& cache) { const failable del(const value& key, const MemCached& cache) { debug(key, "memcache::delete::key"); - const string ks(scheme::writeValue(key)); + const string ks(write(content(scheme::writeValue(key)))); const apr_status_t rc = apr_memcache_delete(cache.mc, nospaces(c_str(ks)), 0); if (rc != APR_SUCCESS) { ostringstream os; diff --git a/sca-cpp/trunk/components/cache/memocache.cpp b/sca-cpp/trunk/components/cache/memocache.cpp index e7e52cdc59..5539ccee2f 100644 --- a/sca-cpp/trunk/components/cache/memocache.cpp +++ b/sca-cpp/trunk/components/cache/memocache.cpp @@ -42,7 +42,7 @@ namespace memocache { /** * Memoize the value of a function application in a cache. */ -const failable memoize(const list& params, const lambda&)>& relay, const lambda&)>& cache) { +const failable memoize(const list& params, const lvvlambda& relay, const lvvlambda& cache) { debug(params, "memocache::memoize::params"); // Lookup memoized value from cache diff --git a/sca-cpp/trunk/components/cache/partitioner.cpp b/sca-cpp/trunk/components/cache/partitioner.cpp index e3f04ba112..a38c053358 100644 --- a/sca-cpp/trunk/components/cache/partitioner.cpp +++ b/sca-cpp/trunk/components/cache/partitioner.cpp @@ -22,7 +22,7 @@ /** * A partitioner component implementation which forwards data access requests to a * dynamically selected data store component. The selection is externalized, performed - * by a selector component, responsible for selecting the target data store given the + * by a selector component, responsible for selecting the target data stores given the * data access request key and a list of references to available data store components. * This pattern can be used for sharding or load balancing for example. */ @@ -38,54 +38,89 @@ namespace tuscany { namespace partitioner { /** - * Return the target partition for a key. + * Return a list of target partitions for a key. */ -const failable&)> > partition(const value& key, const lambda&)>& selector, const list& partitions) { +const failable > partition(const value& key, const lvvlambda& selector, const list& partitions) { - // Call the selector component to convert the given key to a partition number + // Call the selector component to convert the given key to a list of partitions const value p = selector(mklist("get", key, partitions)); if (isNil(p)) { ostringstream os; - os << "Couldn't get partition number: " << key; - return mkfailure&)> >(str(os), -1, false); + os << "Couldn't get partition: " << key; + return mkfailure >(str(os), -1, false); } - return (const lambda&)>)p; + return (list)p; +} + + +/** + * Get lists of items from a list of partitions. + */ +const failable > getlist(const value& key, const list& partitions) { + if (isNil(partitions)) + return nilListValue; + + const lvvlambda l = car(partitions); + const value val = l(mklist("get", key)); + if (isNil(val)) + return getlist(key, cdr(partitions)); + if (!isList(val)) { + ostringstream os; + os << "Couldn't get list of entries from partition: " << key; + return mkfailure >(str(os), 500, false); + } + + const failable > cdrval = getlist(key, cdr(partitions)); + if (!hasContent(cdrval)) + return cdrval; + + return append((list)val, content(cdrval)); } /** * Get an item from a partition. */ -const failable get(const value& key, const lambda&)>& selector, const list& partitions) { +const failable get(const value& key, const lvvlambda& selector, const list& partitions) { // Select partition - const failable&)> > p = partition(key, selector, partitions); - if (!hasContent(p)) - return mkfailure(p); - - // Get from selected partition - const value val = content(p)(mklist("get", key)); - if (isNil(val)) { - ostringstream os; - os << "Couldn't get entry from partition: " << key; - return mkfailure(str(os), 404, false); + const failable > fp = partition(key, selector, partitions); + if (!hasContent(fp)) + return mkfailure(fp); + const list p = content(fp); + + // Get a single item from the selected partition + if (length(p) == 1) { + const lvvlambda l = car(p); + const value val = l(mklist("get", key)); + if (isNil(val)) { + ostringstream os; + os << "Couldn't get entry from partition: " << key; + return mkfailure(str(os), 404, false); + } + return val; } - return val; + // Get list of items from the list of selected partitions + const failable > val = getlist(key, p); + if (!hasContent(val)) + return mkfailure(val); + return (value)content(val); } /** * Post an item to a partition. */ -const failable post(const value& key, const value& val, const lambda&)>& selector, const list& partitions) { +const failable post(const value& key, const value& val, const lvvlambda& selector, const list& partitions) { const value id = append(key, mklist(mkuuid())); // Select partition - const failable&)> > p = partition(id, selector, partitions); + const failable > p = partition(id, selector, partitions); if (!hasContent(p)) return mkfailure(p); // Put into select partition - content(p)(mklist("put", id, val)); + const lvvlambda l = car(content(p)); + l(mklist("post", id, val)); return id; } @@ -93,33 +128,35 @@ const failable post(const value& key, const value& val, const lambda put(const value& key, const value& val, const lambda&)>& selector, const list& partitions) { +const failable put(const value& key, const value& val, const lvvlambda& selector, const list& partitions) { // Select partition - const failable&)> > p = partition(key, selector, partitions); + const failable > p = partition(key, selector, partitions); if (!hasContent(p)) return mkfailure(p); // Put into selected partition - content(p)(mklist("put", key, val)); + const lvvlambda l = car(content(p)); + l(mklist("put", key, val)); - return value(true); + return trueValue; } /** * Delete an item from a partition. */ -const failable del(const value& key, const lambda&)>& selector, const list& partitions) { +const failable del(const value& key, const lvvlambda& selector, const list& partitions) { // Select partition - const failable&)> > p = partition(key, selector, partitions); + const failable > p = partition(key, selector, partitions); if (!hasContent(p)) return mkfailure(p); // Delete from selected partition - content(p)(mklist("delete", key)); + const lvvlambda l = car(content(p)); + l(mklist("delete", key)); - return value(true); + return trueValue; } } diff --git a/sca-cpp/trunk/components/cache/select-test.scm b/sca-cpp/trunk/components/cache/select-test.scm index 9baa82a5da..f788a6104a 100644 --- a/sca-cpp/trunk/components/cache/select-test.scm +++ b/sca-cpp/trunk/components/cache/select-test.scm @@ -17,5 +17,5 @@ ; Partition selector test case -(define (get key partitions) (if (= (car key) "a") (car partitions) (cadr partitions))) +(define (get key partitions) (if (= (car key) "a") (list (car partitions)) (list (cadr partitions)))) -- cgit v1.2.3