44
|
1 package jungle.test.bbs.codesegment;
|
|
2
|
|
3 import java.util.regex.Pattern;
|
|
4 import java.util.regex.Matcher;
|
|
5
|
|
6 import javax.servlet.Servlet;
|
|
7
|
|
8 import jungle.test.bbs.BulletinBoard;
|
|
9 import jungle.test.bbs.CreateBoardMessageServlet;
|
|
10 import jungle.test.bbs.CreateBoardServlet;
|
|
11 import jungle.test.bbs.EditMessageServlet;
|
|
12 import jungle.test.bbs.NetworkJungleBulletinBoard;
|
|
13 import jungle.test.bbs.ShowBoardMessageServlet;
|
|
14 import jungle.test.bbs.ShowBoardsServlet;
|
|
15
|
|
16 import org.mortbay.jetty.Server;
|
|
17 import org.mortbay.jetty.servlet.ServletHandler;
|
|
18 import org.mortbay.jetty.servlet.ServletHolder;
|
|
19
|
|
20 import alice.codesegment.CodeSegment;
|
|
21 import alice.datasegment.CommandType;
|
|
22 import alice.datasegment.Receiver;
|
47
|
23 import alice.jungle.codesegment.LogUpdateCodeSegment;
|
52
|
24 import alice.jungle.datasegment.HashSetDataSegment;
|
44
|
25
|
|
26 public class StartBBSCodeSegment extends CodeSegment {
|
|
27
|
48
|
28 int bbsPort = 8080;
|
44
|
29 Receiver host = ids.create(CommandType.PEEK);
|
|
30 private Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$");
|
|
31
|
48
|
32 public StartBBSCodeSegment(int p) {
|
|
33 bbsPort = p;
|
|
34 host.setKey("host");
|
|
35 }
|
|
36
|
44
|
37 public StartBBSCodeSegment() {
|
|
38 host.setKey("host");
|
|
39 }
|
|
40
|
|
41 public void run() {
|
|
42 System.out.println("StartBBSCodeSegment");
|
|
43 String name = host.asString();
|
46
|
44 System.out.println("name : "+ name);
|
44
|
45 Matcher matcher = pattern.matcher(name);
|
|
46 matcher.find();
|
|
47 String type = matcher.group(1);
|
52
|
48
|
|
49
|
44
|
50 BulletinBoard cassaBBS = new NetworkJungleBulletinBoard(name);
|
|
51 String createBoardMessagePath = "/createBoardMessage";
|
|
52 String createBoardPath = "/createBoard";
|
|
53 String editMessagePath = "/editMessage";
|
|
54 String showBoardMessagePath = "/showBoardMessage";
|
|
55
|
|
56 Servlet createBoardMessage = new CreateBoardMessageServlet(cassaBBS);
|
|
57 Servlet createBoard = new CreateBoardServlet(cassaBBS);
|
|
58 Servlet editBoardMessage = new EditMessageServlet(cassaBBS);
|
|
59 Servlet index = new ShowBoardsServlet(cassaBBS,createBoardPath,showBoardMessagePath);
|
|
60 Servlet board = new ShowBoardMessageServlet(cassaBBS,createBoardMessagePath,editMessagePath);
|
|
61
|
48
|
62 Server serv = new Server(bbsPort);
|
44
|
63 ServletHandler context = new ServletHandler();
|
|
64 context.addServletWithMapping(new ServletHolder(createBoardMessage),createBoardMessagePath);
|
|
65 context.addServletWithMapping(new ServletHolder(createBoard),createBoardPath);
|
|
66 context.addServletWithMapping(new ServletHolder(editBoardMessage),editMessagePath);
|
|
67 context.addServletWithMapping(new ServletHolder(index),"/");
|
|
68 context.addServletWithMapping(new ServletHolder(board),showBoardMessagePath);
|
|
69 serv.addHandler(context);
|
|
70 try {
|
|
71 serv.start();
|
|
72 } catch (Exception e) {
|
|
73 e.printStackTrace();
|
|
74 }
|
49
|
75
|
50
|
76 new ChildLogCheckCodeSegment();
|
52
|
77 HashSetDataSegment hashLog = new HashSetDataSegment();
|
|
78 ods.put("hashLog", hashLog);
|
|
79
|
49
|
80 int num = new Integer(matcher.group(2));
|
|
81 if (num != 0) {
|
|
82 // try {Thread.sleep(100);} catch(Exception e) { e.printStackTrace(); }
|
50
|
83 new LogUpdateCodeSegment();
|
49
|
84 }
|
|
85
|
|
86
|
44
|
87
|
|
88 }
|
|
89
|
|
90 }
|