From f0d916a6263878537dde5f76922c6d24913885e2 Mon Sep 17 00:00:00 2001 From: rfeng Date: Sat, 10 Oct 2009 00:35:42 +0000 Subject: Add code to try memcache git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@823753 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/gae/services/DatastoreServiceImpl.java | 2 ++ .../src/sample/HelloworldService.java | 3 +-- .../src/sample/HelloworldServiceImpl.java | 25 +++++++++++++++++++++- .../war/WEB-INF/web.composite | 1 + 4 files changed, 28 insertions(+), 3 deletions(-) (limited to 'sandbox/rfeng') diff --git a/sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/DatastoreServiceImpl.java b/sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/DatastoreServiceImpl.java index 5d58358b76..05eb40ff2c 100644 --- a/sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/DatastoreServiceImpl.java +++ b/sandbox/rfeng/helloworld-jsp-google-appengine/src/org/apache/tuscany/sca/gae/services/DatastoreServiceImpl.java @@ -23,6 +23,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import org.oasisopen.sca.annotation.Init; import org.oasisopen.sca.annotation.Scope; import org.oasisopen.sca.annotation.Service; @@ -44,6 +45,7 @@ import com.google.appengine.api.datastore.Transaction; public class DatastoreServiceImpl implements DatastoreService { private DatastoreService delegate; + @Init public void init() { delegate = DatastoreServiceFactory.getDatastoreService(); } diff --git a/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldService.java b/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldService.java index 9e19edbf9a..721d93ce8a 100644 --- a/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldService.java +++ b/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldService.java @@ -18,9 +18,8 @@ */ package sample; -import org.oasisopen.sca.annotation.Remotable; -@Remotable + public interface HelloworldService { String sayHello(String name); diff --git a/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java b/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java index 69227b1750..d7867c6a45 100644 --- a/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java +++ b/sandbox/rfeng/helloworld-jsp-google-appengine/src/sample/HelloworldServiceImpl.java @@ -20,12 +20,16 @@ package sample; import java.io.IOException; import java.net.URL; +import java.util.Date; +import java.util.Stack; import org.oasisopen.sca.annotation.EagerInit; import org.oasisopen.sca.annotation.Init; import org.oasisopen.sca.annotation.Reference; import org.oasisopen.sca.annotation.Scope; +import org.oasisopen.sca.annotation.Service; +import com.google.appengine.api.memcache.MemcacheService; import com.google.appengine.api.urlfetch.HTTPResponse; import com.google.appengine.api.urlfetch.URLFetchService; import com.google.appengine.api.users.User; @@ -33,6 +37,7 @@ import com.google.appengine.api.users.UserService; @EagerInit @Scope("COMPOSITE") +@Service(HelloworldService.class) public class HelloworldServiceImpl implements HelloworldService { @Reference protected UserService userService; @@ -40,9 +45,20 @@ public class HelloworldServiceImpl implements HelloworldService { @Reference protected URLFetchService fetchService; + @Reference + protected MemcacheService memcacheService; + public String sayHello(String name) { User user = userService.getCurrentUser(); String id = (user == null) ? "" : user.getUserId(); + + Stack stack = (Stack)memcacheService.get("history"); + if (stack == null) { + stack = new Stack(); + } + stack.push(new Date().toString() + ": " + name); + memcacheService.put("history", stack); + String content = ""; try { HTTPResponse response = fetchService.fetch(new URL("http://tuscany.apache.org")); @@ -53,7 +69,14 @@ public class HelloworldServiceImpl implements HelloworldService { } catch (IOException e) { e.printStackTrace(); } - return "[" + id + "] Hello " + name + "

Content from Tuscany Web Site

" + content; + return "[" + id + + "] Hello " + + name + + "


Content from Tuscany Web Site

" + + content + + "

History


" + + stack + + "

"; } @Init diff --git a/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite b/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite index 6923254bc2..e7f05bb67b 100644 --- a/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite +++ b/sandbox/rfeng/helloworld-jsp-google-appengine/war/WEB-INF/web.composite @@ -24,6 +24,7 @@ + -- cgit v1.2.3