package cs263.cs263;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.memcache.ErrorHandlers;
import com.google.appengine.api.memcache.MemcacheService;
import com.google.appengine.api.memcache.MemcacheServiceFactory;

public class Worker extends HttpServlet {
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String key = request.getParameter("key");
		// Do something with key.

		DatastoreService datastore = DatastoreServiceFactory
				.getDatastoreService();
		Entity employee = new Entity("Employee", "names");
		MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
		syncCache.setErrorHandler(ErrorHandlers
				.getConsistentLogAndContinue(Level.INFO));
		List<String> value = (List<String>) syncCache.get("names"); // read from
		value.add(0, key);
		syncCache.put("names", value);

		Entity ret = null;
		try {
			ret = datastore.get(employee.getKey());
		} catch (EntityNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if(ret == null){
			ret=new  Entity("Employee", "names");
			ret.setProperty("names", Arrays.<String>asList("test Name"));
		}
		List<String> list = (List<String>)ret.getProperty("names");
		if(list==null)
			list=new ArrayList<String>();

		list.add(0, key);
		employee.setProperty("names", list);
		
		datastore.put(employee);
	}
}

@@ -1,1963 +1 @@
-package cs263.cs263;%0A%0Aimport java.io.IOException;%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.Date;%0Aimport java.util.List;%0Aimport java.util.logging.Level;%0A%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A%0Aimport com.google.appengine.api.datastore.DatastoreService;%0Aimport com.google.appengine.api.datastore.DatastoreServiceFactory;%0Aimport com.google.appengine.api.datastore.Entity;%0Aimport com.google.appengine.api.datastore.EntityNotFoundException;%0Aimport com.google.appengine.api.memcache.ErrorHandlers;%0Aimport com.google.appengine.api.memcache.MemcacheService;%0Aimport com.google.appengine.api.memcache.MemcacheServiceFactory;%0A%0Apublic class Worker extends HttpServlet %7B%0A%09protected void doPost(HttpServletRequest request,%0A%09%09%09HttpServletResponse response) throws ServletException, IOException %7B%0A%09%09String key = request.getParameter(%22key%22);%0A%09%09// Do something with key.%0A%0A%09%09DatastoreService datastore = DatastoreServiceFactory%0A%09%09%09%09.getDatastoreService();%0A%09%09Entity employee = new Entity(%22Employee%22, %22names%22);%0A%09%09MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();%0A%09%09syncCache.setErrorHandler(ErrorHandlers%0A%09%09%09%09.getConsistentLogAndContinue(Level.INFO));%0A%09%09List%3CString%3E value = (List%3CString%3E) syncCache.get(%22names%22); // read from%0A%09%09value.add(0, key);%0A%09%09syncCache.put(%22names%22, value);%0A%0A%09%09Entity ret = null;%0A%09%09try %7B%0A%09%09%09ret = datastore.get(employee.getKey());%0A%09%09%7D catch (EntityNotFoundException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09%0A%09%09if(ret == null)%7B%0A%09%09%09ret=new  Entity(%22Employee%22, %22names%22);%0A%09%09%09ret.setProperty(%22names%22, Arrays.%3CString%3EasList(%22test Name%22));%0A%09%09%7D%0A%09%09List%3CString%3E list = (List%3CString%3E)ret.getProperty(%22names%22);%0A%09%09if(list==null)%0A%09%09%09list=new ArrayList%3CString%3E();%0A%0A%09%09list.add(0, key);%0A%09%09employee.setProperty(%22names%22, list);%0A%09%09%0A%09%09datastore.put(employee);%0A%09%7D%0A%7D
 %0A

Update Worker.java