diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-07-28 09:50:21 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-07-28 09:50:21 +0000 |
commit | 9e52793370e243c647f6df181402a827e1948c67 (patch) | |
tree | b45fc568df85769e4281a01b84f45bf141d4dabb /sca-cpp/trunk/samples/store-cluster/domains | |
parent | fe93d86e5572870b2e4004c7788da8320a28de3d (diff) |
Change sample to use a pool of three memcached servers. Add a property to the memcached component to list multiple memcached servers. Replace spaces by tabs in memcached keys as spaces are not allowed in keys.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@980010 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/samples/store-cluster/domains')
4 files changed, 34 insertions, 26 deletions
diff --git a/sca-cpp/trunk/samples/store-cluster/domains/jane/shopping-cart.py b/sca-cpp/trunk/samples/store-cluster/domains/jane/shopping-cart.py index 405adb85bf..e315b2f1ca 100644 --- a/sca-cpp/trunk/samples/store-cluster/domains/jane/shopping-cart.py +++ b/sca-cpp/trunk/samples/store-cluster/domains/jane/shopping-cart.py @@ -19,21 +19,23 @@ import uuid import sys -cartId = "1234" +# Convert a particular host and user email to a cart id +def cartid(host, email): + return ("cart", host(), email()) # Get the shopping cart from the cache # Return an empty cart if not found def getcart(id, cache): - cart = cache("get", (id,)) + cart = cache("get", id) if cart is None: return () return cart # Post a new item to the cart, create a new cart if necessary -def post(collection, item, cache): +def post(collection, item, cache, host, email): id = str(uuid.uuid1()) - cart = ((item[0], id, item[2]),) + getcart(cartId, cache) - cache("put", (cartId,), cart) + cart = ((item[0], id, item[2]),) + getcart(cartid(host, email), cache) + cache("put", cartid(host, email), cart) return (id,) @@ -47,15 +49,15 @@ def find(id, cart): return find(id, cart[1:]) # Get items from the cart -def get(id, cache): +def get(id, cache, host, email): if id == (): - return ("Your Cart", cartId) + getcart(cartId, cache) - return find(id[0], getcart(cartId, cache)) + return ("Your Cart", email()) + getcart(cartid(host, email), cache) + return find(id[0], getcart(cartid(host, email), cache)) # Delete items from the cart -def delete(id, cache): +def delete(id, cache, host, email): if id == (): - return cache("delete", (cartId,)) + return cache("delete", cartid(host, email)) return True # Return the price of an item @@ -69,7 +71,6 @@ def sum(items): return price(items[0]) + sum(items[1:]) # Return the total price of the items in the cart -def gettotal(cache): - cart = getcart(cartId, cache) - return sum(cart) +def gettotal(cache, host, email): + return sum(getcart(cartid(host, email), cache)) diff --git a/sca-cpp/trunk/samples/store-cluster/domains/jane/store.composite b/sca-cpp/trunk/samples/store-cluster/domains/jane/store.composite index 893b4f0ed4..396970a6e6 100644 --- a/sca-cpp/trunk/samples/store-cluster/domains/jane/store.composite +++ b/sca-cpp/trunk/samples/store-cluster/domains/jane/store.composite @@ -43,6 +43,8 @@ <component name="ShoppingCart"> <t:implementation.python script="shopping-cart.py"/> + <property name="host">localhost</property> + <property name="email">anonymous@localhost</property> <service name="ShoppingCart"> <t:binding.atom uri="shoppingCart"/> </service> @@ -64,6 +66,7 @@ <service name="Cache"> <t:binding.atom uri="cache"/> </service> + <property name="servers">localhost:11211,localhost:11212,localhost:11213</property> </component> </composite> diff --git a/sca-cpp/trunk/samples/store-cluster/domains/joe/shopping-cart.py b/sca-cpp/trunk/samples/store-cluster/domains/joe/shopping-cart.py index 405adb85bf..e315b2f1ca 100644 --- a/sca-cpp/trunk/samples/store-cluster/domains/joe/shopping-cart.py +++ b/sca-cpp/trunk/samples/store-cluster/domains/joe/shopping-cart.py @@ -19,21 +19,23 @@ import uuid import sys -cartId = "1234" +# Convert a particular host and user email to a cart id +def cartid(host, email): + return ("cart", host(), email()) # Get the shopping cart from the cache # Return an empty cart if not found def getcart(id, cache): - cart = cache("get", (id,)) + cart = cache("get", id) if cart is None: return () return cart # Post a new item to the cart, create a new cart if necessary -def post(collection, item, cache): +def post(collection, item, cache, host, email): id = str(uuid.uuid1()) - cart = ((item[0], id, item[2]),) + getcart(cartId, cache) - cache("put", (cartId,), cart) + cart = ((item[0], id, item[2]),) + getcart(cartid(host, email), cache) + cache("put", cartid(host, email), cart) return (id,) @@ -47,15 +49,15 @@ def find(id, cart): return find(id, cart[1:]) # Get items from the cart -def get(id, cache): +def get(id, cache, host, email): if id == (): - return ("Your Cart", cartId) + getcart(cartId, cache) - return find(id[0], getcart(cartId, cache)) + return ("Your Cart", email()) + getcart(cartid(host, email), cache) + return find(id[0], getcart(cartid(host, email), cache)) # Delete items from the cart -def delete(id, cache): +def delete(id, cache, host, email): if id == (): - return cache("delete", (cartId,)) + return cache("delete", cartid(host, email)) return True # Return the price of an item @@ -69,7 +71,6 @@ def sum(items): return price(items[0]) + sum(items[1:]) # Return the total price of the items in the cart -def gettotal(cache): - cart = getcart(cartId, cache) - return sum(cart) +def gettotal(cache, host, email): + return sum(getcart(cartid(host, email), cache)) diff --git a/sca-cpp/trunk/samples/store-cluster/domains/joe/store.composite b/sca-cpp/trunk/samples/store-cluster/domains/joe/store.composite index 893b4f0ed4..396970a6e6 100644 --- a/sca-cpp/trunk/samples/store-cluster/domains/joe/store.composite +++ b/sca-cpp/trunk/samples/store-cluster/domains/joe/store.composite @@ -43,6 +43,8 @@ <component name="ShoppingCart"> <t:implementation.python script="shopping-cart.py"/> + <property name="host">localhost</property> + <property name="email">anonymous@localhost</property> <service name="ShoppingCart"> <t:binding.atom uri="shoppingCart"/> </service> @@ -64,6 +66,7 @@ <service name="Cache"> <t:binding.atom uri="cache"/> </service> + <property name="servers">localhost:11211,localhost:11212,localhost:11213</property> </component> </composite> |