Add a new sharded counter counter example, using the
[gae-samples.git] / sharded-counter-java / src / V2Servlet.java
blob8ca1c593f79c4a1b249f1be00d44ac03e1713c3e
1 import java.io.IOException;
3 import javax.servlet.http.HttpServlet;
4 import javax.servlet.http.HttpServletRequest;
5 import javax.servlet.http.HttpServletResponse;
7 @SuppressWarnings("serial")
8 public class V2Servlet extends HttpServlet {
9 @Override
10 public void doGet(HttpServletRequest req, HttpServletResponse resp)
11 throws IOException {
12 resp.setContentType("text/plain");
14 String counterName = req.getParameter("name");
15 String action = req.getParameter("action");
16 String shards = req.getParameter("shards");
18 ShardedCounterV2 counter = new ShardedCounterV2(counterName);
20 if ("increment".equals(action)) {
21 counter.increment();
22 resp.getWriter().println("Counter incremented.");
23 } else if ("increase_shards".equals(action)) {
24 int inc = Integer.valueOf(shards);
25 counter.addShards(inc);
26 resp.getWriter().println("Shard count increased by " + inc + ".");
27 } else {
28 resp.getWriter().println("getCount() -> " + counter.getCount());