Mercurial > hg > Members > nobuyasu > jungle-network
view src/jungle/app/bbs/codesegment/StartBBSCodeSegment.java @ 89:f3f89613c7e3
Rmoved NetworkJournal
author | one |
---|---|
date | Tue, 05 Nov 2013 15:56:31 +0900 |
parents | 29127ac788a6 |
children | fcce7ca4adb9 |
line wrap: on
line source
package jungle.app.bbs.codesegment; import java.util.regex.Pattern; import java.util.regex.Matcher; import javax.servlet.Servlet; import jungle.app.bbs.BulletinBoard; import jungle.app.bbs.CreateBoardMessageServlet; import jungle.app.bbs.CreateBoardServlet; import jungle.app.bbs.EditMessageServlet; import jungle.app.bbs.NetworkJungleBulletinBoard; import jungle.app.bbs.ShowBoardMessageServlet; import jungle.app.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 alice.jungle.datasegment.HashSetDataSegment; public class StartBBSCodeSegment extends CodeSegment { int bbsPort = 8080; Receiver host = ids.create(CommandType.PEEK); private Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$"); public StartBBSCodeSegment(int p) { bbsPort = p; host.setKey("host"); } public StartBBSCodeSegment() { host.setKey("host"); } public void run() { System.out.println("StartBBSCodeSegment"); String name = host.asString(); System.out.println("name : "+ name); Matcher matcher = pattern.matcher(name); matcher.find(); // String type = matcher.group(1); /* Jetty registration */ BulletinBoard cassaBBS = new NetworkJungleBulletinBoard(name); 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); 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); serv.addHandler(context); try { serv.start(); } catch (Exception e) { e.printStackTrace(); } new ChildLogCheckCodeSegment(); HashSetDataSegment hashLog = new HashSetDataSegment(); ods.put("hashLog", hashLog); int num = new Integer(matcher.group(2)); if (num != 0) { // try {Thread.sleep(100);} catch(Exception e) { e.printStackTrace(); } new LogUpdateCodeSegment(); } } }