Mercurial > hg > Members > nobuyasu > jungle-network
changeset 44:9202247e6077
added StartBBSCodeSegment
author | one |
---|---|
date | Fri, 12 Jul 2013 09:14:23 +0900 |
parents | 12d87bb4b84d |
children | bf3dc481cc9b |
files | src/jungle/test/bbs/codesegment/NullCodeSegmentForUpdate.java src/jungle/test/bbs/codesegment/StartBBSCodeSegment.java |
diffstat | 2 files changed, 83 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jungle/test/bbs/codesegment/NullCodeSegmentForUpdate.java Fri Jul 12 09:14:23 2013 +0900 @@ -0,0 +1,11 @@ +package jungle.test.bbs.codesegment; + +import alice.codesegment.CodeSegment; + +public class NullCodeSegmentForUpdate extends CodeSegment{ + + public void run() { + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jungle/test/bbs/codesegment/StartBBSCodeSegment.java Fri Jul 12 09:14:23 2013 +0900 @@ -0,0 +1,72 @@ +package jungle.test.bbs.codesegment; + +import java.util.regex.Pattern; +import java.util.regex.Matcher; + +import javax.servlet.Servlet; + +import jungle.test.bbs.BulletinBoard; +import jungle.test.bbs.CreateBoardMessageServlet; +import jungle.test.bbs.CreateBoardServlet; +import jungle.test.bbs.EditMessageServlet; +import jungle.test.bbs.JungleManager; +import jungle.test.bbs.NetworkJungleBulletinBoard; +import jungle.test.bbs.ShowBoardMessageServlet; +import jungle.test.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; + +public class StartBBSCodeSegment extends CodeSegment { + + Receiver host = ids.create(CommandType.PEEK); + private Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$"); + + public StartBBSCodeSegment() { + host.setKey("host"); + } + + public void run() { + System.out.println("StartBBSCodeSegment"); + String name = host.asString(); + Matcher matcher = pattern.matcher(name); + matcher.find(); + String type = matcher.group(1); + int num = new Integer(matcher.group(2)); + + + 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 = null; + serv = new Server(9090); + 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(); + } + + } + +}