annotate src/main/java/app/bbs/codesegment/StartBBSCodeSegment.java @ 153:69b5565c4a63

no use toporogy
author tatsuki
date Sat, 05 Jul 2014 18:28:40 +0900
parents 29734d7d6521
children a6bf0369f0a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
112
8f9811a1e00c Moved app files
one
parents: 106
diff changeset
1 package app.bbs.codesegment;
44
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
2
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
3 import java.util.regex.Pattern;
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
4 import java.util.regex.Matcher;
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
5
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
6 import javax.servlet.Servlet;
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
7
125
6104702a1880 Added dependency bulletinboard in pom.xml
one
parents: 124
diff changeset
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.CreateBoardMessageServlet;
6104702a1880 Added dependency bulletinboard in pom.xml
one
parents: 124
diff changeset
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.CreateBoardServlet;
6104702a1880 Added dependency bulletinboard in pom.xml
one
parents: 124
diff changeset
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.EditMessageServlet;
140
09b405d0830b Removed EditMessageUseGetServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 139
diff changeset
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.EditMessageUseGetServlet;
125
6104702a1880 Added dependency bulletinboard in pom.xml
one
parents: 124
diff changeset
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.ShowBoardsServlet;
6104702a1880 Added dependency bulletinboard in pom.xml
one
parents: 124
diff changeset
13
44
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
14 import org.mortbay.jetty.Server;
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
15 import org.mortbay.jetty.servlet.ServletHandler;
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
16 import org.mortbay.jetty.servlet.ServletHolder;
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
17
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
18 import alice.codesegment.CodeSegment;
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
19 import alice.datasegment.CommandType;
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
20 import alice.datasegment.Receiver;
124
dacfa7eba841 To select persistent mode "-persistent"
one
parents: 122
diff changeset
21 import app.bbs.NetworkBulletinBoard;
112
8f9811a1e00c Moved app files
one
parents: 106
diff changeset
22 import app.bbs.NetworkJungleBulletinBoard;
143
7a7bac51a3cc Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
23 import app.bbs.RequestNumCheckServlet;
146
29734d7d6521 Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 143
diff changeset
24 import app.bbs.ShowMessageWithTimeStampServlet;
106
f42f2e6b31de Removed project reference and Added dependency in pom.xml
one
parents: 105
diff changeset
25
44
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
26 public class StartBBSCodeSegment extends CodeSegment {
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
27
48
ab8c655ef457 implemented bbsPort setting
one
parents: 47
diff changeset
28 int bbsPort = 8080;
44
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
29 Receiver host = ids.create(CommandType.PEEK);
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
30 private Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$");
124
dacfa7eba841 To select persistent mode "-persistent"
one
parents: 122
diff changeset
31 private String[] args;
dacfa7eba841 To select persistent mode "-persistent"
one
parents: 122
diff changeset
32 boolean persistentFlag = false;
44
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
33
124
dacfa7eba841 To select persistent mode "-persistent"
one
parents: 122
diff changeset
34 public StartBBSCodeSegment(String[] _args, int p) {
dacfa7eba841 To select persistent mode "-persistent"
one
parents: 122
diff changeset
35 args = _args;
48
ab8c655ef457 implemented bbsPort setting
one
parents: 47
diff changeset
36 bbsPort = p;
ab8c655ef457 implemented bbsPort setting
one
parents: 47
diff changeset
37 host.setKey("host");
ab8c655ef457 implemented bbsPort setting
one
parents: 47
diff changeset
38 }
ab8c655ef457 implemented bbsPort setting
one
parents: 47
diff changeset
39
44
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
40 public StartBBSCodeSegment() {
124
dacfa7eba841 To select persistent mode "-persistent"
one
parents: 122
diff changeset
41 args = null;
44
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
42 host.setKey("host");
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
43 }
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
44
153
69b5565c4a63 no use toporogy
tatsuki
parents: 146
diff changeset
45 @Override
44
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
46 public void run() {
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
47 String name = host.asString();
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
48 Matcher matcher = pattern.matcher(name);
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
49 matcher.find();
65
ebf42371454b remove warning
one
parents: 59
diff changeset
50 // String type = matcher.group(1);
124
dacfa7eba841 To select persistent mode "-persistent"
one
parents: 122
diff changeset
51 for(String arg: args) {
dacfa7eba841 To select persistent mode "-persistent"
one
parents: 122
diff changeset
52 if(arg.equals("-persistent")){
dacfa7eba841 To select persistent mode "-persistent"
one
parents: 122
diff changeset
53 persistentFlag = true;
dacfa7eba841 To select persistent mode "-persistent"
one
parents: 122
diff changeset
54 }
dacfa7eba841 To select persistent mode "-persistent"
one
parents: 122
diff changeset
55 }
dacfa7eba841 To select persistent mode "-persistent"
one
parents: 122
diff changeset
56 NetworkBulletinBoard cassaBBS = null;
dacfa7eba841 To select persistent mode "-persistent"
one
parents: 122
diff changeset
57 if(persistentFlag) {
dacfa7eba841 To select persistent mode "-persistent"
one
parents: 122
diff changeset
58 System.out.println("log loading...");
135
2e8034524259 Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 125
diff changeset
59 cassaBBS = NetworkJungleBulletinBoard.NewPersistentJungle(name);
2e8034524259 Added NetworkJournal and SingletonMessageFromAlice class
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 125
diff changeset
60 cassaBBS.init();
124
dacfa7eba841 To select persistent mode "-persistent"
one
parents: 122
diff changeset
61 } else {
118
f64ff5bd66f5 Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents: 112
diff changeset
62 cassaBBS = new NetworkJungleBulletinBoard(name);
f64ff5bd66f5 Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents: 112
diff changeset
63 cassaBBS.init();
f64ff5bd66f5 Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents: 112
diff changeset
64 }
f64ff5bd66f5 Implements persistent for bbs app and Fixed bug JungleUpdater
one
parents: 112
diff changeset
65
122
cef245f71053 Implemented NetworkJungleBulletinBoard.checkAndCreateLogDirectory method
one
parents: 118
diff changeset
66 System.out.println("StartBBSCodeSegment");
cef245f71053 Implemented NetworkJungleBulletinBoard.checkAndCreateLogDirectory method
one
parents: 118
diff changeset
67 System.out.println("name : "+ name);
65
ebf42371454b remove warning
one
parents: 59
diff changeset
68 /* Jetty registration */
44
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
69 String createBoardMessagePath = "/createBoardMessage";
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
70 String createBoardPath = "/createBoard";
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
71 String editMessagePath = "/editMessage";
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
72 String showBoardMessagePath = "/showBoardMessage";
139
c1d75b031b15 Added EditMessageUseGetServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
73
c1d75b031b15 Added EditMessageUseGetServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
74
c1d75b031b15 Added EditMessageUseGetServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
75 Servlet createBoardMessage = new CreateBoardMessageServlet(cassaBBS);
44
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
76 Servlet createBoard = new CreateBoardServlet(cassaBBS);
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
77 Servlet editBoardMessage = new EditMessageServlet(cassaBBS);
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
78 Servlet index = new ShowBoardsServlet(cassaBBS,createBoardPath,showBoardMessagePath);
146
29734d7d6521 Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 143
diff changeset
79 // Servlet board = new ShowBoardMessageServlet(cassaBBS,createBoardMessagePath,editMessagePath);
29734d7d6521 Added ShowMessageWithTimeStampServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 143
diff changeset
80 Servlet board = new ShowMessageWithTimeStampServlet(cassaBBS,createBoardMessagePath,editMessagePath);
44
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
81
48
ab8c655ef457 implemented bbsPort setting
one
parents: 47
diff changeset
82 Server serv = new Server(bbsPort);
44
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
83 ServletHandler context = new ServletHandler();
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
84 context.addServletWithMapping(new ServletHolder(createBoardMessage),createBoardMessagePath);
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
85 context.addServletWithMapping(new ServletHolder(createBoard),createBoardPath);
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
86 context.addServletWithMapping(new ServletHolder(editBoardMessage),editMessagePath);
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
87 context.addServletWithMapping(new ServletHolder(index),"/");
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
88 context.addServletWithMapping(new ServletHolder(board),showBoardMessagePath);
139
c1d75b031b15 Added EditMessageUseGetServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
89 /*
c1d75b031b15 Added EditMessageUseGetServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
90 * For write benchmark
c1d75b031b15 Added EditMessageUseGetServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
91 */
c1d75b031b15 Added EditMessageUseGetServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
92 String editMessageUseGetPath = "/editMessageUseGet";
c1d75b031b15 Added EditMessageUseGetServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
93 Servlet editMessageUseGet = new EditMessageUseGetServlet(cassaBBS);
c1d75b031b15 Added EditMessageUseGetServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 137
diff changeset
94 context.addServletWithMapping(new ServletHolder(editMessageUseGet), editMessageUseGetPath);
143
7a7bac51a3cc Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
95 String requestNumCheckPath = "/requestNum";
7a7bac51a3cc Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
96 Servlet requestNumCheckServlet = new RequestNumCheckServlet(cassaBBS);
7a7bac51a3cc Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
97 context.addServletWithMapping(new ServletHolder(requestNumCheckServlet), requestNumCheckPath);
7a7bac51a3cc Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
98
7a7bac51a3cc Added RequestNumCheckServlet
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 140
diff changeset
99
44
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
100 serv.addHandler(context);
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
101 try {
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
102 serv.start();
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
103 } catch (Exception e) {
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
104 e.printStackTrace();
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
105 }
96
fcce7ca4adb9 Modified LogUpdateCodesegment
one
parents: 89
diff changeset
106 new LogUpdateCodeSegment();
44
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
107 }
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
108
9202247e6077 added StartBBSCodeSegment
one
parents:
diff changeset
109 }