Mercurial > hg > Database > jungle-network
changeset 143:7a7bac51a3cc
Added RequestNumCheckServlet
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 26 Jan 2014 16:45:58 +0900 |
parents | 85dab752d0ac |
children | 0efdfe370400 |
files | src/main/java/app/bbs/NetworkBulletinBoard.java src/main/java/app/bbs/NetworkJungleBulletinBoard.java src/main/java/app/bbs/RequestNumCheckServlet.java src/main/java/app/bbs/codesegment/StartBBSCodeSegment.java |
diffstat | 4 files changed, 51 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/app/bbs/NetworkBulletinBoard.java Sun Jan 26 01:36:47 2014 +0900 +++ b/src/main/java/app/bbs/NetworkBulletinBoard.java Sun Jan 26 16:45:58 2014 +0900 @@ -5,4 +5,6 @@ public interface NetworkBulletinBoard extends BulletinBoard { public void init(); + public int getRequestNum(); + }
--- a/src/main/java/app/bbs/NetworkJungleBulletinBoard.java Sun Jan 26 01:36:47 2014 +0900 +++ b/src/main/java/app/bbs/NetworkJungleBulletinBoard.java Sun Jan 26 16:45:58 2014 +0900 @@ -35,6 +35,7 @@ private final NetworkJournal journal; private final String LOG_DIR; private Boolean persistentFlag; + private AtomicInteger requestCounter = new AtomicInteger(0); private NetworkJungleBulletinBoard(String _uuid, NetworkJournal _journal) { @@ -131,6 +132,7 @@ public void createBoards(final String _name,final String _author,final String _initMessage,final String _editKey) { + requestCounter.incrementAndGet(); if(null == jungle.createNewTree(_name)){ throw new IllegalStateException(); } @@ -190,6 +192,7 @@ public void createBoardMessage(final String _board,final String _author,final String _message,final String _editKey) { + requestCounter.incrementAndGet(); JungleTree tree = jungle.getTreeByName(_board); if(tree == null){ throw new IllegalStateException(); @@ -231,6 +234,7 @@ public void editMessage(String _board,String _uuid,final String _author,final String _message,final String _editKey) { + requestCounter.incrementAndGet(); final long timestamp = new Date().getTime(); for(;;) { DefaultNodePath path = new DefaultNodePath(); @@ -264,6 +268,7 @@ public Iterable<BoardMessage> getMessages(String _boardName) { + requestCounter.incrementAndGet(); JungleTree tree = jungle.getTreeByName(_boardName); Node node = tree.getRootNode(); Children<Node> chs = node.getChildren(); @@ -280,7 +285,9 @@ return new IterableConverter<BoardMessage,Node>(chs,converter); } - + public int getRequestNum() { + return requestCounter.get(); + } private static class BoardMessageImpl implements BoardMessage { @@ -309,6 +316,7 @@ { return uuid; } + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/app/bbs/RequestNumCheckServlet.java Sun Jan 26 16:45:58 2014 +0900 @@ -0,0 +1,34 @@ +package app.bbs; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +public class RequestNumCheckServlet extends HttpServlet +{ + private final NetworkBulletinBoard bbs; + + public RequestNumCheckServlet(NetworkBulletinBoard _bbs) + { + bbs = _bbs; + } + + public void doGet(HttpServletRequest _req,HttpServletResponse _res) + { + int num = bbs.getRequestNum(); + + try{ + PrintWriter pw = _res.getWriter(); + pw.write(Integer.toString(num)); + pw.flush(); + }catch(Exception _e){ + _res.setStatus(500); + } + + + } + +}
--- a/src/main/java/app/bbs/codesegment/StartBBSCodeSegment.java Sun Jan 26 01:36:47 2014 +0900 +++ b/src/main/java/app/bbs/codesegment/StartBBSCodeSegment.java Sun Jan 26 16:45:58 2014 +0900 @@ -21,6 +21,7 @@ import alice.datasegment.Receiver; import app.bbs.NetworkBulletinBoard; import app.bbs.NetworkJungleBulletinBoard; +import app.bbs.RequestNumCheckServlet; public class StartBBSCodeSegment extends CodeSegment { @@ -89,6 +90,11 @@ String editMessageUseGetPath = "/editMessageUseGet"; Servlet editMessageUseGet = new EditMessageUseGetServlet(cassaBBS); context.addServletWithMapping(new ServletHolder(editMessageUseGet), editMessageUseGetPath); + String requestNumCheckPath = "/requestNum"; + Servlet requestNumCheckServlet = new RequestNumCheckServlet(cassaBBS); + context.addServletWithMapping(new ServletHolder(requestNumCheckServlet), requestNumCheckPath); + + serv.addHandler(context); try { serv.start();