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
{
10 public void doGet(HttpServletRequest req
, HttpServletResponse resp
)
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
)) {
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
+ ".");
28 resp
.getWriter().println("getCount() -> " + counter
.getCount());