changeset 156:89999029c543

remove asynchronous showMessage
author tatsuki
date Fri, 11 Jul 2014 20:07:09 +0900
parents 83e99eba6ec1
children 47ca5d48c30f
files src/main/java/app/bbs/ShowMessageWithTimeStampServlet.java
diffstat 1 files changed, 51 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/app/bbs/ShowMessageWithTimeStampServlet.java	Wed Jul 09 19:44:47 2014 +0900
+++ b/src/main/java/app/bbs/ShowMessageWithTimeStampServlet.java	Fri Jul 11 20:07:09 2014 +0900
@@ -11,64 +11,60 @@
 
 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BoardMessage;
 
-public class ShowMessageWithTimeStampServlet extends HttpServlet
-{
-	/**
+public class ShowMessageWithTimeStampServlet extends HttpServlet {
+    /**
 	 * 
 	 */
-	private static final long serialVersionUID = 1L;
-	private final NetworkBulletinBoard bbs;
-	private final String createBoardMessagePath;
-	private final String editMessagePath;
+    private static final long serialVersionUID = 1L;
+    private final NetworkBulletinBoard bbs;
+    private final String createBoardMessagePath;
+    private final String editMessagePath;
     private ThreadPool threadPool;
-	
-	private static final String PARAM_BOARD_NAME = "bname";
+
+    private static final String PARAM_BOARD_NAME = "bname";
 
-	public ShowMessageWithTimeStampServlet(NetworkBulletinBoard _bbs,String _createBoardMessagePath, String _editMessagePath, ThreadPool thp)
-	{
-		bbs = _bbs;
-		createBoardMessagePath = _createBoardMessagePath;
-		editMessagePath = _editMessagePath;
-		threadPool = thp; 
-	}
+    public ShowMessageWithTimeStampServlet(NetworkBulletinBoard _bbs,
+            String _createBoardMessagePath, String _editMessagePath,
+            ThreadPool thp) {
+        bbs = _bbs;
+        createBoardMessagePath = _createBoardMessagePath;
+        editMessagePath = _editMessagePath;
+        threadPool = thp;
+    }
+
+    public void doGet(HttpServletRequest _req, HttpServletResponse _res) {
+        final String bname = _req.getParameter(PARAM_BOARD_NAME);
+        try {
+            printBoard(bname, _res.getWriter());
+        } catch (Exception _e) {
+            _res.setStatus(500);
+        }
+    }
 
-	public void doGet(HttpServletRequest _req,HttpServletResponse _res)
-	{
-	    final AsyncContext asc = _req.startAsync();
-	    final String bname = _req.getParameter(PARAM_BOARD_NAME);
-	    Runnable printBoardThread = new Runnable() {
-            @Override
-            public void run() {
-                try{
-                    printBoard(bname,_res.getWriter());
-                }catch(Exception _e){
-                    _res.setStatus(500);
-                } 
-                asc.complete();
-            }
-	    };
-	    threadPool.execute(printBoardThread);
-	}
-	
-	private void printBoard(String _bname,PrintWriter _pw) throws Exception
-	{
-		_pw.write("<html><body>\n");
-		_pw.write("<h1>"+_bname+"</h1>\n");
-		_pw.write("<p>Latest renew time : "+bbs.getRenewTime(_bname)+"</p>\n");;
-		
-		_pw.write("<form action='"+createBoardMessagePath+"' method='POST'\n");
-		_pw.write("<p>Author : <input type='text' name='author'/> <input type='hidden' name='bname' value='"+_bname+"'/> EditKey : <input type='text' name='key'/></p>\n");
-		_pw.write("<p>Message<br/> <input type='textarea' name='msg'/> </p>\n");
-		_pw.write("<p><input type='submit' value='submit'/></p>\n");
-		
-		for(BoardMessage msg : bbs.getMessages(_bname)){
-			_pw.write("<hr/>");
-			_pw.write("<p><b>"+msg.getAuthor()+"</b></p>");
-			_pw.write("<p>"+msg.getMessage()+"</p>");
-			_pw.write("<small><a href='"+editMessagePath+"?bname="+_bname+"&uuid="+msg.getUUID()+"'>edit</a></small>");
-		}
-		
-		_pw.write("</body></html>");
-		_pw.flush();
-	}
+    private void printBoard(String _bname, PrintWriter _pw) throws Exception {
+        _pw.write("<html><body>\n");
+        _pw.write("<h1>" + _bname + "</h1>\n");
+        _pw.write("<p>Latest renew time : " + bbs.getRenewTime(_bname)
+                + "</p>\n");
+        ;
+
+        _pw.write("<form action='" + createBoardMessagePath
+                + "' method='POST'\n");
+        _pw.write("<p>Author : <input type='text' name='author'/> <input type='hidden' name='bname' value='"
+                + _bname
+                + "'/> EditKey : <input type='text' name='key'/></p>\n");
+        _pw.write("<p>Message<br/> <input type='textarea' name='msg'/> </p>\n");
+        _pw.write("<p><input type='submit' value='submit'/></p>\n");
+
+        for (BoardMessage msg : bbs.getMessages(_bname)) {
+            _pw.write("<hr/>");
+            _pw.write("<p><b>" + msg.getAuthor() + "</b></p>");
+            _pw.write("<p>" + msg.getMessage() + "</p>");
+            _pw.write("<small><a href='" + editMessagePath + "?bname=" + _bname
+                    + "&uuid=" + msg.getUUID() + "'>edit</a></small>");
+        }
+
+        _pw.write("</body></html>");
+        _pw.flush();
+    }
 }