Mercurial > hg > Database > jungle-network
diff src/main/java/app/bbs/codesegment/StartBBSCodeSegment.java @ 112:8f9811a1e00c
Moved app files
author | one |
---|---|
date | Fri, 29 Nov 2013 04:31:22 +0900 (2013-11-28) |
parents | src/main/java/jungle/app/bbs/codesegment/StartBBSCodeSegment.java@f42f2e6b31de |
children | f64ff5bd66f5 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/app/bbs/codesegment/StartBBSCodeSegment.java Fri Nov 29 04:31:22 2013 +0900 @@ -0,0 +1,76 @@ +package app.bbs.codesegment; + +import java.util.regex.Pattern; +import java.util.regex.Matcher; + +import javax.servlet.Servlet; + +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.BulletinBoard; +import app.bbs.CreateBoardMessageServlet; +import app.bbs.CreateBoardServlet; +import app.bbs.EditMessageServlet; +import app.bbs.NetworkJungleBulletinBoard; +import app.bbs.ShowBoardMessageServlet; +import app.bbs.ShowBoardsServlet; + + +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 LogUpdateCodeSegment(); + } + +}