Mercurial > hg > Members > nobuyasu > jungle-network
view src/main/java/app/bbs/codesegment/StartBBSCodeSegment.java @ 122:cef245f71053
Implemented NetworkJungleBulletinBoard.checkAndCreateLogDirectory method
author | one |
---|---|
date | Fri, 27 Dec 2013 19:17:07 +0900 |
parents | f64ff5bd66f5 |
children | dacfa7eba841 |
line wrap: on
line source
package app.bbs.codesegment; import java.io.FileNotFoundException; import java.io.IOException; 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.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() { String name = host.asString(); Matcher matcher = pattern.matcher(name); matcher.find(); // String type = matcher.group(1); System.out.println("log loading..."); NetworkJungleBulletinBoard cassaBBS = null; try { cassaBBS = new NetworkJungleBulletinBoard(name); cassaBBS.init(); } catch (FileNotFoundException e1) { e1.printStackTrace(); System.exit(0);; } catch (IOException e) { e.printStackTrace(); } 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); 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(); } }