Mercurial > hg > Database > jungle-network
view src/main/java/app/bbs/codesegment/StartBBSCodeSegment.java @ 146:29734d7d6521
Added ShowMessageWithTimeStampServlet
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 28 Jan 2014 08:47:45 +0900 |
parents | 7a7bac51a3cc |
children | 69b5565c4a63 |
line wrap: on
line source
package app.bbs.codesegment; import java.util.regex.Pattern; import java.util.regex.Matcher; import javax.servlet.Servlet; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.CreateBoardMessageServlet; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.CreateBoardServlet; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.EditMessageServlet; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.EditMessageUseGetServlet; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.ShowBoardsServlet; import org.mortbay.jetty.Server; import org.mortbay.jetty.servlet.ServletHandler; import org.mortbay.jetty.servlet.ServletHolder; import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; import app.bbs.NetworkBulletinBoard; import app.bbs.NetworkJungleBulletinBoard; import app.bbs.RequestNumCheckServlet; import app.bbs.ShowMessageWithTimeStampServlet; public class StartBBSCodeSegment extends CodeSegment { int bbsPort = 8080; Receiver host = ids.create(CommandType.PEEK); private Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$"); private String[] args; boolean persistentFlag = false; public StartBBSCodeSegment(String[] _args, int p) { args = _args; bbsPort = p; host.setKey("host"); } public StartBBSCodeSegment() { args = null; host.setKey("host"); } public void run() { String name = host.asString(); Matcher matcher = pattern.matcher(name); matcher.find(); // String type = matcher.group(1); for(String arg: args) { if(arg.equals("-persistent")){ persistentFlag = true; } } NetworkBulletinBoard cassaBBS = null; if(persistentFlag) { System.out.println("log loading..."); cassaBBS = NetworkJungleBulletinBoard.NewPersistentJungle(name); cassaBBS.init(); } else { cassaBBS = new NetworkJungleBulletinBoard(name); cassaBBS.init(); } System.out.println("StartBBSCodeSegment"); System.out.println("name : "+ name); /* Jetty registration */ String createBoardMessagePath = "/createBoardMessage"; String createBoardPath = "/createBoard"; String editMessagePath = "/editMessage"; String showBoardMessagePath = "/showBoardMessage"; Servlet createBoardMessage = new CreateBoardMessageServlet(cassaBBS); Servlet createBoard = new CreateBoardServlet(cassaBBS); Servlet editBoardMessage = new EditMessageServlet(cassaBBS); Servlet index = new ShowBoardsServlet(cassaBBS,createBoardPath,showBoardMessagePath); // Servlet board = new ShowBoardMessageServlet(cassaBBS,createBoardMessagePath,editMessagePath); Servlet board = new ShowMessageWithTimeStampServlet(cassaBBS,createBoardMessagePath,editMessagePath); Server serv = new Server(bbsPort); ServletHandler context = new ServletHandler(); context.addServletWithMapping(new ServletHolder(createBoardMessage),createBoardMessagePath); context.addServletWithMapping(new ServletHolder(createBoard),createBoardPath); context.addServletWithMapping(new ServletHolder(editBoardMessage),editMessagePath); context.addServletWithMapping(new ServletHolder(index),"/"); context.addServletWithMapping(new ServletHolder(board),showBoardMessagePath); /* * For write benchmark */ 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(); } catch (Exception e) { e.printStackTrace(); } new LogUpdateCodeSegment(); } }